pycortex icon indicating copy to clipboard operation
pycortex copied to clipboard

Make the freesurfer input work for T1-weighted data that is not 1mm resoultion

Open Gilles86 opened this issue 5 years ago • 3 comments

Hi,

I tried to use pycortex with my 7T mp2rage data at a resolution of 0.64mm and I just couldn't get it to work. The volumes always seemed to be sampled wrong, whatever transformation matrix I would use, even for the very T1w images the segmentations were built on (identity matrix, fsl BBR, import of freesurfer, import of fsl...).

After some digging, I noticed that when I imported the freesurfer segmentations using cortex.freesurfer.import_subj, the resulting giftis that were put in the db-folder were already not properly aligned: screenshot 2018-12-06 11 02 10

After digging some more, I found this piece of code that corrects the gifti coordinates to be RAS coordinates: https://github.com/gallantlab/pycortex/blob/bbc17412f41a46406a0b801a6ff8c2e1995a92a0/cortex/freesurfer.py#L144

This seems to assume that the anatomicals are always 256x256x256 voxels and at a resolution of 1 mm, like the standard freesurfer pipelines spit out. However, my data is different: I have 256x320x320 voxels at a resolution of 0.64 mm. I think there will be more people like me.

I revised the code, using Freesurfer's mris_convert to go to gii and borrowing very heavily on the work by the fmriprep folks to correct to RAS coordinates (who apparently base their work on the HPC preprocessing pipeline): https://github.com/poldracklab/fmriprep/blob/master/fmriprep/interfaces/surf.py#L193

What do guys you think?

Gilles86 avatar Dec 06 '18 10:12 Gilles86

So I rebased this commit to the latest upstream/master version. Can someone of the core pycortex team have a look at this gain?

For my research the submillimeter resolution is really necessary, but I also want to stay in sync with the latest upstream updates.

Gilles86 avatar Feb 08 '19 10:02 Gilles86

@alexhuth @jamesgao Sorry to badger you, but is there any way you could merge this pul request? We're moving our entire lab to high-res anatomies and we'd like to be able to keep using pycortex. If you have any questions, please ask me or @Gilles86 Thanks!

tknapen avatar Feb 22 '19 09:02 tknapen

Any chance you guys can rebase these commits off the latest head? The diff is pretty hard to read because of doc updates. If possible, a cleaner commit history would also be highly appreciated!

Also, since we don't have any higher resolution anatomicals to test this with, adding a test would also let us know if this code actually works or not.

jamesgao avatar Feb 25 '19 20:02 jamesgao

Hi @Gilles86 @tknapen, sorry it took so long but I guess it's better late than never :-) I finally got my hands on a sub-mm T1 and could replicate the bug. This bug will be fixed as soon as we merge #531.

For PyCortex's purposes, I think it's sufficient to use mris_convert --to-scanner rather than using the fixes from fMRIPrep (now in sMRIprep: https://www.nipreps.org/smriprep/0.11.1/api/smriprep.interfaces.surf.html#smriprep.interfaces.surf.NormalizeSurf).

If you have a chance to test the new code, please let me know if it works with your files too. We will push a new pycortex release soon with this new fix.

mvdoc avatar Apr 05 '24 19:04 mvdoc

Note also that the surfaces imported into pycortex will not look aligned to the T1 when opened with freeview (this happens also with surfaces computed on 1mm isotropic data). But they will work fine in pycortex.

mvdoc avatar Apr 05 '24 21:04 mvdoc

I will close this PR as the bug has been fixed. Please feel free to open an issue if there are still problems with importing sub-mm volumes.

mvdoc avatar Apr 08 '24 22:04 mvdoc