Home > fmri > utils > old > GE2SPM.orig > GE_reorientImage.m

GE_reorientImage

PURPOSE ^

SYNOPSIS ^

function [outVol] = GE_reorientImage(inVol, orient)

DESCRIPTION ^

GE_reorientImage

 function [outVol] = GE_reorientImage(inVol, orient)
 reorients the inVol 3D volume to be SPM compatible
 based on the orient flag

 Souheil J. Inati
 Dartmouth College
 Spring 2000

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [outVol] = GE_reorientImage(inVol, orient)
0002 %
0003 %GE_reorientImage
0004 %
0005 % function [outVol] = GE_reorientImage(inVol, orient)
0006 % reorients the inVol 3D volume to be SPM compatible
0007 % based on the orient flag
0008 %
0009 % Souheil J. Inati
0010 % Dartmouth College
0011 % Spring 2000
0012 %
0013 
0014 [nX nY nZ] = size(inVol);
0015 
0016 % Reshape and flip around to match what SPM expects
0017 % ie axial in radiological convention
0018 % Orientation is 1=axial, 2=sagittal, 3=coronal
0019 % with opposite sign if backwards slice order
0020 %
0021 % This has been tested with Ax,Sag,Cor with slices going
0022 % both ways.  Also for Oblique axial.
0023 % Don't count on double obliques or anything really fancy
0024 %
0025 
0026 
0027 switch orient
0028 case  0 % Undefined Orientation
0029    fprintf('Orientation is undefined.  Check your images!');
0030    outArray = inArray;
0031 
0032 case  1 % Sagittal (L to R)
0033    outVol = permute(inVol,[3 1 2]);
0034    outVol(1:nZ,:,:) = outVol(nZ:-1:1,:,:);
0035    outVol(:,1:nX,:) = outVol(:,nX:-1:1,:);
0036    outVol(:,:,1:nY) = outVol(:,:,nY:-1:1);
0037 
0038 case -1 % Sagittal (R to L)
0039    outVol = permute(inVol,[3 1 2]);
0040    outVol(:,1:nX,:) = outVol(:,nX:-1:1,:);
0041    outVol(:,:,1:nY) = outVol(:,:,nY:-1:1);
0042 
0043 case  2  % Axial (I to S)
0044    outVol = inVol;
0045    outVol(:,1:nY,:) = outVol(:,nY:-1:1,:);
0046 
0047 case -2  % Axial (S to I)
0048    outVol = inVol;
0049    outVol(:,1:nY,:) = outVol(:,nY:-1:1,:);
0050    outVol(:,:,1:nZ) = outVol(:,:,nZ:-1:1);
0051 
0052 case  3 % Coronal (A to P)
0053    outVol = permute(inVol,[1 3 2]);
0054    outVol(:,:,1:nY) = outVol(:,:,nY:-1:1);
0055    outVol(:,1:nZ,:) = outVol(:,nZ:-1:1,:);
0056 
0057 case -3 % Coronal (P to A)
0058    outVol = permute(inVol,[1 3 2]);
0059    outVol(:,:,1:nY) = outVol(:,:,nY:-1:1);
0060 
0061 end
0062 
0063 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003