tierneytim / OPM

Tools for OPM processing using SPM
GNU General Public License v2.0
17 stars 7 forks source link

Headshape #2

Closed neurofractal closed 2 years ago

neurofractal commented 3 years ago

spm_opm_create should have an S.headshape input, in which headshape can be associated with fiducial info for better coregistration

georgeoneill commented 3 years ago

Hi @neurofractal

I've got an experimental version of this working, and it looks like should work. But as you'll see we'll actually have to think about how we want to make this a permenant addtion.

Below are the anatomy/sensor coregistrations using 4 scenarios.

  1. Subject anatomical - where canonical meshes are fitted with a non-linear warp.
  2. Template anatomical - 7 DOF affine transformation (rigid body + gobal rescale) based only on the 3 fiducials.
  3. Template + headshape - uses the headshape to do at 12 DOF affine transform (good if fiducials are not where one thinks they are) but then nixes the scaling after the fact. This is default behaviour for MEG data in SPM.
  4. Template + headshape (EEG hack) - uses the full 12DOF affine transform. Default for EEG data in SPM

image

As you can see from a eyeball of these. If we use the default behaviour of SPM and it turns out the fiducials are close to where they ideally should be, its no better than just a bog standard template. But hacking the code to use an EEG-like behaviour looks promising! I'm just going to quantify the errors to see how much better it might be.

neurofractal commented 3 years ago

Thanks George - looks really promising. A couple of thoughts:

georgeoneill commented 3 years ago

Yeah I think as you'll see from the plot below your obervation about point one is correct, but I think its because that the canonical mesh cuts off not inferior to the brain enough for it to really minimse the issues. We definitely need to get the anatomical fiducial locations yes,

The plot below is the difference in vertiex locations (Euclidian distance) between the non-linear warp to native space, and the other simplified fits, plotted in the same order as above.

Interestingly, even though from eyeballing fits 2 and 3 look similar above, it turns out using the headshape points gets the average error down a few millimeters. Using the EEG behvior (fit 4) looks like it should perform better, it does. BUT it does appear to get the variation in the error down. And becayse of the cutoff of the MRI in SPM its the infereior errors which have the largest error.

image

neurofractal commented 3 years ago

Interesting...

georgeoneill commented 3 years ago

Just some overlap plots, blue is the native, and red is the approximation, again in the order of the first post.

image

georgeoneill commented 3 years ago

Just doing the lead field error (assume Nolte model). Just incase for some reason it turns out the way it warps the brain/csf boundary for the different approximations is somehow more important than just source position error...

georgeoneill commented 3 years ago

Measuring the relative error between the leadfields from the native MRI fit and the ximplifications. (norm of the difference of lead fields, scaled by norm of the native lead field). Option three (template + headshape MEG style) gives the lowest error based on SPM's way of dipole modelling.

image

I think what this tells us is that the simple additional fitting based on the iPad generated headshape is the way to go.

This is somwhat of a relief as to get the EEG method of headshape fitting on MEG data requires some hacking of how we communcated to SPM that this is OPM data - something we currently do not do. To get the MEG method working just requires changes to spm_opm_create.

Thoughts?

neurofractal commented 3 years ago

Sounds good.. although I guess it's just the occipital cortex which is biasing the bottom right plot? I'll investigate which bits of the headshape to include/leave out...

Would you be able to share your code for calculating relative error between the leadfields? Then I can test my Thin Plate Spline (TPS) Warp approach...

georgeoneill commented 3 years ago

Yeah happy to share my code. Its a mess as I wrote it very quickly. But it should give you the ground work!

https://gist.github.com/georgeoneill/e5407bca5321a438404953274cd0958e

georgeoneill commented 2 years ago

I'm going to consider this basic headshape implementaiton issue closed.