Home > rest_20090422 > rest_spm5_files > @read_nifti > private > mayo2nifti1.m

mayo2nifti1

PURPOSE ^

Convert from an ANALYZE to a NIFTI-1 header

SYNOPSIS ^

function hdr = mayo2nifti1(ohdr,mat)

DESCRIPTION ^

 Convert from an ANALYZE to a NIFTI-1 header
 _______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

mayo2nifti1.m

SOURCE CODE ^

0001 function hdr = mayo2nifti1(ohdr,mat)
0002 % Convert from an ANALYZE to a NIFTI-1 header
0003 % _______________________________________________________________________
0004 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0005 
0006 %
0007 % $Id: mayo2nifti1.m 253 2005-10-13 15:31:34Z guillaume $
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; %  int8
0032 case 132, hdr.datatype = 512; % uint16
0033 case 136, hdr.datatype = 768; % uint32
0034 end;
0035 
0036 if nargin<2,
0037     % No mat, so create the equivalent from the hdr...
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         %disp(['Assuming that image is stored left-handed']);
0047         mat = diag([-1 1 1 1])*mat;
0048     else
0049         %disp(['Assuming that image is stored right-handed']);
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

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005