nipy / nibabel

Python package to access a cacophony of neuro-imaging file formats
http://nipy.org/nibabel/
Other
647 stars 257 forks source link

Reading CAT12 geometries #1265

Closed jescab01 closed 11 months ago

jescab01 commented 11 months ago

Dear all,

I am using CAT12 to perform the segmentation of MRI scans. It generates an output similar to Freesurfer's, however, the functions for Freesurfer i/o don't seem to work.

Is there any other way to reconstruct the geometries generated by CAT12? Would it be possible to implement a set of functions to do it?

Thanks in advance,

effigies commented 11 months ago

What format are the cat12 files in?

jescab01 commented 11 months ago

In CAT12, you get an output structured in 4 folders see documentation: mri (contains nifti files), surf (contains gifti and annot files), label (with regional information in .XML), and report.

effigies commented 11 months ago

Which of these files are you trying to open? You can open NIfTIs and GIFTIs with nibabel.load.

For NIfTI, you will get a Nifti1Image. This follows the spatial image API. We also have some docs on NIfTI in particular: Working with NIfTI images

For GIFTI, you will get a GiftiImage. GIFTI data is organized in data arrays, which are struc. The narrative docs are not as good here. The img.darrays will access GiftiDataArrays, which have .data and .meta for accessing the data and metadata, respectively.

The XML files are presumably according to some custom format of CAT12's; we don't currently have anything for working with them, but you can use something like lxml to access the data in an ad hoc way. I did not see any documentation about "annot" files.

jescab01 commented 11 months ago

I am using MNE package in Python to process MEG data. To do source reconstruction, I need to import an anatomical segmentation of the MRI data including surface geometries. To perform that import, MNE relies on nibabel\freesurfer\io "read_geometry" function that is specific for Freesurfer processed data.

Although the file types and folder structure are quite similar, CAT12 processed data cannot be loaded with that function:

Traceback (most recent call last): File "", line 2, in rr_mm, tris = mne.read_surface(fname) File "", line 12, in read_surface File "...\venv\lib\site-packages\mne\surface.py", line 895, in read_surface ret = read_geometry(fname, read_metadata=read_metadata) File "...\venv\lib\site-packages\nibabel\freesurfer\io.py", line 181, in read_geometry raise ValueError('File does not appear to be a Freesurfer surface') ValueError: File does not appear to be a Freesurfer surface

It has been commented on the MNE forum without much solution for the moment.

effigies commented 11 months ago

Right. You can't open GIFTIs using functions intended for FreeSurfer geometry files. They're simply not the same format. NiBabel will let you open these files, but what to do with the data is up to you. I do not know what CAT12 gives you, or what MNE is expecting in the line in your traceback (what is rr_mm supposed to be?), so I can't provide much guidance here.

Possibly @larsoner could provide some context. You could also try using FreeSurfer's mris_convert to convert GIFTI files to FreeSurfer format.

larsoner commented 11 months ago

I do not know what CAT12 gives you, or what MNE is expecting in the line in your traceback (what is rr_mm supposed to be?), so I can't provide much guidance here.

I am also not familiar with CAT12. I agree with @effigies you could try converting the GIFTI using mris_convert but as pointed out in https://mne.discourse.group/t/mne-python-and-cat12/6816/7 you're likely to hit problems at the MNE end. I don't think this is really a nibabel issue but rather a MNE one in the end so I'm inclined to close this issue and continue discussion in https://mne.discourse.group/t/mne-python-and-cat12/6816/7