Home > fmri > utils > reslice_axial.m

reslice_axial

PURPOSE ^

SYNOPSIS ^

function reslice_axial(fname,VOX,BB)

DESCRIPTION ^

 function reslice_axial(fname,VOX,BB)

 Takes a file name fname and reslices it axially using trilinear
 interpolation to the space defined by it. 
 If VOX is not specified it defaults to [1 1 1].

 VOX = [3 3 3] for example asks for 3x3x3 mm voxels
 BB = bounding box of new image.  If this is left empty it will use the
 bounding box of the original image.

 Uses the spm function spm_write_sn and trilinear interpolation

 Souheil Inati
 Dartmouth College

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function reslice_axial(fname,VOX,BB)
0002 %
0003 % function reslice_axial(fname,VOX,BB)
0004 %
0005 % Takes a file name fname and reslices it axially using trilinear
0006 % interpolation to the space defined by it.
0007 % If VOX is not specified it defaults to [1 1 1].
0008 %
0009 % VOX = [3 3 3] for example asks for 3x3x3 mm voxels
0010 % BB = bounding box of new image.  If this is left empty it will use the
0011 % bounding box of the original image.
0012 %
0013 % Uses the spm function spm_write_sn and trilinear interpolation
0014 %
0015 % Souheil Inati
0016 % Dartmouth College
0017 
0018 % Modification history:
0019 % 10/12/01 PJ -- Added BB parameter
0020 
0021 if (nargin<2)
0022   VOX = [1 1 1];
0023 end
0024 
0025 if nargin<3
0026   BB = [];
0027 end
0028 
0029 V = spm_vol(fname);
0030 
0031 % Compute the bounding box
0032 % Find the mins and maxes
0033 if isempty(BB)
0034   lims1 = V.mat*[1 1 1 1]';
0035   lims2 = V.mat*[V.dim(1:3) 1]';
0036   coordlims = [ lims1(1:3) lims2(1:3) ];
0037   mins = [min(coordlims,[],2)];
0038   maxs = [max(coordlims,[],2)];
0039   BB = [mins';maxs'];
0040 end
0041 
0042 % Define the identity sn3d matrix and save it next to the image
0043 [imgpath,imgname] = fileparts(fname);
0044 sn3dfilename = fullfile(imgpath,'identity_sn3d.mat');
0045 mgc    = 960209;
0046 MF     = eye(4);
0047 MG     = eye(4);
0048 Affine = eye(4);
0049 Dims   = [1 1 1; 0 0 0; 1 1 1; 1 1 1; 1 1 1; 1 1 1];
0050 Transform = [];
0051 save(sn3dfilename,'mgc','Dims','Affine','MF','MG','Transform');
0052 
0053 % Use Trilinear interpolation
0054 Hold = 1;
0055 
0056 % Write it out
0057 spm_write_sn(fname,sn3dfilename,BB,VOX,Hold);
0058 
0059 % Clean Up
0060 delete(sn3dfilename)
0061 
0062 return

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