avw2cor - converts an avw struct to FreeSurfer COR-* files avw2cor(avw,CORpath) avw - Analyze volume, see avw_read CORpath - full path to FreeSurfer directory This function will translate an 8-bit uchar AVW file to a series of MGH-style COR files that also have an 8-bit uchar datatype. Example: avw2cor(avw,'/data/subjects/bert/mri/orig') will use the workspace avw struct and output files named /data/subjects/bert/mri/orig/COR-[0-256] However, it is probably best to use the FreeSurfer command line tool, mri_convert, as it will handle various datatypes and it will reslice Analyze volumes that are not 256^3 mm FOV and 1^3 mm voxels.
0001 function avw2cor(avw,CORpath) 0002 0003 % avw2cor - converts an avw struct to FreeSurfer COR-* files 0004 % 0005 % avw2cor(avw,CORpath) 0006 % 0007 % avw - Analyze volume, see avw_read 0008 % 0009 % CORpath - full path to FreeSurfer directory 0010 % 0011 % This function will translate an 8-bit 0012 % uchar AVW file to a series of MGH-style 0013 % COR files that also have an 8-bit uchar 0014 % datatype. 0015 % 0016 % Example: avw2cor(avw,'/data/subjects/bert/mri/orig') 0017 % will use the workspace avw struct and output files 0018 % named /data/subjects/bert/mri/orig/COR-[0-256] 0019 % 0020 % However, it is probably best to use the FreeSurfer 0021 % command line tool, mri_convert, as it will handle 0022 % various datatypes and it will reslice Analyze 0023 % volumes that are not 256^3 mm FOV and 1^3 mm 0024 % voxels. 0025 % 0026 0027 % An AFNI BRIK volume may be formed from the resulting 0028 % COR files by using the AFNI command: 0029 % to3d -anat -prefix raw -session $SUBJECTS_DIR/$subjname/afni \ 0030 % -view orig -datum byte -orient LSP \ 0031 % $SUBJECTS_DIR/$subjname/mri/orig/COR-\[0-256]\* 0032 0033 0034 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $ 0035 0036 % Licence: GNU GPL, no express or implied warranties 0037 % History: 1/21/99: Timothy M. Ellmore, LBC/NIMH 0038 % Aug 2003, Darren.Weber_at_radiology.ucsf.edu 0039 % Adapted to mri_toolbox 0040 % 0041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0042 0043 version = '[$Revision: 1.1 $]'; 0044 fprintf('\nAVW2COR [v%s]\n',version(12:16)); tic; 0045 0046 if ~exist('avw','var'), 0047 doc avw2cor; 0048 msg = sprintf('...no input avw\n'); 0049 error(msg); 0050 elseif isempty(avw), 0051 doc avw2cor; 0052 msg = sprintf('...empty input avw\n'); 0053 error(msg); 0054 end 0055 0056 % MGH COR files have these dimensions 0057 xdim = 256; 0058 ydim = 256; 0059 zdim = 256; 0060 0061 % datatype is always 8-bit uchar for MGH COR files 0062 type = 'uchar'; 0063 0064 % this function used to read in an avwfile, but 0065 % it now takes a workspace avw struct, so the 0066 % conversion process requires avw_read first 0067 %avw = avw_read(AVWfile); 0068 0069 0070 % check that avw.img is the right dimensions 0071 dim = avw.hdr.dime.dim(2:4); 0072 if (dim(1) == xdim) & (dim(2) == ydim) & (dim(3) == zdim), 0073 % OK we have the right dimensions 0074 else 0075 %should try to reslice the volume, but not sure if 0076 %this works properly, as meshgrid is a strange beast. 0077 %[xi,yi,zi] = meshgrid(1:1:256,1:1:256,1:1:256); 0078 %reslice = interp3(avw.img,xi,yi,zi); 0079 error('...avw.img is not 256x256x256 voxels, reslice it.\n'); 0080 end 0081 0082 0083 % extract sliceplanes and write COR files 0084 0085 for i = 1:ydim, 0086 0087 % COR files are coronal slices, so we assume 0088 % the analyze file was read correctly by avw_read 0089 % and we use the ydim to loop over coronal slices 0090 0091 % create zero sliceplane 0092 CORfile = zeros(xdim,zdim); 0093 0094 % extract the current sliceplane 0095 CORfile(:,:) = avw.img(:,i,:); 0096 0097 % create the CORfile name 0098 CORfname = [CORpath,filesep,sprintf('COR-%03d',i)]; 0099 0100 if i > 1, 0101 backspaces = repmat('\b',1,7); 0102 else 0103 backspaces = ''; 0104 end 0105 fprintf([backspaces,'%s image.'],sprintf('COR-%03d',i)); 0106 0107 fid = fopen(CORfname, 'w'); 0108 fwrite(fid, CORfile(:), type); 0109 fclose(fid); 0110 0111 end