# Problem by registration of an MRI Head image and an CT Head Image

**URL:** https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641
**Category:** Beginner Questions
**Tags:** python, simpleitk
**Created:** [December 5, 2021, 12:47pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641 "2021-12-05T12:47:11Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![sunshine123](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@sunshine123](https://discourse.itk.org/u/sunshine123)
#### Post date: [December 5, 2021, 12:47pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/1 "2021-12-05T12:47:11Z")

</div>

Hello,

I am new to image registration and I want to register an MRI Head Image with a CT image.

I began with the example from this Topic to understand how image registration is working in SITK:

> [@Multiresolution Registration with 2D Affine Transformation on pairs of 2D images](https://discourse.itk.org/t/multiresolution-registration-with-2d-affine-transformation-on-pairs-of-2d-images/3096/4):
>
> Hello @ScottP, Happy to help. Thanks for sharing an image that is more representative of what you are working with. Your task is harder than most if you want to use intensity based registration. It may be more appropriate to identify corresponding points in the two images and perform point based registration ([LandmarkBasedTransformInitializerFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1LandmarkBasedTransformInitializerFilter.html)). With intensity based registration the issue is that you have very high frequency content (what you refer to as blocky). That means that it is ea…

But when I applied the code on my MRI and CT images the result look like the input image.  
As an input(fixed image) I chose the MRI image and the moving image is the CT image. Both images have the same size(512x512).  
Here is my fixed image:

 ![Problem registration fixed](https://discourse.itk.org/uploads/default/original/2X/c/cae4a1275b69276fd66384059d70755e22302481.jpeg)

Here ist the moving image:

 ![Problem registration moving](https://discourse.itk.org/uploads/default/original/2X/e/e57f931f27f1d6eef6dc52e2ed0c806f0e9c5a94.jpeg)

And here is the result:

 ![Problem registration result](https://discourse.itk.org/uploads/default/original/2X/1/16a0f688c9d0710da0d0fdfc8ea8b42a9b8131a1.jpeg)

```auto

def multires_registration(fixed_image, moving_image, initial_transform):
        
    registration_method = sitk.ImageRegistrationMethod()
    registration_method.SetInterpolator(sitk.sitkBSpline)
    registration_method.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50)
    registration_method.SetMetricSamplingStrategy(registration_method.RANDOM)
    registration_method.SetMetricSamplingPercentage(0.01)
    registration_method.SetOptimizerAsGradientDescent(learningRate=0.5, numberOfIterations=100, convergenceMinimumValue=1e-6, convergenceWindowSize=10)
    registration_method.SetOptimizerScalesFromPhysicalShift() 
    registration_method.SetShrinkFactorsPerLevel(shrinkFactors = [2,1]) 
    registration_method.SetSmoothingSigmasPerLevel(smoothingSigmas = [1,0]) 
    registration_method.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()

    optimized_transform = sitk.AffineTransform(2)
    registration_method.SetMovingInitialTransform(initial_transform)   
    registration_method.SetInitialTransform(optimized_transform, inPlace=False)

    #registration_method.AddCommand(sitk.sitkStartEvent, registration_callbacks.metric_start_plot)
    #registration_method.AddCommand(sitk.sitkEndEvent, registration_callbacks.metric_end_plot)
    #registration_method.AddCommand(sitk.sitkMultiResolutionIterationEvent, registration_callbacks.metric_update_multires_iterations) 
    #registration_method.AddCommand(sitk.sitkIterationEvent, lambda: registration_callbacks.metric_plot_values(registration_method))

    optimized_transform = registration_method.Execute(fixed_image, moving_image)
        
    print('Final metric value: {0}'.format(registration_method.GetMetricValue()))
    print('Optimizer\'s stopping condition, {0}'.format(registration_method.GetOptimizerStopConditionDescription()))
    print('Optimized Transform from Multires:')
    print(optimized_transform)

    return (optimized_transform)
sitk.Show(resample_Atlas_Image2, 'fixed')
sitk.Show(phantom_image2, 'moving')
sitk.Show(sitk.Resample(phantom_image2, resample_Atlas_Image2, sitk.Transform()), 'identity transform')

# Centered 2D affine transform and show the resampled moving_image using this transform.
registration_transform = sitk.CenteredTransformInitializer(resample_Atlas_Image2, 
                                                      phantom_image2, 
                                                      sitk.AffineTransform(2), 
                                                      sitk.CenteredTransformInitializerFilter.GEOMETRY)
sitk.Show(sitk.Resample(phantom_image2, resample_Atlas_Image2, registration_transform), 'initial affine transform')

# Register using 2D affine initial transform that is overwritten
# and show the resampled moving_image using this transform.
multires_registration(resample_Atlas_Image2, phantom_image2, registration_transform)
sitk.Show(sitk.Resample(phantom_image2, resample_Atlas_Image2, registration_transform), 'final affine transform')

```

Could anybody help me with this?  
Thank you very much!

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [December 6, 2021, 2:36pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/2 "2021-12-06T14:36:45Z")

</div>

Hello @sunshine123,

Not sure what is the expectation that isn’t fulfilled. Does the registration converge? What was the optimizer’s stopping condition? Is the final transformation the identity and the expectation is that it be something else?

The input images are a bit strange. It looks like the moving image is not the original, but a resampling of the original. Also, the 2D slices don’t match in terms of the anatomical structures, they belong to different parts of the head so no matter what alignment is obtained it isn’t a correct one.

Steps to debug:

1. Read the [fundamental concepts](https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html) and [registration overview](https://simpleitk.readthedocs.io/en/master/registrationOverview.html).
2. Confirm that the inputs make sense.
3. Run a simpler registration, without the multi-resolution structure, and see that it converges to something reasonable.

---

<div class="post-metadata">

### Author: ![sunshine123](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@sunshine123](https://discourse.itk.org/u/sunshine123)
#### Post date: [December 6, 2021, 5:46pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/3 "2021-12-06T17:46:32Z")

</div>

Hello zivy,

My idea was that I want to register different CT datasets to one MRI reference image so that every CT image has the same orientation as the MRI image. (I want that the Nose of all CT-head images is always pointing up in anterior direction)  
My expectation was that the bone structures of the nose are pointing up in the anterior direction.

In general, my problem is that I have many different CT datasets where the head can be tilted and have a different orientation. Now I want to compare these datasets and for this, all CT images should have the same orientation.  
I had the idea to use an MRI Atlas of the brain and register the bones of the MRI atlas with the bones of the different CT datasets, so that every CT-dataset has the same orientation as the MRI atlas.  
DO you have any idea/tips on how I can register different CT datasets to one MRI reference dataset?

Thank you so much. I will read the docs and search for a solution.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [December 6, 2021, 6:36pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/4 "2021-12-06T18:36:43Z")

</div>

Hello @sunshine123,

If the CTs are in DICOM format and the Patient Position tag is correct, then just reading the image should allow you to orient it correctly. If the issue is the head being titled, then why not select one CT which is in the desired orientation and register all others to it? There doesn’t seem to be a need for MR here.

Also, the images should be dealt with using their native dimensionality, a single 3D volume and not a collection of 2D slices.

---

<div class="post-metadata">

### Author: ![sunshine123](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@sunshine123](https://discourse.itk.org/u/sunshine123)
#### Post date: [December 7, 2021, 4:19pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/5 "2021-12-07T16:19:51Z")

</div>

Hello zivy,

yes, the CTs are in DICOM. I already thought about using a CT image. But I would like to have an official Atlas Dataset as a Reference Image ([BIC - The McConnell Brain Imaging Centre: ICBM 152 N Lin 2009](http://www.bic.mni.mcgill.ca/ServicesAtlases/ICBM152NLin2009)). And I don’t found yet an Atlas Head CT dataset. So I had the idea of using an MRI Atlas. But I think a CT Atlas would be the better solution.

Do you have maybe an example of how I can use the DICOM tag Patient Position in the registration process or in which line I can use it?

Thank you so much for your help.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 7, 2021, 5:05pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/6 "2021-12-07T17:05:44Z")

</div>

Read the DICOM series as a 3D image, that will handle the Z position implicitly during registration.

---

<div class="post-metadata">

### Author: ![sunshine123](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@sunshine123](https://discourse.itk.org/u/sunshine123)
#### Post date: [December 8, 2021, 4:54pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/7 "2021-12-08T16:54:21Z")

</div>

ok thank you so much. But I need the DICOM header of the fixed and moving image right?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 8, 2021, 5:11pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/8 "2021-12-08T17:11:47Z")

</div>

Take a look at the [example](https://itk.org/ITKExamples/src/IO/GDCM/ReadDICOMSeriesAndWrite3DImage/Documentation.html). If you follow this pattern, the resulting fixed and moving images should have all the relevant metadata from the DICOM header.

---

<div class="post-metadata">

### Author: ![sunshine123](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@sunshine123](https://discourse.itk.org/u/sunshine123)
#### Post date: [December 8, 2021, 8:19pm UTC](https://discourse.itk.org/t/problem-by-registration-of-an-mri-head-image-and-an-ct-head-image/4641/9 "2021-12-08T20:19:37Z")

</div>

Perfect Thank you so much for your help and the example!! I will try now to solve my problems and get hopefully a proper registration result.
