Repository navigation
WIP: MRI/Head Coregistration / Scaling FsAverage #379
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
Closed
Closed
Changes from all commits
Commits
Show all changes
151 commits
Select commit
Hold shift + click to select a range
18bfbd4
ENH: i/o for fiducials fiff files
christianbrodbeck 7bc1440
ENH coreg: add MriHeadFitter
christianbrodbeck 943b7db
ENH: add GUIs: MriHeadCoreg, FixDigHeadShape, FindDigPoint
christianbrodbeck 8f6f093
ENH: import shortcuts / mne.gui module
christianbrodbeck ffa1be9
DOC
christianbrodbeck 0137428
ENH: mri fitting with scaling
christianbrodbeck d44fbc7
ENH geom: wireframe plotting (line_width=1 and lighting=False)
christianbrodbeck 297c9f8
FIX coreg: MriHeadFitter
christianbrodbeck 43242e4
ENH: MRI-Head coregistration GUI
christianbrodbeck 206efec
FIX: MriHeadFitter.save_all() default trans fname; HeadMriFitter raw …
christianbrodbeck 268ae25
FIX coreg
christianbrodbeck cc928a3
ENH: MriHeadCoreg fit & save progress bars
christianbrodbeck 664f1c3
ENH coreg-gui: dialog text
christianbrodbeck d0bbfd4
ADD: fit_matched_pts() from t3on/tb-mne_kit2fiff
christianbrodbeck 24bf311
ENH: add Fiducials GUI
christianbrodbeck a9c83b5
ENH coreg: make subject attribute public
christianbrodbeck 27c539a
ENH: add HeadMriCoreg GUI
christianbrodbeck 355cee4
ENH: add fit using fiducials to head-mri coreg
christianbrodbeck 5bcba09
ENH Fiducials: load fiducials file as initial state
christianbrodbeck 7ab5cbc
FIX coreg
christianbrodbeck 068fd83
RF: use HeadViewer baseclass
christianbrodbeck ed5af03
STY
christianbrodbeck de11d17
ENH: mne.gui
christianbrodbeck 33dbdbb
ENH: add scale to HeadViewer
christianbrodbeck 4d2ab70
ENH: find files for mri scaling (follow symlinks)
christianbrodbeck 3852026
ENH mri-head coreg: call mne_setup_foward_model with check_output
christianbrodbeck b72b919
ENH: mri scaling src handling
christianbrodbeck c66b56e
ENH: move configure_traits() out of __init__
christianbrodbeck 9572cd9
ENH find_mri_paths(): don't raise an error if no source spaces are found
christianbrodbeck 9b25c6d
ENH: provisional wrappers for mne_watershed_bem and mne_setup_mri
christianbrodbeck a84baf1
ENH: add mne.create_default_subject()
christianbrodbeck bd976ca
ENH: allow customization of trans_fname
christianbrodbeck 224a53c
ENH: add combine_markers GUI
christianbrodbeck 193d0c3
ENH kit coreg read_hsp(): limit number of points
christianbrodbeck c555b03
FIX: coreg_gui
christianbrodbeck f93927c
ENH: KIT coregistration
christianbrodbeck f4ef1bb
ADD: viewer module for HeadViewController, PointObject, SurfaceObject
christianbrodbeck fa9b763
OPT apply_transform: only transpose trans
christianbrodbeck 011f429
ENH: add coord_trans() function for transform between different coord…
christianbrodbeck 068d00a
ENH marker_gui
christianbrodbeck fa13936
ADD kit2fiff_gui
christianbrodbeck 2915612
ADD fiducials_gui
christianbrodbeck 5fc6a1b
update mne.gui: add fiducials()
christianbrodbeck 41e8f6f
ENH coreg: proper error message
christianbrodbeck 0ae53c9
ENH: coreg / MRI scaling
christianbrodbeck 0618dc1
kit2fiff_gui
christianbrodbeck 579c01c
viewer
christianbrodbeck b78f108
ENH: RawKIT.__repr__
christianbrodbeck a0b65f0
ENH transforms: add rotation3d
christianbrodbeck 9be190c
ADD file_traits
christianbrodbeck 608253a
marker GUI
christianbrodbeck 746e213
ENH source_space: add mne_prepare_bem_model and mne_setup_source_spac…
christianbrodbeck 9131a20
ADD manual page
christianbrodbeck 1d8eaff
coreg_gui
christianbrodbeck e6996c6
viewer
christianbrodbeck 60f6a73
fiducials_gui
christianbrodbeck b042b37
mne.gui
christianbrodbeck 503d136
amend mne.fiff.kit.test_coreg
christianbrodbeck 80456a7
manual
christianbrodbeck b27138e
ENH fiff.kit.coreg.read_elp(): assert correct number of points
christianbrodbeck 5b2b962
marker_gui
christianbrodbeck 211abe0
FIX fiff.kit: read AD channels (by @t3on); Allow .mrk extension fo…
christianbrodbeck 558f607
ki2fiff_gui
christianbrodbeck 86ce00c
ENH kit2fiff: add slope argument for stim channel conversion.
teonbrooks 08be04c
coreg_gui: expose picker tolerance
christianbrodbeck 84f1246
mne.source_space
christianbrodbeck 06b1753
ENH coreg: create_default_subject() add option to create source space
christianbrodbeck a831f93
ENH source_space: logging for subprocesses
christianbrodbeck d099fdd
FIX change the default endian and trigger slope
teonbrooks 20b2afe
ENH read sns info from the sqd
teonbrooks 4a54996
FIX kit2fiff_gui: remove sns file
christianbrodbeck 23edd41
ENH RawKIT: extract (and expose) .set_stimchannels() method
christianbrodbeck 2ca7720
ENH kit2fiff_gui Abu Dhabi compatibility
christianbrodbeck 6bb9b5e
DOC: error message when loading non-continuus sqd
christianbrodbeck 40c0d9c
FIX source_space subprocess call
christianbrodbeck aaced2f
coreg_gui
christianbrodbeck b07d5cb
coreg_gui: fit evaluation
christianbrodbeck 61482e9
kit2fif_gui
christianbrodbeck ddcc6cf
tranforms.apply_trans(): allow trans with shape (3, 3)
christianbrodbeck e0a418e
kit2fiff: DOC
christianbrodbeck 860063d
fiff/kit.py amend
christianbrodbeck ed379c1
marker_gui: show distance for each marker
christianbrodbeck c9c2bb8
ENH coreg_gui: warn if MNE_ROOT is not set
christianbrodbeck 439a5de
mne.gui
christianbrodbeck b3b9142
kit2fiff_gui
christianbrodbeck 3c34a8e
marker_gui
christianbrodbeck b3c608d
coreg (prune)
christianbrodbeck df641be
expose more functions in mne.transforms
christianbrodbeck 0d0ff6a
ENH RawKIT: allow saving without dig/trans
christianbrodbeck eca77ff
ENH kit2fiff_gui: allow saving without dig/trans
christianbrodbeck ae30262
STY: move all gui scripts to a separate package
christianbrodbeck e02df5d
FIX fiducials gui fiducials order
christianbrodbeck 03fa4cc
coreg: DOC/cleanup
christianbrodbeck 1db83cd
coreg_gui
christianbrodbeck e3b68eb
ENH wrapers for mne_prepare_bem_model and mne_setup_source_space
christianbrodbeck fa87298
ENH run_subprocess(): make stdout/stderr headings more discernible
christianbrodbeck e8b2626
mne.__init__: add setup_source_space()
christianbrodbeck 0670295
cleanup (DOC, pep8 etc.)
christianbrodbeck a841537
ENH kit2fiff_gui: threaded conversion processing
christianbrodbeck c6d7d0c
ENH coreg_gui: threaded background processing
christianbrodbeck c591ce1
FIX coreg_gui: deal with empty subjects_dir
christianbrodbeck 6978e86
ENH SubjectSelector: add "create fsaverage" option
christianbrodbeck 12fba89
RawKIT: STY: method names to set digitizer data; RF: integrate get_…
christianbrodbeck 0fed6c6
FIX coreg_gui / fiducially panel: don't allow locking incomplete fid…
christianbrodbeck 60baaaf
DOC: manual
christianbrodbeck e20d069
ENH coreg_gui: interactivity
christianbrodbeck 874faab
API: expose more functions in mne.transforms
christianbrodbeck b91841c
ENH coreg_gui: disable immediate interpretation of scale1 parameter …
christianbrodbeck 9b9234a
ENH coreg_gui: add resolution option to GUI viewer PointObject for h…
christianbrodbeck 82f6ff3
FIX coreg_gui: NewMriDialog feedback behavior
christianbrodbeck 9c99e7e
STY fiducials_gui: make attribute names all lowercase
christianbrodbeck b495305
ENH coreg_gui: fiducials picker uses cell picker
christianbrodbeck cddc35d
ENH fiducials_gui: one array editor to edit current fiducial position
christianbrodbeck a12bc9f
ENH coreg_gui: 3 column view
christianbrodbeck eb0640b
ENH coreg_gui: display processing info as multiple lines
christianbrodbeck 0a29f18
ENH kit2fiff_gui: specify view height
christianbrodbeck 26e2bff
DOC/STY
christianbrodbeck 1df301d
ENH transforms: supplant coord_trans () and transform_ALS_to_RAS() w…
christianbrodbeck 448db15
FIX coreg_gui: don't allow mne_setup_source_space without mne_prepar…
christianbrodbeck 7d9b52c
FIX coreg_gui: qt4 backend compatibility
christianbrodbeck 84ed321
FIX SubjectSelector: "Make FsAverage" as button instead of drop down…
christianbrodbeck 896ce5a
STY coreg_gui: group subject trait synchronization commands
christianbrodbeck c4de928
FIX coreg_gui: in assert_env_set, also add mne/bin directory to PATH
christianbrodbeck 87da754
FIX coreg_gui: on initialization, ignore subjects_dir if it is not a…
christianbrodbeck fa21eb8
REV/DOC KIT head shapes: drop support for pickled head shapes
christianbrodbeck 9d2fd60
TEST
christianbrodbeck 6d7f4be
TEST coreg: fit_matched_points
christianbrodbeck a50417a
ENH coreg: make fit_ functions more similar
christianbrodbeck d7ae2f3
ENH kit2fiff: automatically decimate head shape points for files wit…
christianbrodbeck f2a8666
TEST coreg: fit_point_cloud
christianbrodbeck 3e04175
ENH coreg_gui: default MRI head shape color
christianbrodbeck 6da8f85
STY in kit2fiff TEST
christianbrodbeck ccf5dd4
API: expose more in mne.transforms
christianbrodbeck 35d06e6
FIX/TEST kit2fiff: transformation into MNE head coordinates
christianbrodbeck 63b4c49
STY
christianbrodbeck 1c5c442
ENH coreg_gui: set busy cursor when fitting
christianbrodbeck e139ab4
ENH scale_labels(): option to include all labels
christianbrodbeck 9423f47
DOC: coregistration manual
christianbrodbeck 4f64fc9
ENH gui: show info dialogs in assert_env
christianbrodbeck 3fff170
ENH mri scaling: make scaling source spaces optional
christianbrodbeck 741b27b
ENH coreg_gui layout: axis labels
christianbrodbeck da29e0c
FIX coreg_gui: don't open error message in worker thread
christianbrodbeck 0faba00
DOC corey manual: note on mne_analyze
christianbrodbeck 1004dc6
ENH kit.coreg: add and TEST write_mrk()
christianbrodbeck 26a770d
TEST scale_mri
christianbrodbeck 6823882
ENH run_subprocess: on error, log stdout and stderr as error
christianbrodbeck 22ee81f
FIX kit: open sqd file in binary mode
christianbrodbeck 822a4bc
FIX: update setup.py
christianbrodbeck dffbb03
ENH read_raw_kit: default mrk, elp and hsp to None
christianbrodbeck f43daf9
FIX coreg_gui: don't do fit-evaluation when impossible
christianbrodbeck 8f51683
ENH coreg_gui: adjust trans parameters with step buttons
christianbrodbeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| ============= | ||
| Python Manual | ||
| ============= | ||
|
|
||
| .. _mne-coreg-info: | ||
|
|
||
| MRI-Head Coregistration in Python | ||
| ================================= | ||
|
|
||
| MRI-Head coregistration is traditionally done in mne_analyze (see | ||
| :ref:`CHDBEHDC`). An alternative is a GUI in Python, which is described below. | ||
| The Python GUI uses a less sophisticated algorithm for matching the head shape | ||
| to the MRI, but it allows scaling the fsaverage brain to match an individual | ||
| subject's head shape. | ||
|
|
||
| The Python coregistration GUI is invoked with:: | ||
|
|
||
| >>> mne.gui.coregistration() | ||
|
|
||
| Different procedures are outlined below for :ref:`coreg-with-mri` and | ||
| :ref:`coreg-without-mri`. | ||
|
|
||
| .. Note:: | ||
| For many GUI elements like buttons, contextual help is available by | ||
| hovering the mouse pointer over the relevant controls. | ||
|
|
||
|
|
||
| .. _coreg-with-mri: | ||
|
|
||
| Subjects with MRI | ||
| ----------------- | ||
|
|
||
| #. **Data Source** Panel: | ||
|
|
||
| #. Make sure that ``subjects_dir`` is set correctly, to the directory | ||
| containing your MRIs. | ||
| #. Load your raw file. Now you should see your digitizer head shape points | ||
| on the left. | ||
| #. You should then be able to select the MRI in the ``Subject`` drop-down | ||
| menu. | ||
|
|
||
|
|
||
| .. _coreg-gui-fiducials: | ||
|
|
||
| #. **MRI Fiducials** Panel: | ||
|
|
||
| #. If the MRI already has a fiducials file they will be automatically | ||
| loaded and "Lock" will be selected. In this case you can skip this panel. | ||
| If fiducials are not loaded, "Edit" will be selected and "Lock" will not | ||
| be selectable until the fiducials are defined. | ||
| #. If a fiducials file exists for the MRI, it can be loaded. Alternatively, | ||
| the fiducial points can be set manually by selecting the relevant point | ||
| (nasion, LAP, RAP) and then clicking on the head model. | ||
| #. Once all fiducials are set, the result can be saved (optionally) and then | ||
| accepted by selecting "Lock" at the top of the panel. | ||
|
|
||
| #. **Coregistration** Panel: Use the lower half of the panel to fit the head | ||
| model to the MRI without scaling the MRI. | ||
|
|
||
| #. The position of head and MRI are initially aligned using the nasion. The | ||
| nasion position will be held constant during the fitting procedure. Use | ||
| the "Digitizer Position Adjustment" fields to adjust the nasion position | ||
| of the digitizer head shape relative to the MRI. | ||
| #. Press one of the "Fit..." buttons to find a transformation that brings | ||
| the head shape as close as possible to the MRI: | ||
|
|
||
| - **Fit Head Shape** estimates rotation parameters that minimize the | ||
| distance from each digitizer point to the closest MRI point. | ||
| - **Fit LAP/RAP** estimates rotation parameters that minimize the | ||
| distance between the LAPs and RAPs | ||
| - **Fit Fiducials** estimates rotation and translation that minimizes | ||
| the distance between all three fiducials. | ||
|
|
||
| #. Once a satisfactory coregistration is achieved, hit "Save" to save | ||
| the trans file. | ||
|
|
||
|
|
||
| .. _coreg-without-mri: | ||
|
|
||
| Subjects without MRI | ||
| -------------------- | ||
|
|
||
| For subjects for which no structural MRI model is available, a generic brain | ||
| model can be substituted. The default is to use the *fsaverage* brain that | ||
| comes with Freesurfer_, however, any valid MRI subject can be used. | ||
|
|
||
|
|
||
| #. **Data Source** panel: | ||
|
|
||
| #. Make sure that ``subjects_dir`` is set correctly, to the directory | ||
| which contains (or is to contain) your MRIs. | ||
| #. Load your raw file. Now you should see your digitizer head shape points | ||
| on the left. | ||
| #. You should then be able to select any existing MRI in the ``Subject`` | ||
| drop-down menu and "Create FsAverage" if the subjects dir does not | ||
| already contain an item of that name. | ||
|
|
||
| #. **MRI Fiducials** Panel: Since the fsaverage brain comes with preset | ||
| fiducials, "Lock" should be selected automatically and you will not have to | ||
| do anything. If you are using a brain without fiducials, refer to the | ||
| :ref:`MRI Fiducials Panel section <coreg-gui-fiducials>` above. | ||
|
|
||
| #. **Coregistration** Panel: Select whether to scale with one factor (same | ||
| scaling along x, y and z axes) or with 3 factors (separate scaling factor | ||
| for each axis). Then, use the upper half of the panel to find a proper | ||
| scaling and the lower half of the panel to adjust the positioning without | ||
| affecting the scale. | ||
|
|
||
| #. The position of head and MRI are initially aligned using the nasion. The | ||
| nasion position will be held constant with most fitting functions. Use | ||
| the "Translation" fields to adjust the initial nasion position of the | ||
| digitizer head shape relative to the MRI. | ||
| #. If the initial rotation of the head shape seems very off, use the | ||
| "Fit LAP/RAP" button to bring the heads into approximately overlapping | ||
| orientation. | ||
| #. Use the upper row of "Fit..." buttons to find a transformation that | ||
| fits the MRI within the head shape. | ||
|
|
||
| - **Fit Head Shape** estimates scaling and rotation parameters that | ||
| minimize the distance from each head shape point to the closest MRI | ||
| point. | ||
| - **Fit LAP/RAP** estimates scaling and rotation parameters that | ||
| minimize the distance between the LAPs and RAPs. | ||
| - **Fit Fiducials** estimates scaling, translation and rotation | ||
| parameters that minimize the distance between all three fiducials. | ||
| - All the parameters can also be manually adjusted in the text fields. | ||
|
|
||
| #. Once a satisfactory coregistration is achieved, hit "Save" to save the | ||
| MRI as well as the trans file. In the dialog that opens, specify the name | ||
| of the new subject (i.e. the folder that is going to be created in the | ||
| subjects directory), and which mne utilities should be run (normally the | ||
| default should be ok), then hit "ok". Source spaces can also be produced | ||
| later by running :func:`mne.setup_source_space`. | ||
| #. While the MRI is processed in the background you can keep working with | ||
| the GUI, you can coregister another subject in the same Window. | ||
|
|
||
| If new labels are added to the fsaverage brain after scaling it, these labels | ||
| can be transferred to scaled copies using :func:`mne.transforms.scale_labels`. | ||
|
|
||
|
|
||
| .. _Freesurfer: http://surfer.nmr.mgh.harvard.edu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why do those have to be lowercase?
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 used lowercase here to distinguish between information that I obtained from the original C++ code (in caps) and my added input (lowercase). It's just a matter of (my personal) convention. I'm trying to see if there is a way to get the breakdown of the different sensors from the raw file now. Currently only the overall number of sensors is being given.
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 to make it consistent with our constants system we should make it uppercase. If there is good reason not to do so let's add comments.
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.
@t3on Do you want to make a PR? Or do you want me to do change the case or add a comment?
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.
Or actually since this is not part of this PR maybe handle it after this one merges?
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.
@christianmbrodbeck I can handle this after the PR.
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.
@christianmbrodbeck @t3on open an issue please for stuff that can be handled after the PR