Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting fiducials read via mne.io.read_fiducials() to BIDS anatomical landmarks #968

Closed
hoechenberger opened this issue Feb 23, 2022 · 8 comments · Fixed by #977
Closed
Assignees
Milestone

Comments

@hoechenberger
Copy link
Member

hoechenberger commented Feb 23, 2022

MNE stores fiducials in the mri (surface RAS) coordinate system; however, BIDS requires MRI voxel coordinates. @alexrockhill has created the helpful function get_anat_landmarks() that generates landmarks in the correct coordinate system based on digitization points in an Info and a transformation matrix.

However, I now have a file created via the coregistration GUI (which internally calls mne.io.write_fiducials()), and there is no easy way to store these mri landmarks in my BIDS MRI's AnatomicalLandmarkCoordinates field.

I suppose we could modify get_anat_landmarks() to accept existing fiducials (or a path to a fiducials file), skip the first bits of processing it currently does with the Info and transfomation matrix, and convert the fiducials into the correct coordinate system.

WDYT?

cc @agramfort

@agramfort
Copy link
Member

agramfort commented Feb 23, 2022 via email

@alexrockhill
Copy link
Contributor

I'm probably missing something but why can't you pass the landmarks directly to write_anat?

@hoechenberger
Copy link
Member Author

I'm probably missing something but why can't you pass the landmarks directly to write_anat?

Because they're not in the correct coordinate system. MNE stores them in mri (which is actually MRI surface RAS, unless I'm mistaken), but write_anat() and the new update_anat_landmarks() expect MRI voxel coordinates.

@hoechenberger
Copy link
Member Author

can you show me how the code would look like?

Yes, in fact, I can try to make a proof-of-concept PR and we can see if it becomes a horrible mess or not ;)
But I won't have time for this until Friday

@agramfort
Copy link
Member

agramfort commented Feb 23, 2022 via email

@alexrockhill
Copy link
Contributor

One suggestion to look into would be whether it would be easier to apply the trans directly to the landmarks like it is done for montage.

@hoechenberger
Copy link
Member Author

hoechenberger commented Feb 23, 2022

One suggestion to look into would be whether it would be easier to apply the trans directly to the landmarks like it is done for montage.

In my case, I don't have a trans, and I may not even have an Info (actually I do have an Info, but there could be situations where I don't)

Based on the landmarks in mri alone + the FreeSurfer reconstructions available, it should be possible to go to voxel space, rigth?

@alexrockhill
Copy link
Contributor

alexrockhill commented Feb 23, 2022

The trans would be from the T1.mgz which you could just load with nibabel and get T1.header.get_vox2ras_tkr and invert it.

You could add a convenience function in _freesurfer.py too like estimate_head_mri_t to get the mri to voxel transform with the subject and subjects_dir.

@hoechenberger hoechenberger added this to the 0.10 milestone Mar 2, 2022
@hoechenberger hoechenberger self-assigned this Mar 4, 2022
hoechenberger added a commit to hoechenberger/mne-bids that referenced this issue Mar 4, 2022
hoechenberger added a commit to hoechenberger/mne-bids that referenced this issue Mar 4, 2022
hoechenberger added a commit that referenced this issue Mar 7, 2022
* Make update_anat_landmarks() accept fiducials file

Fixes #968

* Update mne_bids/sidecar_updates.py

* Update mne_bids/sidecar_updates.py

* We don't need zooming after all 😶‍🌫️

* Remove subject magic

* Deprecate behavior in get_head_mri_trans()

* Apply suggestions from code review

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

* Fix typos in comment

* Flake

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants