www.gusucode.com > images 案例代码 matlab源码程序 > images/ApplyRotationTransformationTo3DMRIDatasetExample.m

    %% Apply Rotation Transformation to 3-D MRI Dataset
% 
%%
% Read MRI data into the workspace and visualize it.

% Copyright 2015 The MathWorks, Inc.

s = load('mri');
mriVolume = squeeze(s.D);
sizeIn = size(mriVolume);
hFigOriginal = figure;
hAxOriginal  = axes;
slice(double(mriVolume),sizeIn(2)/2,sizeIn(1)/2,sizeIn(3)/2);
grid on, shading interp, colormap gray
%%
% Create a 3-D geometric transformation object. First create a
% transformation matrix that rotates the image around the _Y_ axis. Then
% pass the matrix to the |affine3d| function.
 theta = pi/8;
 t = [cos(theta)  0      -sin(theta)   0
     0             1              0     0
     sin(theta)    0       cos(theta)   0
     0             0              0     1]

tform = affine3d(t)
%%
% Apply the transformation to the image.
mriVolumeRotated = imwarp(mriVolume,tform);
%%
% Visualize three slice planes through the center of the transformed
% volumes.
sizeOut = size(mriVolumeRotated);
hFigRotated = figure;
hAxRotated  = axes;
slice(double(mriVolumeRotated),sizeOut(2)/2,sizeOut(1)/2,sizeOut(3)/2);
grid on, shading interp, colormap gray
%%
% Link views of both axes together.
linkprop([hAxOriginal,hAxRotated],'View');
%%
% Set view to see effect of rotation.
set(hAxRotated,'View',[-3.5 20.0])