Home > bioelectromagnetism > brik2mgh.m

brik2mgh

PURPOSE ^

BRIK2MGH function to read 3D+time AFNI BRIK

SYNOPSIS ^

function BRIK2MGH(fname,xdim,ydim,zdim,timepoints,type,foutstem)

DESCRIPTION ^

 BRIK2MGH function to read 3D+time AFNI BRIK
 of any type and dimensionality and convert
 to MGH-style bshort of bfloat files and 
 accompanying MGH header files

 Example: this writes out 16 .bshort and .hdr files
 BRIK2MGH('/data9/mike/AS/afni/ASt3avvr+orig.BRIK',64,64,16,100,'short','test_')

 Written December 11, 1998 by Timothy M. Ellmore
 Laboratory of Brain and Cognition, NIMH

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function BRIK2MGH(fname,xdim,ydim,zdim,timepoints,type,foutstem)
0002 % BRIK2MGH function to read 3D+time AFNI BRIK
0003 % of any type and dimensionality and convert
0004 % to MGH-style bshort of bfloat files and
0005 % accompanying MGH header files
0006 %
0007 % Example: this writes out 16 .bshort and .hdr files
0008 % BRIK2MGH('/data9/mike/AS/afni/ASt3avvr+orig.BRIK',64,64,16,100,'short','test_')
0009 %
0010 % Written December 11, 1998 by Timothy M. Ellmore
0011 % Laboratory of Brain and Cognition, NIMH
0012 
0013 disp(' ')
0014 disp('**********************************')
0015 disp(' ')
0016 disp('BRIK2MGH: reading raw data . . . .')
0017 fid = fopen(fname, 'rb');
0018 data = fread(fid, [xdim * ydim * zdim * timepoints], type);
0019 disp(['max: ' num2str(max(data(:))) ', min: '  num2str(min(data(:))) ])
0020 fclose(fid);
0021 disp('BRIK2MGH: done reading raw data !')
0022 disp(' ')
0023 
0024 disp('BRIK2MGH: reshaping raw data to 3D+time matrix . . . .')
0025 V = reshape(data,xdim,ydim,zdim,timepoints);
0026 disp('BRIK2MGH: done reshaping raw data to 3D+time matrix !')
0027 disp(' ')
0028 
0029 disp('BRIK2MGH: writing MGH-style image files . . . .')
0030 disp(' ')
0031 
0032 bfile =  zeros(xdim,ydim,timepoints);
0033 
0034 % cycle over slices and make a volume
0035 % where the new zdimension is timpoints
0036 
0037 for i = 1:zdim
0038 
0039  % make file of timepoints
0040  bfile(:,:,:) = V(:,:,i,:);
0041 
0042  % create the bfile name
0043  suffix = ['.b' type];
0044  outfname = sprintf('%s%03d%s%s',foutstem,i-1,suffix);
0045 
0046  % write out the bfile
0047  
0048  disp(['BRIK2MGH: writing file ' num2str(outfname) ', max: ' num2str(max(bfile(:))) ', min: ' num2str(min(bfile(:))) ])
0049  fid = fopen(outfname, 'w');
0050  fwrite(fid, bfile(:), type);
0051  fclose(fid);
0052 
0053  % write out a header file
0054  hdrfname = sprintf('%s%03d%s',foutstem,i-1,'.hdr');
0055  fid = fopen(hdrfname,'w');
0056  fprintf(fid,'%d %d %d 0\n',xdim, ydim, timepoints);
0057  fclose(fid);
0058 
0059 end
0060 
0061 disp(' ')
0062 disp('Done!')
0063 
0064 
0065       
0066 
0067     
0068       
0069         
0070

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