0001 function hdr = mayo2nifti1(ohdr,mat)
0002
0003
0004
0005
0006
0007
0008
0009
0010 if isfield(ohdr,'magic'),
0011 hdr = ohdr;
0012 return;
0013 end;
0014 hdr = empty_hdr;
0015 hdr.dim = ohdr.dim;
0016 hdr.datatype = ohdr.datatype;
0017 hdr.bitpix = ohdr.bitpix;
0018 hdr.pixdim = ohdr.pixdim;
0019 hdr.vox_offset = ohdr.vox_offset;
0020 hdr.scl_slope = ohdr.roi_scale;
0021 hdr.scl_inter = ohdr.funused1;
0022 hdr.descrip = ohdr.descrip;
0023 hdr.aux_file = ohdr.aux_file;
0024 hdr.glmax = ohdr.glmax;
0025 hdr.glmin = ohdr.glmin;
0026 hdr.cal_max = ohdr.cal_max;
0027 hdr.cal_min = ohdr.cal_min;
0028 hdr.magic = 'ni1';
0029
0030 switch hdr.datatype,
0031 case 130, hdr.datatype = 256;
0032 case 132, hdr.datatype = 512;
0033 case 136, hdr.datatype = 768;
0034 end;
0035
0036 if nargin<2,
0037
0038 if any(ohdr.origin(1:3)), origin = double(ohdr.origin(1:3));
0039 else origin = (double(ohdr.dim(2:4))+1)/2; end;
0040 vox = double(ohdr.pixdim(2:4));
0041 if all(vox == 0), vox = [1 1 1]; end;
0042 off = -vox.*origin;
0043 mat = [vox(1) 0 0 off(1) ; 0 vox(2) 0 off(2) ; 0 0 vox(3) off(3) ; 0 0 0 1];
0044 flp = nic_spm_flip_analyze_images;
0045 if flp,
0046
0047 mat = diag([-1 1 1 1])*mat;
0048 else
0049
0050 end;
0051 end;
0052
0053 hdr = encode_qform0(mat,hdr);
0054 mat = mat*[eye(4,3) [1 1 1 1]'];
0055 hdr.srow_x = mat(1,:);
0056 hdr.srow_y = mat(2,:);
0057 hdr.srow_z = mat(3,:);
0058 hdr.qform_code = 2;
0059 hdr.sform_code = 2;
0060 return;
0061