# Incorrect lta affine from pre-alignment during MRI - CT coregistration

**URL:** https://mne.discourse.group/t/incorrect-lta-affine-from-pre-alignment-during-mri-ct-coregistration/6432
**Category:** Support & Discussions
**Created:** [February 28, 2023, 5:21pm UTC](https://mne.discourse.group/t/incorrect-lta-affine-from-pre-alignment-during-mri-ct-coregistration/6432 "2023-02-28T17:21:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)
#### Post date: [February 28, 2023, 5:21pm UTC](https://mne.discourse.group/t/incorrect-lta-affine-from-pre-alignment-during-mri-ct-coregistration/6432/1 "2023-02-28T17:21:39Z")

</div>

Hi,

I’m coregistering MRI and CT scans to localize intracranial contacts. Today I’ve hit the first instance of incorrect automatic MRI-CT coregistration:

 ![incorrect_MRI_CT_coreg](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/c/ce6f673a1deeac4014d63294f7ab2385d32090c2.jpeg)  
(the red ovals show where the incorrect alignment can be best seen)

Following the adivce in the great " Locating intracranial electrode contacts" tutorial I’ve corrected the issue by aligning the CT to MRI by hand in freeview. However later, when I read the lta saved in freeview to mne using the code provided in the tutorial:

```python
manual_reg_affine_vox = mne.read_lta(op.join(
    save_dir, 'sub-U06_ct_aligned_manual.nii.lta'))

# convert from vox->vox to ras->ras
manual_reg_affine = \
    CT_orig.affine @ np.linalg.inv(manual_reg_affine_vox) \
    @ np.linalg.inv(CT_orig.affine)

```

I see that applying the manual\_reg\_affine to CT does not give me the MRI-CT placement that I saw in freeview:

 ![obraz](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/4/4e120d5ad6028b354c386d3a2e41c3117fc40b36.jpeg)

But when I apply the lta in freeview I see that it is correct:

```bash
 freeview T1.mgz sub-U06_ct_Tilt_1.nii:colormap=heat:opacity=0.6:reg=sub-U06_ct_aligned_manual.nii.lta

```

I get the following text (might be related):

```python
QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '/home/mmagnuski/.xdg', please create it with 0700 permissions.
WARNING: hdr.dim[4] = 0 (nframes), setting to 1
WARNING: hdr.dim[4] = 0 (nframes), setting to 1
INFO: LTA input is not RAS to RAS...converting...

```

and I see the correct alignment (the one I performed by hand):

 ![obraz](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/e/e73d49482ad794582fb63f3ac641be52523508eb.jpeg)

I’d be thankful for any ideas on what the issue could be.

I can share the CT, MRI and lta matrix that I am using.

### Additional info

- MNE version: 1.3.0
- operating system: Windows 10
- I am using freesurfer 7.2.0 on WSL 2 (with Xming for freeview)
- after aligning the scan to ACPC and running recon-all freesurfer errored due to FOV \> 256, so I used `-cw256` flag and then recon-all completed without problems. However, after reading the mri from freesurfer subject/mri directory in python I saw that the scan was no longer in ACPC. It might be due to cropping that freesurfer does when `-cw256` is provided, but I’m not sure it is relevant here.

---

<div class="post-metadata">

### Author: ![mmagnuski](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mmagnuski/32/153_2.png) [@mmagnuski](https://mne.discourse.group/u/mmagnuski)
#### Post date: [March 11, 2023, 12:27pm UTC](https://mne.discourse.group/t/incorrect-lta-affine-from-pre-alignment-during-mri-ct-coregistration/6432/2 "2023-03-11T12:27:12Z")

</div>

The issue has been resolved - it turns out that in the development version of mne the function reading freesurfers affine matrices (`mne.read_lta`) has been fixed.  
([prealigning CT and MRI: incorrect transformation read from freesurfer .lta file · Issue #11527 · mne-tools/mne-python · GitHub](https://github.com/mne-tools/mne-python/issues/11527))
