-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
WIP: Generate subject fiducials #6693
Conversation
@jhouck do you want to iterate on this based on comments or would you rather I push commits? For example, you have a hard-coded path in there... :) |
Codecov Report
@@ Coverage Diff @@
## master #6693 +/- ##
==========================================
+ Coverage 89.41% 89.42% +<.01%
==========================================
Files 416 417 +1
Lines 75253 75406 +153
Branches 12355 12369 +14
==========================================
+ Hits 67289 67430 +141
- Misses 5148 5157 +9
- Partials 2816 2819 +3 |
@larsoner I won't quit my day job just yet. ;) Either is fine; happy to iterate with comments or if you've got the time feel free to hop in and push commits. |
For what it's worth I also looked into getting more precise landmarks using images produced from the outer skin surface with tools like opencv & scikit-image. Nasion might be do-able since it seems to be a pretty commonly used keypoint. I stopped pursuing it when it started to look like the fsaverage fiducials would work. |
This pull request introduces 2 alerts when merging fad3f12 into d3a7142 - view on LGTM.com new alerts:
|
Rendered example looks like a good start https://14813-1301584-gh.circle-artifacts.com/0/dev/auto_examples/forward/plot_auto_alignment.html |
nice
we need to see how to handle the use of the private code...
… |
If the pipeline looks OK, could put a new function in coreg to run all the private functions from gui? The private functions are all from gui, but none is actually graphical, so it wouldn't necessarily make sense there. The example would then be maybe 5 lines of code. :) One small related issue is that there seem to be three independent ways to calculate the coreg error: |
mne/coreg.py
Outdated
fids_default, coord_frame = read_fiducials(fname_fids_fs) | ||
xfm_tal = np.matrix(_read_fs_xfm(fname_tal)[0]) | ||
|
||
# Get Freesurfer vox2ras and vox2ras-tkr as matrices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment just states what we can read in the code before.
Instead of this, it would be nice if you could give some rationale / background about the different coordinate systems instead. When reading the code, that's what I usually struggle to understand as these are not so well-documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I used https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems as my reference for the transformation stuff. There's also good content on this in the plot_source_alignment tutorial. Would a pointer to these be useful, or are you thinking that it would be more helpful to include a condensed version of some of that content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need to overhaul coord frame docs, there is an issue about it. It's particularly critical in two places: 1) vol source space, and 2) vol morphing. So I'd rather tackle it in a general overhaul rather than here.
But I will say that we ship the fs fids with MNE so you should just use that and not rely on them being in the subjects_dir
that the user passes:
https://github.com/mne-tools/mne-python/tree/master/mne/data/fsaverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can include a link to the transformation details for the curious, and leave out the specifics for now.
I think the fsaverage fids are coming from the testing data right now, not from subjects_dir
(i.e., from .io.tests import data_dir as fsaverage_dir
& fname_fids_fs = op.join(fsaverage_dir, 'fsaverage-fiducials.fif')
-- in the function, subjects_dir
is only used to get the subject's transformations. It would definitely make more sense to get them from the location you provided, rather than from the testing data.
Regarding "private" code -- I think your PR basically shows what we'd need to use for it. I thought about how we could make these things all functions, but a class is probably justified here. The coregistration process really does have a state associated with it (things to omit, current head<->MRI trans, etc.). So maybe it actually makes sense to just make the |
(but regarding the code dup you point out, we should ideally reduce it somehow, though it's possible/likely they are all doing slightly different things, so maybe one function with some options is the way to go) |
Yes, they're all doing slightly different things. Maybe add an option for Line 423 in 0600f81
mne-python/mne/gui/_coreg_gui.py Lines 702 to 703 in 3769993
|
This pull request introduces 2 alerts when merging 6dee5a7 into 3769993 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 1f27976 into 3769993 - view on LGTM.com new alerts:
|
I won't have much time to look at this PR these days. To have a real look I'd like to play with some more datasets eg cam-can to see how much we can advertise some automated approach for coreg. Maybe someone wants to beat me to it... |
@agramfort That was my first testing dataset, back before the fiducials thing was working well. If I'd noticed sooner that the coreg files had been released I would have added a section to the reliability paper. Which is a long way of saying that this will not take me very long to do... |
For cam-can, the Neuroimage paper earlier this year reported the coreg error as "on the order of 0.5 cm." Using the transformation files from https://github.com/tbardouille/camcan_coreg, I'm getting mean coreg error of 2.358 mm (SD=0.523). The mean coreg error from the auto-coreg is 1.776 mm (SD=0.514). This is unexpected, as in my other sample manual coregistration performed a little better than automatic. There might be some differences in the surfaces, since everyone is running Freesurfer independently with the camcan MRIs. In the cam-can sample, the auto coreg improves a bit if I allow the parameters to vary by subject (only 10% done that way, it's a somewhat slower process, but on average about a 0.3 mm further reduction in error so far, relative to the value reported above). https://gist.github.com/jhouck/c3a2a3ceae1c5a27af6f568f6cd9641c So far, the auto coreg seems to be working pretty well. I can update again tomorrow after the other 500 subjects have run through the updated version. |
@agramfort In the new, improved version from the above gist, mean auto-coreg error for cam-can (computed by The coreg error reported by In terms of the fit parameters, for the initial ICP fit after aligning fiducials and before dropping outliers, most subjects (53.3%) had their best fit with 5 or fewer iterations; 17.1% did best with 20 or more. For the final ICP fit, the vast majority of subjects (88.6%) did best with a nasion weight of 5. At that same fit, most subjects (63.0%) achieved their best fit with 10 iterations; for the remaining subjects it was 20 (12.4%), 30 (9.0%), 40 (7.0%), or 50 (8.7%) iterations. For the auto-coreg, coreg error was weakly correlated with the percentage of head points retained in the final ICP fit (r = -0.244, p < .001). This effect was stronger for the manual cam-can coreg (r = -0.540, p < .001), although again these are the points not dropped as outliers by Happy to attached the output (tab-delimited text) if there's a way to do that and anyone wants to see it. |
thx for the detailed report.
to expose such auto-registration tool so users who you just make the class
public?
as a not so small remark we should have this feature available without
traits and mayavi.
… |
See also #6728, but even with this I agree visualization should be optional. |
This has an example we should adapt somehow |
Thoughts on what to do with the example? |
this is not a simple issue. Example makes public a lot of code that was never meant to be. Suddenly we would need to maintain the API of this code while it was just internal to the GUI. This API was never discussed in PRs as it was just GUI. What I would do is propose a public API that does not depend of traits / vtk to do the job. It means some work to decouple GUI code from the model. |
Closing as this example is noted in the |
What does this implement/fix?
This PR would add a little helper function
get_mni_fiducials
to estimate the locations of a subject's fiducial points by transforming the fsaverage fiducials to the subject's MRI coordinate space (RAS). It also adds an exampleplot_auto_alignment
that applies the results.While the helper function is not exactly earthshattering on its own, if the fiducials are saved to the default location, they can be used in the mne coreg gui to perform an automated co-registration. In my data (and in the sample dataset) the results are usually well below the > 2 mm coreg threshold. The parameters in the example probably need to be tweaked a little, but you get the gist.