0001 function [outVol] = GE_convertT2PD(inDir,outstub)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 img_types = {'PD','T2'};
0029 ntypes = length(img_types);
0030
0031 status = 1;
0032
0033 if (nargin < 2)
0034 error('Not enough input arguments.')
0035 return
0036 end
0037
0038 for itype = 1:ntypes
0039 fprintf('Working on conversion of %s image...\n', img_types{itype});
0040
0041
0042 firstfile = fullfile(inDir,sprintf('I.%03d', itype));
0043
0044
0045 fprintf('Getting header info from: %s\n', firstfile);
0046 [header, orient, im_offset, adwcount] = GE_createSPMHeader(firstfile);
0047 volSize = [header.dim(2) header.dim(3) header.dim(4)];
0048
0049
0050 header = GE_reorientHeader(header, orient);
0051
0052 imageVol = zeros(volSize);
0053 for islice = 1:volSize(3)
0054
0055 curr_fname = fullfile(inDir,sprintf('I.%03d',(islice-1)*2+itype));
0056
0057
0058 fid = fopen(curr_fname,'rb');
0059 if fid == -1
0060 fprintf('Failed to open: %s\n', curr_fname);
0061 imageVol = [];
0062 status = 0;
0063 return
0064 end
0065
0066
0067 fseek(fid,im_offset+1,-1);
0068 buffer = fread(fid,volSize(1:2),sprintf('ubit%d',header.bitpix));
0069
0070
0071 imageVol(:,:,islice) = reshape(buffer,volSize(1),volSize(2));
0072
0073
0074 fclose(fid);
0075 end
0076
0077
0078 imageVol = GE_reorientImage(imageVol, orient);
0079
0080 outName = sprintf('%s_%s',outstub,img_types{itype});
0081
0082
0083 outFile = strcat(outName,'.hdr');
0084 status = GE_writeSPMHeader(outFile,header);
0085
0086
0087 outFile = [outName sprintf('.img')];
0088 [fid,message] = fopen(outFile,'w');
0089 if (fid == -1)
0090 fprintf('Cannot Open %s for writing.\n',outFile);
0091 error(message);
0092 end
0093
0094 fwrite(fid,reshape(imageVol,1,prod(size(imageVol))),'int16');
0095 status = fclose(fid);
0096
0097
0098 fprintf('Wrote %s.img.\n',outName);
0099 end
0100
0101
0102 fprintf('\nConversion Finished. \n');
0103
0104 return