% Example 6 - Extract 2D slices from 3D MRI data
% ----------------------------------------------
% start with clean slate
close all, clear all, clc
%Step 1: Load and View Horizontal MRI
load mri
figure, montage(D,map)
title('Horizontal Slices')
pause %extract sagittal slice (index)
%Step 2: Extract Sagittal Slice from Horizontal Slices by Indexing Data
M1 = D(:,64,:,:); size(M1)
M2 = reshape(M1,[128 27]); size(M2)
figure, imshow(imrotate(M2,90),map)
title('Sagittal - Raw Data')
pause %extract sagittal slice (tform)
%Step 3: Extract Sagittal Slice from Horizontal Slices using imtransform
T0 = maketform('affine',[0 -2.5; 1 0; 0 0]);
R2 = makeresampler({'cubic','nearest'},'fill');
M3 = imtransform(M2,T0,R2);
figure, imshow(M3,map)
title('Sagittal - IMTRANSFORM')
pause %montage of sagittal slices
%Step 4: Create Sagittal Slices and Show Them as montage
T3 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 0.5; 68.5 0 -14]);
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
S = tformarray(D,T3,R3,[4 1 2],[1 2 4],[66 128 35],[],0);
S2 = padarray(S,[6 0 0 0],0,'both');
figure, montage(S2,map)
title('Sagittal Slices')
pause %montage of coronal slices
%Step 5: Create Coronal Slices and Show Them as montage
T4 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 -0.5; 68.5 0 61]);
C = tformarray(D,T4,R3,[4 2 1],[1 2 4],[66 128 45],[],0);
C2 = padarray(C,[6 0 0 0],0,'both');
figure, montage(C2,map)
title('CoronalSlices')
pause %cleanup
%clean up
close all, clear all, clc
% Copyright 2003-2010 RBemis The MathWorks, Inc.