You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to Convert 4D-Single to MxNXN
3 views (last 30 days)
Show older comments
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 Comments
mohd akmal masud
on 30 Jun 2022
various..
Bjorn Gustavsson
on 30 Jun 2022
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
on 30 Jun 2022
This all 400 data set that I want to change into MxNxN
mohd akmal masud
on 30 Jun 2022
Because the type .mat is 4D-Single
mohd akmal masud
on 30 Jun 2022
Not same.
mohd akmal masud
on 30 Jun 2022
to each size itself
mohd akmal masud
on 30 Jun 2022
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
on 30 Jun 2022
@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]);
mohd akmal masud
on 30 Jun 2022
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
on 30 Jun 2022
Edited: mohd akmal masud
on 30 Jun 2022
@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
on 30 Jun 2022
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
on 30 Jun 2022
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
on 30 Jun 2022
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
on 30 Jun 2022
@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
on 1 Jul 2022
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
on 1 Jul 2022
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.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)