Home > bioelectromagnetism > avw2ctf.m

avw2ctf

PURPOSE ^

mri = avw2ctf(avw)

SYNOPSIS ^

function mri = avw2ctf(avw)

DESCRIPTION ^

 mri = avw2ctf(avw)

 The purpose of this function is to convert an Analyze volume into a CTF
 .mri volume.  It currently requires that the Analyze volume is
 256x256x256, 1x1x1 mm voxels.  The avw_read function can
 handle various Analyze orientations, so this function assumes that the
 avw.img volume has axial unflipped orientation (it always is when
 returned by avw_read, regardless of the format in the .img file). The
 returned mri struct in the matlab workspace can be saved using
 ctf_write_mri (available in the ctf module of the cvs repository, see
 http://eeg.sf.net/.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mri = avw2ctf(avw)
0002 
0003 % mri = avw2ctf(avw)
0004 %
0005 % The purpose of this function is to convert an Analyze volume into a CTF
0006 % .mri volume.  It currently requires that the Analyze volume is
0007 % 256x256x256, 1x1x1 mm voxels.  The avw_read function can
0008 % handle various Analyze orientations, so this function assumes that the
0009 % avw.img volume has axial unflipped orientation (it always is when
0010 % returned by avw_read, regardless of the format in the .img file). The
0011 % returned mri struct in the matlab workspace can be saved using
0012 % ctf_write_mri (available in the ctf module of the cvs repository, see
0013 % http://eeg.sf.net/.
0014 %
0015 
0016 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $
0017 
0018 % Licence:  GNU GPL, no implied or express warranties
0019 % History:  08/2003, Darren.Weber_at_radiology.ucsf.edu
0020 %                    - adapted from an appendex to CTF document
0021 %                    MRIConverter.pdf, which is copied at the end of this
0022 %                    function.
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 
0026 mri = ctf_make_mri;
0027 
0028 mri.file = [avw.fileprefix,'.mri'];
0029 
0030 
0031 ver = '[$Revision: 1.1 $]';
0032 fprintf('\nCTF_AVW2MRI [v%s]\n',ver(12:16));  tic;
0033 
0034 
0035 % these checks for the volume dims/pixel size could be replaced with an
0036 % interpolation function that could take any Analyze volume and convert it
0037 % to 256x256x256, 1x1x1 mm
0038 if avw.hdr.dime.dim(2) ~= 256,
0039     error('avw.hdr.dime.dim(2) ~= 256');
0040 end
0041 if avw.hdr.dime.dim(3) ~= 256,
0042     error('avw.hdr.dime.dim(3) ~= 256');
0043 end
0044 if avw.hdr.dime.dim(4) ~= 256,
0045     error('avw.hdr.dime.dim(4) ~= 256');
0046 end
0047 
0048 if avw.hdr.dime.pixdim(2) ~= 1,
0049     error('avw.hdr.dime.dim(2) ~= 256');
0050 end
0051 if avw.hdr.dime.pixdim(3) ~= 1,
0052     error('avw.hdr.dime.dim(3) ~= 256');
0053 end
0054 if avw.hdr.dime.pixdim(4) ~= 1,
0055     error('avw.hdr.dime.dim(4) ~= 256');
0056 end
0057 
0058 
0059 % mri.hdr.dataSize = 1 or 2 (bytes), 8 or 16 bits
0060 if avw.hdr.dime.bitpix == 8,
0061     mri.hdr.dataSize = 1;
0062     mri.hdr.clippingRange = 255;
0063 else
0064     mri.hdr.dataSize = 2;
0065     mri.hdr.clippingRange = 65536;
0066 end
0067 
0068 % This next step should always work correctly, given that avw_read always
0069 % converts any Analyze orientation into axial unflipped in the matlab
0070 % workspace variable avw.img; the axial unflipped orientation is
0071 % (+X left,  +Y anterior,  +Z superior); the ctf orientation is
0072 % (+X right, +Y posterior, +Z inferior), the complete opposite.
0073 temp = flipdim(avw.img,1);
0074 temp = flipdim(temp,2);
0075 temp = flipdim(temp,3);
0076 mri.img = temp;
0077 
0078 t=toc; fprintf('...done (%5.2f sec).\n\n',t);
0079 
0080 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003