# any quantified methods to evaluate the CT - MRI alignment?

**URL:** <https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218>\
**Category:** Support & Discussions\
**Tags:** ieeg-and-ecog\
**Created:** [January 4, 2022, 9:43am UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218 "2022-01-04T09:43:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BarryLiu97](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/barryliu97/32/33_2.png) [@BarryLiu97](https://mne.discourse.group/u/BarryLiu97)\
**Post date:** [January 4, 2022, 9:43am UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/1 "2022-01-04T09:43:58Z")

</div>

Hi, I was using `mne.transforms.compute_volume_registration` and `mne.transforms.apply_volume_registration` to align CT and MRI.  
I wonder if there is another quantified method that could help evaluate the quality of this alignment besides R2?  
And also, the alignment result is always not good, any solution?

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [January 4, 2022, 4:43pm UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/2 "2022-01-04T16:43:02Z")

</div>

Yes, this is an ongoing issue: [[BUG] MRI-CT alignment failure · Issue #2490 · dipy/dipy · GitHub](https://github.com/dipy/dipy/issues/2490), it appears that the CT with an MR is an alignment with many local minima to get stuck in.

You can try the ANTSpy version that is on the linked issue (above), that is the most reliable one I’ve found _but only on Ubuntu_, it works on MacOSX but just as poorly as Dipy on those hard cases with alignment failures.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![BarryLiu97](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/barryliu97/32/33_2.png) [@BarryLiu97](https://mne.discourse.group/u/BarryLiu97)\
**Post date:** [January 4, 2022, 4:52pm UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/3 "2022-01-04T16:52:16Z")

</div>

Thank you for your help!  
I found that in the issue you used

```python
from dipy.align.imaffine import MutualInformationMetric

```

to compare the mutual info between bad\_align\_ct and good\_align\_ct, so can I suppose mutual info is a nice method to help us quantify the quality of the CT-MRI alignment?

---

<div class="post-metadata">

**Author:** ![BarryLiu97](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/barryliu97/32/33_2.png) [@BarryLiu97](https://mne.discourse.group/u/BarryLiu97)\
**Post date:** [January 4, 2022, 4:57pm UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/4 "2022-01-04T16:57:42Z")

</div>

I’ve tried ANTSpy, but still, 5/46 had a bad result. However, antspy is much faster for it’s using multi-threads. And I found If I used affine method to do alignment, the result is not good. Like this  
 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/f/f5b68ad46b0e1fecbcdc7c2e58956fb61a60a7f0.png)  
This is the result from ANTSPY with ‘Affine’ transform. Here is a sample code

```python
transform = 'Affine'
            mytx = ants.registration(fixed=t1, moving=ct, type_of_transform=transform)
            warped_ct = ants.apply_transforms(fixed=t1, moving=ct,
                                              transformlist=mytx['fwdtransforms'], interpolator='linear')
            warped_ct.set_direction(t1.direction)
            warped_ct.set_origin(t1.origin)
            warped_ct.set_spacing(t1.spacing)
            ants.image_write(warped_ct, os.path.join(root, subject, 'CT_aligned_ants_' + transform.lower() + '.nii'))

```

Does this mean normally Rigid is enough?

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [January 11, 2022, 5:39pm UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/6 "2022-01-11T17:39:53Z")

</div>

You really don’t want to use `Affine` because that stretches and shears the image. If the subjects are the same (i.e. the MR and CT are from the same subject) that shouldn’t be necessary and should actually be detrimental because it will change the size and location of the electrode contacts. Hope that makes sense.

---

<div class="post-metadata">

**Author:** ![BarryLiu97](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/barryliu97/32/33_2.png) [@BarryLiu97](https://mne.discourse.group/u/BarryLiu97)\
**Post date:** [January 12, 2022, 10:59am UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/7 "2022-01-12T10:59:47Z")

</div>

That does make sense! Thank you so much. After doing about 10 patients’ affine registration, none of the results is good.

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [February 9, 2022, 1:47am UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/8 "2022-02-09T01:47:51Z")

</div>

Hey @BarryLiu97, you might be interested in the latest PR that just merged [https://github.com/mne-tools/mne-python/pull/10298](https://github.com/mne-tools/mne-python/pull/10298), it explains how to do manual alignment on the ones that fail and only takes ~2 minutes per patient of user interaction in my experience

---

<div class="post-metadata">

**Author:** ![BarryLiu97](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/barryliu97/32/33_2.png) [@BarryLiu97](https://mne.discourse.group/u/BarryLiu97)\
**Post date:** [February 9, 2022, 3:34pm UTC](https://mne.discourse.group/t/any-quantified-methods-to-evaluate-the-ct-mri-alignment/4218/9 "2022-02-09T15:34:36Z")

</div>

Wow, that really helps！
