Saturday, August 13, 2016

example to display MRI image and data

close

close all; % Clear all windows
clear all; % Clear all variables
clc; % Clear console

% load the data and transform the data array from 4-D to 3-D
% The MRI data, D, is stored as a 128-by-128-by-1-by-27 array.
% Use the squeeze command to remove  4-D to 3-D.
% The result is a 128-by-128-by-27 array
load mri
D = squeeze(D);

display one of the MRI images

figure
colormap(map)
image_num = 10;
image(D(:,:,image_num))
axis image
x = xlim;
y = ylim;



2-D Contour Slice

contour plot uses the jet colormap
twodc = brighten(jet(length(map)),-.5);
figure;
colormap(twodc);
contourslice(D,[],[],image_num)
axis ij
xlim(x)
ylim(y)
daspect([1,1,1])


%%3-D Contour Slices
figure
colormap(twodc)
contourslice(D,[],[],[1,12,19,27],10);
view(3);
axis tight

%%Isosurface to the MRI Data
figure
colormap(map)
Ds = smooth3(D);
hiso = patch(isosurface(Ds,5),...
   'FaceColor',[1,.75,.65],...
   'EdgeColor','none');
   isonormals(Ds,hiso);



Isocaps Show Cut-Away Surface

 hcap = patch(isocaps(D,5),...
   'FaceColor','interp',...
   'EdgeColor','none');

Defining the View

%Define the view and set the aspect ratio (view, axis, daspect).


view(75,30)
axis tight
daspect([1,1,.4])
lightangle(75,30);


lighting gouraud
hcap.AmbientStrength = 0.5;
hiso.SpecularColorReflectance = 0;
hiso.SpecularExponent = 60;

figure;

close;







Slices 3-Dimensional MRI Data

load mri;%Load the MRI data
figure; montage(D,map) %view the 27 horizontal slices as a montage.
title('Horizontal Slices');


M1 = D(:,64,:,:); size(M1);
M2 = reshape(M1,[128 27]); size(M2)
figure; imshow(M2,map);
title('Sagittal - Raw Data');

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');

T1 = maketform('affine',[-2.5 0; 0 1; 68.5 0]);
inverseFcn = @(X,t) [X repmat(t.tdata,[size(X,1) 1])];
T2 = maketform('custom',3,2,[],inverseFcn,64);
Tc = maketform('composite',T1,T2);

R3 = makeresampler({'cubic','nearest','nearest'},'fill');

M4 = tformarray(D,Tc,R3,[4 1 2],[1 2],[66 128],[],0);
figure; imshow(M4,map);
title('Sagittal - TFORMARRAY');


T3 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 0.5; 68.5 0 -14]);
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');


M1 = D(:,64,:,:); size(M1) M2 = reshape(M1,[128 27]); size(M2) figure, imshow(M2,map); title('Sagittal - Raw Data');



R2 = makeresampler({'cubic','nearest'},'fill');
M3 = imtransform(M2,T0,R2);
figure, imshow(M3,map);
title('Sagittal - IMTRANSFORM')


T1 = maketform('affine',[-2.5 0; 0 1; 68.5 0]);
inverseFcn = @(X,t) [X repmat(t.tdata,[size(X,1) 1])];
T2 = maketform('custom',3,2,[],inverseFcn,64);
Tc = maketform('composite',T1,T2);


M4 = tformarray(D,Tc,R3,[4 1 2],[1 2],[66 128],[],0);


figure, imshow(M4,map);
title('Sagittal - TFORMARRAY');





T3 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 0.5; 68.5 0 -14]);


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');


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('Coronal Slices');





ans =

   128    27


ans =

   128     1     1    27


ans =

   128    27


No comments:

Post a Comment