Home > bioelectromagnetism > freesurfer_read_cor.m

freesurfer_read_cor

PURPOSE ^

SYNOPSIS ^

function [cor,M] = fmri_ldcor(subject,arg2,arg3)

DESCRIPTION ^

 Loads the indicated corronal slices from 
   $SUBJECTS_DIR/subject/mri/volumeid

 cor = fmri_ldcor(subject)                
 cor = fmri_ldcor(subject,volumeid)
 cor = fmri_ldcor(subject,slices)
 cor = fmri_ldcor(subject,volid,slices)

 If unspecified, volumeid defaults to T1.
 If unspecified, nslices defaults to [1:256].

 $Id: freesurfer_read_cor.m,v 1.1 2004/11/12 01:32:34 psdlw Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [cor,M] = fmri_ldcor(subject,arg2,arg3)
0002 %
0003 % Loads the indicated corronal slices from
0004 %   $SUBJECTS_DIR/subject/mri/volumeid
0005 %
0006 % cor = fmri_ldcor(subject)
0007 % cor = fmri_ldcor(subject,volumeid)
0008 % cor = fmri_ldcor(subject,slices)
0009 % cor = fmri_ldcor(subject,volid,slices)
0010 %
0011 % If unspecified, volumeid defaults to T1.
0012 % If unspecified, nslices defaults to [1:256].
0013 %
0014 % $Id: freesurfer_read_cor.m,v 1.1 2004/11/12 01:32:34 psdlw Exp $
0015 
0016 if(nargin < 1 | nargin > 3)
0017   msg = 'USAGE: cor = fmri_ldcor(subject,<volid>,<slices>)';
0018   qoe(msg);error(msg);
0019 end
0020 
0021 volumeid = 'T1';
0022 slices   = [1:256];
0023 
0024 if(nargin == 2)
0025   if(ischar(arg2)) volumeid = arg2;
0026   else             slices   = arg2;
0027   end
0028 end
0029 
0030 if(nargin == 3)
0031   if(ischar(arg2)) volumeid = arg2;
0032   else             slices   = arg2;
0033   end
0034   if(ischar(arg3)) volumeid = arg3;
0035   else             slices   = arg3;
0036   end
0037 end
0038 
0039 if(min(slices) < 1)
0040   msg = sprintf('Min Slice No = %d, must be > 0',min(slices));
0041   qoe(msg);error(msg);
0042 end
0043 
0044 if(max(slices) > 256)
0045   msg = sprintf('Max Slice No = %d, must be <= 256',max(slices));
0046   qoe(msg);error(msg);
0047 end
0048 
0049 
0050 subject = deblank(subject);
0051 volumeid = deblank(volumeid);
0052 
0053 SubjectsDir = deblank(getenv('SUBJECTS_DIR'));
0054 if(isempty(SubjectsDir))
0055   msg = 'Cannot find SUBJECTS_DIR environment variable';
0056   qoe(msg);error(msg);
0057 end
0058 
0059 SubjDir = strcat(SubjectsDir,'/',subject);
0060 CorDir  = strcat(SubjDir,'/mri/',volumeid);
0061 
0062 d = dir(CorDir);
0063 if(isempty(d))
0064   CorDir = deblank(subject);
0065   d = dir(CorDir);
0066   if(isempty(d))
0067     msg = sprintf('Directory %s does not exist (DIR=%s, SD=%s)', ...
0068                 CorDir,volumeid, SubjectsDir);
0069     qoe(msg);error(msg);
0070   end
0071 end
0072 
0073 nslices = length(slices);
0074 cor = zeros(256,nslices,256);
0075 
0076 Endian = 0;
0077 precision = 'uint8';
0078 Nv = 256*256;
0079 
0080 fprintf(1,'Loading coronals from subject %s, volume %s, %d slices ... \n',...
0081         subject,volumeid,nslices);
0082 
0083 for s = 1:nslices,
0084 
0085   n = slices(s);
0086 
0087   corfile = sprintf('%s/COR-%03d',CorDir,n);
0088   d = dir(corfile);
0089   if(isempty(d))
0090     msg = sprintf('File %s does not exist',corfile);
0091     qoe(msg);error(msg);
0092   end
0093   
0094   %%%% Open the corfile %%%%%
0095   if(Endian == 0) fid=fopen(corfile,'r','b'); % Big-Endian
0096   else            fid=fopen(corfile,'r','l'); % Little-Endian
0097   end
0098   if(fid == -1)
0099     msg = sprintf('Could not open %s for reading.',corfile); 
0100     qoe(msg); error(msg);
0101   end
0102 
0103   %%% Read the file in corfile %%%
0104   z = fread(fid,Nv,precision);
0105   cor(:,:,s) = reshape(z, [256 256])'; %' transpose for row major
0106   fclose(fid); 
0107 
0108 end
0109 
0110 %cor = permute(cor, [3 2 1]);
0111 
0112 M = [0,-1,0,129;0,0,1,-129;-1,0,0,129;0,0,0,1];
0113 
0114 return;

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