Skip to content

MRG: Add talairach.xfm and MRI scaling to coreg - #5132

Merged
agramfort merged 5 commits into
mne-tools:masterfrom
larsoner:talxfm
Apr 27, 2018
Merged

agramfort merged 5 commits into
mne-tools:masterfrom
larsoner:talxfm

Conversation

@larsoner

@larsoner larsoner commented Apr 13, 2018 •

Copy link
Copy Markdown
Member

This should work once nipy/nibabel#619 is sorted out.

@christianbrodbeck does this look good to you assuming I can work out the nibabel bug and thus get tests to pass?

@larsoner larsoner mentioned this pull request Apr 13, 2018
26 of 29 tasks
@larsoner larsoner changed the title WIP: Add talairach.xfm and MRI scaling to coreg MRG: Add talairach.xfm and MRI scaling to coreg Apr 13, 2018
@codecov

codecov Bot commented Apr 13, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5132 into master will increase coverage by 0.04%.
The diff coverage is 97.18%.

@@            Coverage Diff             @@
##           master    #5132      +/-   ##
==========================================
+ Coverage   88.14%   88.19%   +0.04%     
==========================================
  Files         356      358       +2     
  Lines       65774    65974     +200     
  Branches    11193    11214      +21     
==========================================
+ Hits        57978    58184     +206     
+ Misses       4959     4957       -2     
+ Partials     2837     2833       -4

@larsoner

Copy link
Copy Markdown
Member Author

Okay transform issue fixed. Ready for review/merge from my end.

@larsoner

Copy link
Copy Markdown
Member Author

... and I did a tiny bit of plotting in freeview and the scaled MRIs seemed to plot properly. It would be good if someone could cross-check to make sure.

@larsoner

Copy link
Copy Markdown
Member Author

@christianbrodbeck WDYT?

@christianbrodbeck

Copy link
Copy Markdown
Member

Conceptually it makes sense, for reviewing it will take me a little longer to get to it (sorry)...

@larsoner larsoner added this to the 0.16 milestone Apr 23, 2018
@larsoner

Copy link
Copy Markdown
Member Author

@cjayb any experience working with MRIs? If so do you want to take a look?

@christianbrodbeck any time to look this week? We're trying to push out a release and it would be good to have this if possible.

Comment thread mne/tests/test_coreg.py
# test exceeding tolerance
tgt_pts[0, :] += 20
assert_raises(RuntimeError, fit_matched_points, tgt_pts, src_pts, tol=10)
pytest.raises(RuntimeError, fit_matched_points, tgt_pts, src_pts, tol=10)

@massich massich Apr 24, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts about the pytest natural syntax using context manager?

with pytest.raises(RuntimeError):
	fit_matched_points(tgt_pts, src_pts, tol=10)

I prefer it since the call is more clear.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do it for all new code but for older stuff I just swap this in as it's faster (you can do a search/replace very easily, and there are a lot of them).

@massich

massich commented Apr 26, 2018

Copy link
Copy Markdown
Contributor

LGTM

@cjayb

cjayb commented Apr 26, 2018

Copy link
Copy Markdown
Contributor

@cjayb any experience working with MRIs? If so do you want to take a look?

sorry @larsoner , my limited experience isn't going to help here

@christianbrodbeck

Copy link
Copy Markdown
Member

Looking into it now.

@christianbrodbeck christianbrodbeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but I don't know enough about the MRI file formats to help with the scaled MRI and xfm. I tried plotting with plot_bem and got the image below, would you expect that mismatch?

mne.viz.plot_bem('sample-fsa-small', '.', src='sample-fsa-small-ico-5-src.fif', brain_surfaces='white')

screen shot 2018-04-26 at 11 54 56 am

Comment thread mne/coreg.py
path = transform_fname.format(subjects_dir=subjects_dir, subject=subject)
if os.path.exists(path):
paths['transforms'].append(transform_fname)
del transform_fname, path

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this del statement left over from debugging?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's more for code safety to ensure if path is used later it's using the correct one

Comment thread mne/coreg.py Outdated
_write_fs_xfm(fname_to, T_ras_mni['trans'], kind)


def _get_sf(subject_to, subject_from, scale, subjects_dir):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of duplicates the _scale_params function further up, maybe the two could be unified?

@larsoner

Copy link
Copy Markdown
Member Author

That plot looks incorrect. Can you see if freeview shows it correctly? It would tell us if there is a bug in plot_bem or in this code

@christianbrodbeck

christianbrodbeck commented Apr 26, 2018 via email

Copy link
Copy Markdown
Member

@christianbrodbeck

Copy link
Copy Markdown
Member

Okay yeah, adding the T1 under Volumes and smoothwm under Surfaces looks like it has the same mismatch.

@larsoner

Copy link
Copy Markdown
Member Author

Here is an example for sample:

freeview -v mri/T1.mgz -f bem/inner_skull.surf:edgecolor=red -f bem/outer_skull.surf:edgecolor=orange -f bem/outer_skin.surf:edgecolor=yellow --layout 4

screenshot from 2018-04-26 12-09-24

You'll need to make sure the .surf files are in your subject before morphing, though. Otherwise there will be extra work involved to extract them from the scaled -bem.fif output to .surf format (in mm IIRC).

@larsoner

Copy link
Copy Markdown
Member Author

Argh yes I think you're right, it doesn't quite look right here after scaling with 80/100/120%:

freeview -v mri/T1.mgz -f bem/inner_skull.surf:edgecolor=red -f bem/outer_skull.surf:edgecolor=orange -f bem/our_skin.surf:edgecolor=yellow -f surf/lh.pial:edgecolor=white -f surf/rh.pial:edgecolor=white --layout 4

screenshot from 2018-04-26 12-18-41

@christianbrodbeck

Copy link
Copy Markdown
Member

I don't have the .surf files for fsaverage, used freeview -v mri/T1.mgz -f surf/lh.white:edgecolor=red instead and got the image below, that should have the same effect right?

screen shot 2018-04-26 at 12 23 13 pm

@larsoner

Copy link
Copy Markdown
Member Author

Okay there was an ordering problem that should now be fixed. This is what I see using 90/110/120 as my sample scale factors:

$ freeview -v mri/T1.mgz -f bem/inner_skull.surf:edgecolor=red -f bem/outer_skull.surf:edgecolor=orange -f bem/our_skin.surf:edgecolor=yellow --layout 4

screenshot from 2018-04-26 13-42-22

And then deforming fsaverage with the same scale factors and doing:

import mne
surf = mne.read_bem_surfaces(subjects_dir + '/sample_deformed/bem/sample_deformed-inner_skull-bem.fif')[0]
mne.write_surface(subjects_dir + '/sample_deformed/bem/inner_skull.surf',
                  surf['rr'] * 1000, surf['tris'])
mne.viz.plot_bem('sample_deformed', brain_surfaces='pial',
                 subjects_dir=subjects_dir)

I get:

figure_1

@christianbrodbeck can you see if things are fixed now for you, too?

@christianbrodbeck

Copy link
Copy Markdown
Member

Yes it looks good now. Not sure how to do an equivalent test for the XFM file. Also, it looks like viz.plot_bem distorts image proportions?

screen shot 2018-04-26 at 9 26 21 pm
figure_1

@larsoner

Copy link
Copy Markdown
Member Author

Also, it looks like viz.plot_bem distorts image proportions?

It probably assumes that the zooms for each dimension are identical. This is a bug we should probably fix separately.

@agramfort
agramfort merged commit 74ac2f3 into mne-tools:master Apr 27, 2018
@agramfort

Copy link
Copy Markdown
Member

Thx !

@larsoner
larsoner deleted the talxfm branch April 27, 2018 21:03
britta-wstnr pushed a commit to britta-wstnr/mne-python that referenced this pull request Jul 5, 2018
* ENH: Add talairach.xfm and MRI scaling to coreg

* FIX: Fix transform

* FIX: Bump version

* STY: Cleaner

* FIX: Fix scale order and unify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants