- MNE version: 1.8.0
- operating system: Debian GNU/Linux 9.8 (stretch)
Dear MNE community,
I’m writing you about some difficulty I am experiencing on aligning properly the volume source space (created using MNE) and the T1 image used to create the source space.
src = mne.setup_volume_source_space(subject, bem=bem_sol, pos=5)
fwd = mne.make_forward_solution(
raw.info, src=src, bem=bem_sol, trans=trans_sol, meg=True, eeg=False
)
mri_img = nib.load(f"{subjects_dir}/{subject}/mri/T1.mgz")
src_pts = fwd['src'][0]['rr'] * 1e3
trans_coords = mne.transforms.apply_trans(trans, src_pts)
voxel_coords = nib.affines.apply_affine(
np.linalg.inv(mri_img.affine),
trans_coords
)
current_ornt = io_orientation(mri_img.affine)
ras_ornt = axcodes2ornt(('R', 'A', 'S'))
transform = ornt_transform(current_ornt, ras_ornt)
img_ras = nib.as_closest_canonical(mri_img)
mri_ras_data = img_ras.get_fdata()
subset = voxel_coords[(voxel_coords[:, 0] > 110) & (voxel_coords[:, 0] < 120)].copy().round()
x = subset[:, 1]
y = subset[:, 2]
mri_slice = mri_ras_data[118, :, :]
fig, ax = plt.subplots(figsize=(6, 6))
ax.imshow(mri_slice)
ax.scatter(x, y)
With this code I’m able to plot both, the src positions and mri slice at the same place but they don’t align perfectly. I’d say there is like a 15-20% missalignement whereas when I use
mne.viz.plot_bem(src=src, subjects_dir=subjects_dir, subject=subject, brain_surfaces='white', orientation='coronal')
The aligment is absolutely perfect but I can’t seem to reproduce the same transformations to get to the same result.
Thank you,