Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


GE_createSPMmat.m

Go to the documentation of this file.
00001 %%%%%%%%%%%%%%%%%%%%%%%%
00002 %                      %
00003 % Write SPM mat file   %
00004 %                      %
00005 %%%%%%%%%%%%%%%%%%%%%%%%
00006 function M = GE_createSPMmat(im_hdr, scandir)
00007 %
00008 % Put the appropriate translations and rotations to the M matrix
00009 % given the information in the image header and the direction of
00010 % acquisition
00011 %
00012 % S. Inati
00013 % Dartmouth College
00014 % Apr. 2001
00015 %
00016 
00017 % The conversion from pixels to mm
00018 Dims = diag( [im_hdr.pixsize_X, ...
00019               im_hdr.pixsize_Y, ...
00020               im_hdr.slthick + im_hdr.scanspacing ]);
00021 
00022 % Compute the coordinate system in the image plane
00023 tlhc = [ im_hdr.tlhc_R; im_hdr.tlhc_A; im_hdr.tlhc_S ]; % Top Left Hand Corner of Image
00024 trhc = [ im_hdr.trhc_R; im_hdr.trhc_A; im_hdr.trhc_S ]; % Top Right Hand Corner of Image
00025 brhc = [ im_hdr.brhc_R; im_hdr.brhc_A; im_hdr.brhc_S ]; % Bottom Right Hand Corner of Image
00026 
00027 x = trhc - tlhc; x = x./sqrt(x'*x);   % xhat
00028 y = trhc - brhc; y = y./sqrt(y'*y);   % yhat
00029 
00030 % The normal to the plane
00031 norm = [ im_hdr.norm_R; im_hdr.norm_A; im_hdr.norm_S ];
00032 % The directional normal
00033 z = scandir * norm;   % zhat
00034 
00035 % Build the M matrix for SPM
00036 % M takes a voxel from the image and gives it a coordinate in mm
00037 % On the scanner the voxels start in the top left hand corner of the
00038 % first image.  In SPM they start in the bottom left hand corner,
00039 % so flip y and set the origin to tlhc.
00040 % NB: The voxel (1,1,1) should have position tlhc
00041 Rot = [x, -y, z];
00042 M = eye(4);
00043 M(1:3,1:3) = Rot  * Dims;
00044 M(1:3,4) = tlhc - Rot*Dims*[1;1;1];
00045 
00046 return
 

Powered by Plone

This site conforms to the following standards: