gllmflndn / gifti

MATLAB/Octave GIfTI Library
https://www.gllmflndn.com/software/matlab/gifti/
MIT License
25 stars 12 forks source link

coordinate system #16

Open moskvich412 opened 6 months ago

moskvich412 commented 6 months ago

Dear Developer and contributors,

Given little documentation on the library, I have hard time figuring out how to specify two coordinate systems to be used for output of the same surface. I know GIFTI formal allows it. Similarly, when reading a GIFTI file, only one transformation (seems to be always the first) is loaded without attributes (anatomical, unknown, etc). How do I deal with these?

Thank you,

neurolabusc commented 6 months ago

@moskvich412 the specification does allow you to support different spatial transforms, though I doubt many tools will detect them. According to the GIFTI specification you can in theory encode different spatial transforms:

NIFTI_XFORM_UNKNOWN
NIFTI_XFORM_SCANNER_ANAT
NIFTI_XFORM_ALIGNED_ANAT
NIFTI_XFORM_TALAIRACH
NIFTI_XFORM_MNI_152

In general, most tools assume that GIfTI vertex positions are in world space. The only exception I know of is FreeSurfer, which can insert different transforms. To see these in action, try mris_convert with one of these options:

--to-scanner : convert coordinates from native FS (tkr) coords to scanner coords
--to-tkr : convert coordinates from scanner coords to native FS (tkr) coords

The GIfTI mesh is a XML format, so the result will look like this:

   <CoordinateSystemTransformMatrix>
      <DataSpace><![CDATA[NIFTI_XFORM_TALAIRACH]]></DataSpace>
      <TransformedSpace><![CDATA[NIFTI_XFORM_TALAIRACH]]></TransformedSpace>
      <MatrixData>
         1 0 0 0 
         0 1 0 0 
         0 0 1 0 
         0 0 0 1 
      </MatrixData>
   </CoordinateSystemTransformMatrix>

I do not know if this library reads, writes or preserves these transforms. Since they are so rarely used, I think they should be used with caution. GIFTI is an interchange format, so having compatibility with how it is implemented in the real world seems important.

moskvich412 commented 6 months ago

I totally agree with neurolabusc's last sentence: "GIFTI is an interchange format, so having compatibility with how it is implemented in the real world seems important." That is why I ask how coordinate system is dealt with in this library.

I do not see a way to specify coordinates when I save GIFTI using this librar. I also do not see second coordinate transformation nor values for DataSpace/TransformedSpace attributes when I load a GIFTI file. It is possible I am doing something wrong. It is possible these are not currently implemented in the library. Hence the question: Which of these two?