Doxygen Source Code Documentation
AFNI_Index2XYZcontinuous.m
Go to the documentation of this file.00001 function [err,XYZdic] = AFNI_Index2XYZcontinuous (Indx, Info, CoordCode)
00002 %
00003 % [err,XYZdic] = AFNI_Index2XYZcontinuous (Indx, Info, [CoordCode])
00004 %
00005 %Purpose:
00006 % Change from voxel XYZindex (called Voxel Coords in AFNI) to XYZ in mm
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 % Indx an Mx3 matrix or an Mx1 vector containing the voxel indices to be
00014 % transformed to voxel coordinates. (indices start at 0)
00015 % Info is the output of BrikInfo
00016 % CoordCode is an optional parameter used to specify the coordinates system of the output
00017 % if empty or not specified, the default is 'RAI'. The code can be either a string or a vector
00018 % of numbers (see AFNI_CoordChange for more on that)
00019 %
00020 %Output Parameters:
00021 % err : 0 No Problem
00022 % : 1 Mucho Problems
00023 % XYZdic : The continuous coordinates corresponding to Indx
00024 % The coordnate system output is in RAI (DICOM)
00025 % unless otherwise specified by CoordCode
00026 %
00027 %
00028 %Key Terms:
00029 %
00030 %More Info :
00031 % BrikInfo
00032 % Test_AFNI_Index2XYZcontinuous
00033 % AFNI_XYZcontinuous2Index
00034 % Test_AFNI_XYZcontinuous2Index
00035 %
00036 % Author : Ziad Saad
00037 % Date : Tue Sep 5 21:48:06 PDT 2000 Latest Modification: Feb 18 04
00038 % LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00039
00040
00041 %Define the function name for easy referencing
00042 FuncName = 'AFNI_Index2XYZcontinuous';
00043
00044 %Debug Flag
00045 DBG = 1;
00046
00047 ChangeCoord = 0;
00048 if (nargin == 3)
00049 if (~isempty(CoordCode)),
00050 ChangeCoord = 1;
00051 end
00052 end
00053
00054
00055 %initailize return variables
00056 err = 1;
00057 XYZmm = [];
00058
00059 %make sure Indx is the right size
00060 switch size(Indx,2),
00061 case 1, %change 1D index to XYZ index
00062 [err, Indx] = AfniIndex2AfniXYZ (Indx, Info.DATASET_DIMENSIONS(1), Info.DATASET_DIMENSIONS(2))
00063 case 3, %OK
00064 otherwise,
00065 err = ErrEval(FuncName,'Err_Bad dimension for Indx');
00066 return
00067 end
00068
00069 XYZmm = Indx;
00070
00071 %The equations that would change the indices to coordinate system result in a coordinate system that
00072 % may be any permutation of RAI (like IRA or AIR or IAR or RIA or ARI) so one only needs to find the
00073 %dimension permutation needed to bring the final result to RAI.
00074
00075 %determine the ordering map to go from any permutation of RAI to RAI
00076 %[maploc(1),jnk] = find(Info.Orientation == 'R');
00077 %[maploc(2),jnk] = find(Info.Orientation == 'A');
00078 %[maploc(3),jnk] = find(Info.Orientation == 'I');
00079
00080 %pre - Wed May 23 18:20:56 PDT 2001 - WRONG !
00081 %XYZmm(:, maploc(1)) = Info.ORIGIN(1) + Indx(:,1) .* Info.DELTA(1);
00082 %XYZmm(:, maploc(2)) = Info.ORIGIN(2) + Indx(:,2) .* Info.DELTA(2);
00083 %XYZmm(:, maploc(3)) = Info.ORIGIN(3) + Indx(:,3) .* Info.DELTA(3);
00084
00085 %post - Wed May 23 18:20:56 PDT 2001 - WRONG!
00086 %XYZmm(:, 1) = Info.ORIGIN(maploc(1)) + Indx(:,maploc(1)) .* Info.DELTA(maploc(1));
00087 %XYZmm(:, 2) = Info.ORIGIN(maploc(2)) + Indx(:,maploc(2)) .* Info.DELTA(maploc(2));
00088 %XYZmm(:, 3) = Info.ORIGIN(maploc(3)) + Indx(:,maploc(3)) .* Info.DELTA(maploc(3));
00089
00090 %Feb 18 04, back to the original
00091 XYZmm(:, 1) = Info.ORIGIN(1) + Indx(:,1) .* Info.DELTA(1);
00092 XYZmm(:, 2) = Info.ORIGIN(2) + Indx(:,2) .* Info.DELTA(2);
00093 XYZmm(:, 3) = Info.ORIGIN(3) + Indx(:,3) .* Info.DELTA(3);
00094 %Now this is in the axis orientation which is Info.Orientation(:,1)' called 3dmm in thd_coords.c
00095 [err,XYZdic, map] = THD_3dmm_to_dicomm (Info, XYZmm);
00096
00097 if (ChangeCoord),
00098 [err, maplocation, mapsign, XYZdic] = AFNI_CoordChange ('RAI', CoordCode, XYZdic);
00099 end
00100
00101 err = 0;
00102 return;
00103