How can I convert 3d MRI data (128x128x27) into 4d (128x128x1x27) for visualization using montage?

조회 수: 10(최근 30일)
I am going to visualize my mri data using the tutorial:
my data size 128x128x27, it is not working with the instructions. it gives the following the error:
"Unrecognized function or variable map"
I found that the data in the give tutorial size is 128x128x1x27.
How can I convert from 128x128x27 to 128x128x1x27?

채택된 답변

Voss 2022년 4월 27일
편집: Voss 2022년 4월 27일
mri.mat is a .mat file included with the MATLAB installation that contains a few variables:
which mri.mat
S = load('mri.mat')
S = struct with fields:
D: [128×128×1×27 uint8] map: [89×3 double] siz: [128 128 27]
As you can see, mri.mat contains variables D, map and siz. When you load mri.mat into your workspace then those variables become variables in your workspace:
load mri
Name Size Bytes Class Attributes D 128x128x1x27 442368 uint8 map 89x3 2136 double siz 1x3 24 double
The error says, "Unrecognized function or variable map". That's because, however you are loading your data (perhaps from your own .mat file or perhaps some other way), there is no variable called map in the workspace.
The error is not caused by your data being the wrong size or having the wrong dimensionality, but you can make it 128x128x1x27 by doing:
data_4D = permute(data_3D,[1 2 4 3]);
You'd still have to define a map variable if you want to use a colormap, but you can make a montage without one. And you can make a montage with 3D data:
montage(D,map); % 128x128x1x27, with map
title('4D, with map');
montage(D); % 128x128x1x27, no map
title('4D, no map');
montage(squeeze(D),map); % 128x128x27, with map
title('3D, with map');
montage(squeeze(D)); % 128x128x27, no map
title('3D, no map');

추가 답변(1개)

Simon Chan
Simon Chan 2022년 4월 27일
B = permute(A,[1 2 4 3])

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by