Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


AFNI_XYZcontinuous2Index.m

Go to the documentation of this file.
00001 function [err,Indx] = AFNI_XYZcontinuous2Index (XYZmm, Info, CoordCode, IndexDim)
00002 %
00003 %   [err,Indx] = AFNI_XYZcontinuous2Index (XYZmm, Info, [CoordCode], [IndexDim])
00004 %
00005 %Purpose:
00006 %   Change from voxel XYZ in mm to XYZindex (called Voxel Coords in AFNI) 
00007 %   The mm and voxel coordinates refer to the values displayed 
00008 %   on the top left corner of AFNI controller.
00009 %   CoordCode is the one you'd set from the Coord Order plugin
00010 %   
00011 %   
00012 %Input Parameters:
00013 %   XYZmm : The continuous coordinates corresponding to Indx
00014 %       The coordnate system is assumed to be RAI (DICOM) 
00015 %       unless otherwise specified by CoordCode
00016 %   Info is the output of BrikInfo
00017 %   CoordCode is an optional parameter used to specify the coordinates system of XYZmm
00018 %      if empty or not specified, the default is 'RAI'. The code can be either a string or a vector 
00019 %      of numbers (see AFNI_CoordChange for more on that)
00020 %   IndexDim (3 or 1) is an optional parameter used to specify if Indx is Mx3 or Mx1 vector
00021 %      (see AfniIndex2AfniXYZ for more info)
00022 %       The default is 3 . If you choose to specify IndexDim, you must specify CoordCode 
00023 %      (you could use an empty string to leave CoordCode to the default)
00024 %   
00025 %Output Parameters:
00026 %   err : 0 No Problem
00027 %       : 1 Mucho Problems
00028 %   Indx an Mx3 matrix or an  Mx1 vector (depending on IndexDim)
00029 %        containing the voxel indices to be
00030 %        transformed to voxel coordinates.  (indices start at 0)
00031 %   
00032 %   
00033 %      
00034 %Key Terms:
00035 %   
00036 %More Info :
00037 %   BrikInfo
00038 %   Test_AFNI_XYZcontinuous2Index
00039 %   AFNI_Index2XYZcontinuous
00040 %   Test_AFNI_Index2XYZcontinuous
00041 %   
00042 %
00043 %     Author : Ziad Saad
00044 %     Date : Thu Sep 7 16:50:38 PDT 2000        Latest Modification: Feb 18 04
00045 %     LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00046 
00047 
00048 %Define the function name for easy referencing
00049 FuncName = 'AFNI_XYZcontinuous2Index';
00050 
00051 %Debug Flag
00052 DBG = 1;
00053 
00054 ChangeCoord = 0;
00055 if (nargin > 2)
00056         if (~isempty(CoordCode)),
00057                 ChangeCoord = 1;
00058         end
00059 end
00060 
00061 ChangeDim = 0;
00062 if (nargin == 4),
00063         if (~isempty(IndexDim)),
00064                 ChangeDim = 1;
00065         end
00066 end
00067 
00068 %initailize return variables
00069 err = 1;
00070 Indx = [];
00071 
00072 
00073 Indx = XYZmm;
00074 
00075 %make sure coordinate system is RAI
00076 if (ChangeCoord),
00077         [err, maplocation, mapsign, XYZdic] = AFNI_CoordChange (CoordCode, 'RAI', XYZmm);
00078 else 
00079    XYZdic = XYZmm;
00080 end
00081 
00082 % now change dicomm to 3dmm
00083 [err, XYZmm, map] = THD_dicomm_to_3dmm (Info, XYZdic);
00084 
00085         %The equations that would change the coordinate system to indices must take the indces in the same
00086         %RAI permutation that the slices are entered into to3d in (No need to worry about R versus L or A versus P)
00087         %determine the ordering map to go from any permutation of RAI to RAI
00088                 %[maploc(1),jnk] = find(Info.Orientation == 'R');
00089                 %[maploc(2),jnk] = find(Info.Orientation == 'A');
00090                 %[maploc(3),jnk] = find(Info.Orientation == 'I');
00091 
00092                 %pre - Wed May 23 18:20:56 PDT 2001 - WRONG !
00093                 %Indx(:,1) = round( ( XYZmm(:, maploc(1)) - Info.ORIGIN(1) ) ./ Info.DELTA(1) );
00094                 %Indx(:,2) = round( ( XYZmm(:, maploc(2)) - Info.ORIGIN(2) ) ./ Info.DELTA(2) );
00095                 %Indx(:,3) = round( ( XYZmm(:, maploc(3)) - Info.ORIGIN(3) ) ./ Info.DELTA(3) );
00096                 
00097                 %post - Wed May 23 18:20:56 PDT 2001 - WRONG !
00098                 %Indx(:,maploc(1)) = round( ( XYZmm(:, 1) - Info.ORIGIN(maploc(1)) ) ./ Info.DELTA(maploc(1)) );
00099                 %Indx(:,maploc(2)) = round( ( XYZmm(:, 2) - Info.ORIGIN(maploc(2)) ) ./ Info.DELTA(maploc(2)) );
00100                 %Indx(:,maploc(3)) = round( ( XYZmm(:, 3) - Info.ORIGIN(maploc(3)) ) ./ Info.DELTA(maploc(3)) );
00101                 
00102       %Feb 18 04
00103       Indx(:,1) = round( ( XYZmm(:, 1) - Info.ORIGIN(1) ) ./ Info.DELTA(1) );
00104                 Indx(:,2) = round( ( XYZmm(:, 2) - Info.ORIGIN(2) ) ./ Info.DELTA(2) );
00105                 Indx(:,3) = round( ( XYZmm(:, 3) - Info.ORIGIN(3) ) ./ Info.DELTA(3) );
00106                 
00107       ineg = find(Indx < 0);
00108                 if (~isempty(ineg)), Indx(ineg) = 0; end
00109                 
00110                 [iover] = find(Indx(:,1) >  Info.DATASET_DIMENSIONS(1)-1);
00111                 if (~isempty(iover)), Indx(iover, 1) = Info.DATASET_DIMENSIONS(1)-1;    end
00112                 
00113                 [iover] = find(Indx(:,2) >  Info.DATASET_DIMENSIONS(2)-1);
00114                 if (~isempty(iover)), Indx(iover, 2) = Info.DATASET_DIMENSIONS(2)-1;    end
00115                 
00116                 [iover] = find(Indx(:,3) >  Info.DATASET_DIMENSIONS(3)-1);
00117                 if (~isempty(iover)), Indx(iover, 3) = Info.DATASET_DIMENSIONS(3)-1;    end
00118                 
00119                         
00120         %Now, if needed, change the Index dimension from Mx3 to Mx1
00121         if (ChangeDim & IndexDim == 1),
00122                  [err, Indx] = AfniXYZ2AfniIndex (Indx, Info.DATASET_DIMENSIONS(1), Info.DATASET_DIMENSIONS(2));  
00123         end
00124         
00125 err = 0;
00126 return;
00127 
 

Powered by Plone

This site conforms to the following standards: