Home > rest_20090422 > rest_spm5_files > @read_nifti > subsref.m

subsref

PURPOSE ^

Subscript referencing

SYNOPSIS ^

function varargout = subsref(opt,subs)

DESCRIPTION ^

 Subscript referencing

 Fields are:
 dat         - a file-array representing the image data
 mat0        - a  9-parameter affine transform (from qform0)
               Note that the mapping is from voxels (where the first
               is considered to be at [1,1,1], to millimetres.  See
               mat0_interp for the meaning of the transform.
 mat         - a 12-parameter affine transform (from sform0)
               Note that the mapping is from voxels (where the first
               is considered to be at [1,1,1], to millimetres.  See
               mat1_interp for the meaning of the transform.
 mat_intent  - intention of mat.  This field may be missing/empty.
 mat0_intent - intention of mat0. This field may be missing/empty.
 intent      - interpretation of image. When present, this structure
               contains the fields
               code   - name of interpretation
               params - parameters needed to interpret the image
 diminfo     - MR encoding of different dimensions.  This structure may
               contain some or all of the following fields
               frequency  - a value of 1-3 indicating frequency direction
               phase      - a value of 1-3 indicating phase direction
               slice      - a value of 1-3 indicating slice direction
               slice_time - only present when "slice" field is present.
                            Contains the following fields
                            code     - ascending/descending etc
                            start    - starting slice number
                            end      - ending slice number
                            duration - duration of each slice acquisition
               Setting frequency, phase or slice to 0 will remove it.
 timing      - timing information.  When present, contains the fields
               toffset - acquisition time of first volume (seconds)
               tspace  - time between sucessive volumes (seconds)
 descrip     - a brief description of the image
 cal         - a two-element vector containing cal_min and cal_max
 aux_file    - name of an auxiliary file
 _______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

subsref.m

SOURCE CODE ^

0001 function varargout = subsref(opt,subs)
0002 % Subscript referencing
0003 %
0004 % Fields are:
0005 % dat         - a file-array representing the image data
0006 % mat0        - a  9-parameter affine transform (from qform0)
0007 %               Note that the mapping is from voxels (where the first
0008 %               is considered to be at [1,1,1], to millimetres.  See
0009 %               mat0_interp for the meaning of the transform.
0010 % mat         - a 12-parameter affine transform (from sform0)
0011 %               Note that the mapping is from voxels (where the first
0012 %               is considered to be at [1,1,1], to millimetres.  See
0013 %               mat1_interp for the meaning of the transform.
0014 % mat_intent  - intention of mat.  This field may be missing/empty.
0015 % mat0_intent - intention of mat0. This field may be missing/empty.
0016 % intent      - interpretation of image. When present, this structure
0017 %               contains the fields
0018 %               code   - name of interpretation
0019 %               params - parameters needed to interpret the image
0020 % diminfo     - MR encoding of different dimensions.  This structure may
0021 %               contain some or all of the following fields
0022 %               frequency  - a value of 1-3 indicating frequency direction
0023 %               phase      - a value of 1-3 indicating phase direction
0024 %               slice      - a value of 1-3 indicating slice direction
0025 %               slice_time - only present when "slice" field is present.
0026 %                            Contains the following fields
0027 %                            code     - ascending/descending etc
0028 %                            start    - starting slice number
0029 %                            end      - ending slice number
0030 %                            duration - duration of each slice acquisition
0031 %               Setting frequency, phase or slice to 0 will remove it.
0032 % timing      - timing information.  When present, contains the fields
0033 %               toffset - acquisition time of first volume (seconds)
0034 %               tspace  - time between sucessive volumes (seconds)
0035 % descrip     - a brief description of the image
0036 % cal         - a two-element vector containing cal_min and cal_max
0037 % aux_file    - name of an auxiliary file
0038 % _______________________________________________________________________
0039 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0040 
0041 %
0042 % $Id: subsref.m 253 2005-10-13 15:31:34Z guillaume $
0043 
0044 
0045 varargout = rec(opt,subs);
0046 return;
0047 
0048 function c = rec(opt,subs)
0049 switch subs(1).type,
0050 case {'.'},
0051     c = {};
0052     opts = struct(opt);
0053     for ii=1:numel(opts)
0054         opt = class(opts(ii),'read_nifti');
0055         %if ~isstruct(opt)
0056         %    error('Attempt to reference field of non-structure array.');
0057         %end;
0058 
0059         h = opt.hdr;
0060         if isempty(h),
0061             %error('No header.');
0062             h = empty_hdr;
0063         end;
0064 
0065         % NIFTI-1 FORMAT
0066         switch(subs(1).subs)
0067         case 'extras',
0068             t = opt.extras;
0069 
0070         case 'raw', % A hidden field
0071             if isa(opt.dat,'create_file_array'),
0072                 tmp         = struct(opt.dat);
0073                 tmp.scl_slope = [];
0074                 tmp.scl_inter = [];
0075                 t           = create_file_array(tmp);
0076             else
0077                 t = opt.dat;
0078             end;
0079 
0080         case 'dat',
0081             t = opt.dat;
0082 
0083         case 'mat0',
0084             t = decode_qform0(h);
0085             s = double(bitand(h.xyzt_units,7));
0086             if s
0087                 d = findindict(s,'units');
0088                 if ~isempty(d)
0089                     t = diag([d.rescale*[1 1 1] 1])*t; 
0090                 end;
0091             end;
0092 
0093         case 'mat0_intent',
0094             d = findindict(h.qform_code,'xform');
0095             if isempty(d) || d.code==0,
0096                 t = '';
0097             else
0098                 t = d.label;
0099             end;
0100 
0101         case 'mat',
0102             if h.sform_code > 0
0103                 t = double([h.srow_x ; h.srow_y ; h.srow_z ; 0 0 0 1]);
0104                 t = t * [eye(4,3) [-1 -1 -1 1]'];
0105             else
0106                 t = decode_qform0(h);
0107             end
0108             s = double(bitand(h.xyzt_units,7));
0109             if s
0110                 d = findindict(s,'units');
0111                 t = diag([d.rescale*[1 1 1] 1])*t;
0112             end;
0113 
0114         case 'mat_intent',
0115             if h.sform_code>0,
0116                 t = h.sform_code;
0117             else
0118                 t = h.qform_code;
0119             end;
0120             d = findindict(t,'xform');
0121             if isempty(d) || d.code==0,
0122                 t = '';
0123             else
0124                 t = d.label;
0125             end;
0126 
0127         case 'intent',
0128             d = findindict(h.intent_code,'intent');
0129             if isempty(d) || d.code == 0,
0130                 %t = struct('code','UNKNOWN','param',[]);
0131                 t = [];
0132             else
0133                 t = struct('code',d.label,'param',...
0134                     double([h.intent_p1 h.intent_p2 h.intent_p3]), 'name',deblank(h.intent_name));
0135                 t.param = t.param(1:length(d.param));
0136             end
0137 
0138          case 'diminfo',
0139             t   = [];
0140             tmp = bitand(         h.dim_info    ,3); if tmp, t.frequency = double(tmp); end;
0141             tmp = bitand(bitshift(h.dim_info,-2),3); if tmp, t.phase     = double(tmp); end;
0142             tmp = bitand(bitshift(h.dim_info,-4),3); if tmp, t.slice     = double(tmp); end;
0143             % t = struct('frequency',bitand(         h.dim_info    ,3),...
0144             %               'phase',bitand(bitshift(h.dim_info,-2),3),...
0145             %               'slice',bitand(bitshift(h.dim_info,-4),3))
0146             if isfield(t,'slice')
0147                  sc = double(h.slice_code);
0148                  ss = double(h.slice_start)+1;
0149                  se = double(h.slice_end)+1;
0150                  ss = max(ss,1);
0151                  se = min(se,double(h.dim(t.slice+1)));
0152 
0153                  sd = double(h.slice_duration);
0154                  s  = double(bitand(h.xyzt_units,24));
0155                  d  = findindict(s,'units');
0156                  if d.rescale, sd = sd*d.rescale; end;
0157 
0158                  ns       = (se-ss+1);
0159                  d = findindict(sc,'sliceorder');
0160                  if isempty(d)
0161                      label = 'UNKNOWN';
0162                  else
0163                      label = d.label;
0164                  end;
0165                  t.slice_time = struct('code',label,'start',ss,'end',se,'duration',sd);
0166                  if 0, % Never
0167                      t.times  = zeros(1,double(h.dim(t.slice+1)))+NaN;
0168                      switch sc,
0169                      case 0, % Unknown
0170                          t.times(ss:se)        = zeros(1,ns);
0171                      case 1, % sequential increasing
0172                          t.times(ss:se)        = (0:(ns-1))*sd;
0173                      case 2, % sequential decreasing
0174                          t.times(ss:se)        = ((ns-1):-1:0)*sd;
0175                      case 3, % alternating increasing
0176                          t.times(ss:2:se)      = (0:floor((ns+1)/2-1))*sd;
0177                          t.times((ss+1):2:se)  = (floor((ns+1)/2):(ns-1))*sd;
0178                      case 4, % alternating decreasing
0179                          t.times(se:-2:ss)     = (0:floor((ns+1)/2-1))*sd;
0180                          t.times(se:-2:(ss+1)) = (floor((ns+1)/2):(ns-1))*sd;
0181                      end;
0182                  end;
0183              end;
0184 
0185         case 'timing',
0186             to = double(h.toffset);
0187             dt = double(h.pixdim(5));
0188             if to==0 && dt==0,
0189                 t = [];
0190             else
0191                 s  = double(bitand(h.xyzt_units,24));
0192                 d  = findindict(s,'units');
0193                 if d.rescale,
0194                     to = to*d.rescale;
0195                     dt = dt*d.rescale;
0196                 end;
0197                 t  = struct('toffset',to,'tspace',dt);
0198             end;
0199 
0200         case 'descrip',
0201             t   = deblank(h.descrip);
0202             msk = find(t==0);
0203             if any(msk), t=t(1:(msk(1)-1)); end;
0204 
0205         case 'cal',
0206             t = [double(h.cal_min) double(h.cal_max)];
0207             if all(t==0), t = []; end;
0208 
0209         case 'aux_file',
0210             t = deblank(h.aux_file);
0211 
0212         case 'hdr', % Hidden field
0213             t = h;
0214 
0215         otherwise
0216             error(['Reference to non-existent field ''' subs(1).subs '''.']);
0217         end;
0218         if numel(subs)>1,
0219             t = subsref(t,subs(2:end));
0220         end;
0221         c{ii} = t;
0222     end;
0223 case {'{}'},
0224     error('Cell contents reference from a non-cell array object.');
0225 case {'()'},
0226     opt  = struct(opt);
0227     t    = subsref(opt,subs(1));
0228     if length(subs)>1
0229         c = {};
0230         for i=1:numel(t),
0231             ti = class(t(i),'read_nifti');
0232             ti = rec(ti,subs(2:end));
0233             c  = {c{:}, ti{:}};
0234         end;
0235     else
0236         c    = {class(t,'read_nifti')};
0237     end;
0238 
0239 otherwise
0240     error('This should not happen.');
0241 end;

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