You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: improving high resolution CT iEEG electrode localization example #11610
@alexrockhill
I have some questions and ideas for the high-res CT iEEG localization example.
First of all, since we already have head-MR and CT-MRI transforms (see the main iEEG localization example), can we create head-CT transform out of these instead of finding CT fiducials in freeview (as suggested in the hi-res CT example)? I tried to create head-CT transform by first inverting the CT-MRI affine to get MRI-CT transformation and then computing the dot product between head-MRI and MRI-CT:
# subj_trans is the head->MRI tranform obtained as in the main iEEG example (transforming fsaverage fiducials to individual MRI)# reg_affine is the CT->MRI transformmri_ct_trans=np.linalg.inv(reg_affine)
head_ct=subj_trans['trans'] @ mri_ct_trans# (I then turn the head_ct matrix to a Transform instance)
but for some reason, after marking a few contacts in GUI and using the mne.transforms.apply_volume_registration_points as in the high-res CT example, all channel positions are NaNed-out in the info. This happens irrespective of channels selection (selecting only the channels in the info that were marked in the GUI) or replacing any NaNs with zeros in info['chs'][idx]['loc']).
BTW - I discovered that mne.transforms.apply_volume_registration_points modifies info in-place. I don't think it should do that.
One thing that would be great to clarify in the example would be the choice between using an adequate head-CT and an identity matrix. It is mentioned that one could fake the head-CT transform as identity matrix but the drawbacks are not dicsussed. I wasn't sure if not having the channel positions in head space would not cause problems at some point later so I didn't use the identity matrix. On the other hand creating the head-CT transform based on fiducials identified by hand sounds error-prone.
I'll post other issues/ideas in a separate post here today.
PS. I am waiting for a green light to share the CT with micro-channels, but it should be possible. Both MRI and CT would be de-faced, but I could share a CT-MRI transformation along with these files.
We can definitely change the modifying the info in place, that's a quick PR and a good point.
That would be really helpful to have a shareable dataset, let me know.
There's not really any drawbacks to faking the head->CT transform, it's just a formality really.
The code looks pretty reasonable for the head->CT transform, it's a bit complicated though because the CT->MR is scanner RAS to scanner RAS. The end of the new tutorial wrangles all these transforms and we could wrap that but I think that is the only way to get the head->CT transform that you're asking for, unless I'm wrong and there's something more efficient. Can you put those things in a minimal example so that I can see what you're talking about a bit easier?
Hi @alexrockhill, sorry for the delay, I was on vacation. Unfortunatelly I also get all NaNs from apply_volume_registration_points when using identity transform. I'll try to create a reproducible example today. Could I share the data with you privately?
Ok, I debugged it and found what the problem was. It was actually in compute_native_head_t towards the end of apply_volume_registration_points. compute_native_head_t seems to assume that non-defined fiducials would be None (as returned by mne.io._digitization._get_fid_coords), while in my case they were NaN (seems to be the default now for "no position"). I didn't use CT scan fiducials, because I used identity matrix head->CT transform (this is easier than annotating fiducials for CT scans).
I've changed the compute_native_head_t to accept NaN as "no position" for fiducials and now it works fine.
I'll send a PR today.
Activity
alexrockhill commentedon Mar 29, 2023
We can definitely change the modifying the info in place, that's a quick PR and a good point.
That would be really helpful to have a shareable dataset, let me know.
There's not really any drawbacks to faking the head->CT transform, it's just a formality really.
The code looks pretty reasonable for the head->CT transform, it's a bit complicated though because the CT->MR is scanner RAS to scanner RAS. The end of the new tutorial wrangles all these transforms and we could wrap that but I think that is the only way to get the head->CT transform that you're asking for, unless I'm wrong and there's something more efficient. Can you put those things in a minimal example so that I can see what you're talking about a bit easier?
mmagnuski commentedon Apr 17, 2023
Hi @alexrockhill, sorry for the delay, I was on vacation. Unfortunatelly I also get all NaNs from
apply_volume_registration_pointswhen using identity transform. I'll try to create a reproducible example today. Could I share the data with you privately?mmagnuski commentedon Apr 17, 2023
Ok, I debugged it and found what the problem was. It was actually in
compute_native_head_ttowards the end ofapply_volume_registration_points.compute_native_head_tseems to assume that non-defined fiducials would be None (as returned bymne.io._digitization._get_fid_coords), while in my case they were NaN (seems to be the default now for "no position"). I didn't use CT scan fiducials, because I used identity matrix head->CT transform (this is easier than annotating fiducials for CT scans).I've changed the
compute_native_head_tto accept NaN as "no position" for fiducials and now it works fine.I'll send a PR today.