How to Convert 4D-Single to MxNXN
8 次查看(过去 30 天)
显示 更早的评论
Dear all,
I have 100 set data 4D-Single. anyone know how to convert it to MxNxN?
Letsay my 4D-Single is cropVol, want to convert to g (see the picture in workspace)
21 个评论
Bjorn Gustavsson
2022-6-30
Can the number of elements in your 4-D arrays be factored into NxNxM? Or do you need to discard or extend some elements of the 4-D array, or do you want to only fill some part of the NxNxM array?
mohd akmal masud
2022-6-30
Or you have any idea, how to read the data for 4D-Single for volds?
clc
clear all
close all
%testDataimages
DATASetDir = fullfile('C:\Users\USER\Downloads\BrainTS\preprocessedDataset');
IMAGEDir = fullfile(DATASetDir,'imagesTr');
volReader = @(x) matRead(x);
volds = imageDatastore(IMAGEDir, ...
'FileExtensions','.mat','ReadFcn',volReader); %THIS ONE IS DATA FOR MXNXN
% labelReader = @(x) matread(x);
matFileDir = fullfile('C:\Users\USER\Downloads\BrainTS\preprocessedDataset\labelsTr');
classNames = ["background", "tumor"];
pixelLabelID = [0 1];
% pxds = (LabelDirr,classNames,pixelLabelID, ...
% 'FileExtensions','.mat','ReadFcn',labelReader);
pxds = pixelLabelDatastore(matFileDir,classNames,pixelLabelID, ...
'FileExtensions','.mat','ReadFcn',@matRead);
Bjorn Gustavsson
2022-6-30
@mohd akmal masud: You will have to explain what size your 4-D array has, what size you want to make the 3-D version, and what elements should be included (or excluded). Otherwise someone might just suggest that you take the first 12 data-points and put it into a 2x2x3 array:
NbyNbyM = reshape(cropVol(1:12),[2 2 3]);
Rik
2022-6-30
Let's make this a little more understandable. Let's say you have a 2D single and want to convert this to a 1D double. How would you do that?
And what is the end purpose of this conversion?
mohd akmal masud
2022-6-30
ok, lets me explain.
actually, I have 400 data set brain tumor. all the data set have the various x,y,z size.
Means all the data set have different x,y,z size.
all my data set is 4D-Single.
Because its all 4D-Single, then I cannot view in volume segmenter apps or volume viewer apps.
then need to convert all data set to x y z single.
are you all get my points?
mohd akmal masud
2022-6-30
编辑:mohd akmal masud
2022-6-30
@Bjorn Gustavsson this one is corect.
But how to loop for 400 data set, then I want o reshap it into the origional size for all?
Rik
2022-6-30
x-y-z is only 3 dimensions. Where are you getting the fourth? Is it maybe the case that your dimensions are x-y-color_channel-z (like the example below)?
load mri
size(D)
ans = 1×4
128 128 1 27
If so, permuting the color channel to the 4th position should solve the problem.
new_D=permute(D,[1 2 4 3]);
size(new_D)
ans = 1×3
128 128 27
mohd akmal masud
2022-6-30
ok let me explain again.
let say one of my data is LiverTS001.mat
then I drag it into command window
>>load('LiverTS001.mat')
so the workspace will be
then I used squeeze to convert it to MxNxN
>>File = squeeze(cropVol);
then the worjspace will be
SHOULD BE the value File is something like 256x256x89 (the size data itself)
Rik
2022-6-30
The squeeze function will only remove dimensions of length 1. It does not promise to make your array 3D. Apparently, none of the dimensions of cropVol have a unit length. You can use the size function to show you the actual size.
Bjorn Gustavsson
2022-6-30
@mohd akmal masud: Give us this information we have been pleading for multiple times:
>> size(cropVol)
Then tell us what the different dimensions correspond to (first dimension might be the variation in x-position for example, but until you've told us that would be pure conjecture), which components you want to display which you want to discard etc. That the array is 4-D tells us very little about what anyting of it means. Is one of the dimensions time? Or wavelength of the X-rays if this is the output from an X-ray tomographic imaging system.
Rik
2022-7-1
Do any of those numbers mean something to you? Do you expect 4 of something? Is your detector 176 by 224?
Without knowing what your dimensions actually mean it is not possible to help you reduce the dimension count to 3.
To explore, you could use the volume viewer on cropVol(:,:,:,k) (putting each of the 4 in a subplot). I don't know if that will help at all, since you're being very sparse with explanations.
Bjorn Gustavsson
2022-7-1
When the 4-D array-size is [176 224 152 4] the only way to put your 4-D array into an N-by-N-by-M array, as you requested is to put the elements into an 128-by-128-by-1463 array. You can do that by something like:
A3D = reshape(cropVol,[128 128 1463]);
If you want or need to re-arrange the for dimensions (of still unknown meaning to us since you still will not tell us what they signify.) you can do that with the permute function. This is the only way to put all elements of an array with dimensions [176 224 152 4] into an N-by-N-by-M array, since the total number of elements factor into: 2^14 * 7 * 11 * 19.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)