Create a .mat file similar to MRI

Hello,
Does anyone know how to place 12 mri images into the same matrix size and shape as D in the .mat file MRI?
Any help is greatly appreciated.
-Thanks

回答(2 个)

hi,
The default MRI sample has singleton dimension right?
try :
% given I1,.............,I12
[m n]=size(I1);
M=zeros(m,n,12);
M(:,:,1)=I1;
%....
M(:,:,12)=I12;
D=zeros(m,n,1,12);
for n=1:12
D(:,:,:,n)=M(:,:,n);
end
save Neoplasm_MRI D

10 个评论

This is how I load the images into the workspace I1=imread('Slice_1.jpg'); I2=imread('Slice_2.jpg'); I3=imread('Slice_3.jpg'); I4=imread('Slice_4.jpg'); I5=imread('Slice_5.jpg'); I6=imread('Slice_6.jpg'); I7=imread('Slice_7.jpg'); I8=imread('Slice_8.jpg'); I9=imread('Slice_9.jpg'); I10=imread('Slice_10.jpg'); I11=imread('Slice_11.jpg'); I12=imread('Slice_12.jpg'); imshow(I12)
Here's the code for placing the images in the matrix
i keep getting this error
??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in ==> imread_tomatrix at 56 D(m,n,1,1)=I1;
[m n]=size(I1); p=12; D=zeros(m,n,1,p); D(m,n,1,1)=I1; D(m,n,1,2)=I2; D(m,n,1,3)=I3; D(m,n,1,4)=I4; D(m,n,1,5)=I5; D(m,n,1,6)=I6; D(m,n,1,7)=I7; D(m,n,1,8)=I8; D(m,n,1,9)=I9; D(m,n,1,10)=I10; D(m,n,1,11)=I11; D(m,n,1,12)=I12; save Neoplasm_MRI D
try the edited code...
I tried the code, it allowed me to upload images into the D matrix only after i made them binary. I modified the code to add an extra dimension to M to see if that was the issue. i received this error in both instances
??? Subscripted assignment dimension mismatch.
Error in ==> imread_tomatrix at 58 M(:,:,:,1)=I1;
hi Christopher,
No 'M' was only a bypass, now D contains the 12 slices and has same m-n-1-12 as dimensions, it can also contains double valued images , what is the problem
here is simple example : ( use : operator instead of 1 ok? )
I1=rand(10); % my first image {double}
I2=rand(10); % my second image {double}
M=zeros(10,10,1,2); % container
M(:,:,:,1)=I1; % transfer 1
M(:,:,:,2)=I1; % transfer 2
This should work in your case too
I initially tried using M that way.
Here's a second try with your code
I got the same error ??? Subscripted assignment dimension mismatch.
Error in ==> imread_tomatrix at 55 M(:,:,1)=I1;
% given I1,.............,I12 [m n]=size(I1); M=zeros(m,n,12); M(:,:,1)=I1; M(:,:,2)=I2; M(:,:,3)=I3; M(:,:,4)=I4; M(:,:,5)=I5; M(:,:,6)=I6; M(:,:,7)=I7; M(:,:,8)=I8; M(:,:,9)=I9; M(:,:,10)=I10; M(:,:,11)=I11; M(:,:,12)=I12; D=zeros(m,n,1,12); for n=1:12 D(:,:,:,n)=M(:,:,:,n); end save Neoplasm_MRI D
the images are RGB , or grayscale ?because that error is not in what we are discussing now its in the size of image(s) : try
size(I1)
size(I1)
ans =
225 210 3
so the 3rd dimension is for rgb right?
well thats where the problem then, you have to solutions : 1) transform them into grayscale images using
rgb2gray
2)or add a 4th/5th dimention in M/D:
M=zeros(m,n,3,1,12) ;
% in the code use M(:,:,:,:,n)
Got it working.
Thank you so much for you help.
It's greatly appreciated.

请先登录,再进行评论。

bintoro adi
bintoro adi 2014-12-2

0 个投票

Hi Christoper, Can u write the final code, because i still have the the same error (Subscripted assignment dimension mismatch). thank u...

类别

帮助中心File Exchange 中查找有关 Neuroimaging 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by