# Multi-resolution registration

**URL:** https://discourse.itk.org/t/multi-resolution-registration/6300
**Category:** Beginner Questions
**Tags:** registration, python, simpleitk
**Created:** [November 15, 2023, 3:59am UTC](https://discourse.itk.org/t/multi-resolution-registration/6300 "2023-11-15T03:59:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![maxtj](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@maxtj](https://discourse.itk.org/u/maxtj)
#### Post date: [November 15, 2023, 3:59am UTC](https://discourse.itk.org/t/multi-resolution-registration/6300/1 "2023-11-15T03:59:39Z")

</div>

I am very new to python and the use of SimpleITK. I have tried to construct python code to register 2 image modalities that have different spatial resolutions. I could not perform registration between 2 images if one of the image has a higher resolution, but I could perform the registration only when I downgraded the higher resolution image to be at very similar resolution). (I used the exact same code for both cases). Here I also showed some of my code that I tried to construct.

def registration(fixed\_image, moving\_image, parameter\_map):

```
FixedImage = sitk.GetImageFromArray(fixed_image)
MovingImage = sitk.GetImageFromArray(moving_image)

ParameterMap = sitk.GetDefaultParameterMap(parameter_map)

elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(FixedImage)
elastixImageFilter.SetMovingImage(MovingImage)
elastixImageFilter.SetParameterMap(ParameterMap)
elastixImageFilter.Execute()

ResultImage = elastixImageFilter.GetResultImage()
TransParameterMap = elastixImageFilter.GetTransformParameterMap()

ResultArray = sitk.GetArrayFromImage(ResultImage)
FixedArray = sitk.GetArrayFromImage(FixedImage)
MovingArray = sitk.GetArrayFromImage(MovingImage)

return ResultArray, FixedArray, MovingArray, TransParameterMap

```

def registration\_plot(ResultArray, FixedArray, MovingArray):

```
ResultArrayNorm = ResultArray/np.amax(ResultArray)
FixedArrayNorm = FixedArray/np.amax(FixedArray)
MovingArrayNorm = MovingArray/np.amax(MovingArray)

plt.figure(figsize=(18,8))
ax = plt.subplot(1, 5, 1)
plt.imshow(FixedArray, cmap='Blues')
plt.axis('off')
plt.title('Fixed Image')
ax = plt.subplot(1, 5, 2)
plt.imshow(MovingArray, cmap='Reds')
plt.axis('off')
plt.title('Moving Image')
ax = plt.subplot(1, 5, 3)
plt.imshow(ResultArray, cmap='Reds')
plt.axis('off')
plt.title('Result Image')
ax = plt.subplot(1, 5, 4)
plt.imshow(FixedArrayNorm, cmap='Blues', alpha=0.8)
plt.axis('off')
plt.imshow(MovingArrayNorm, cmap='Reds', alpha=0.4)
plt.axis('off')
plt.title('Before optimization')
ax = plt.subplot(1, 5, 5)
plt.imshow(FixedArrayNorm, cmap='Blues', alpha=0.8)
plt.axis('off')
plt.imshow(ResultArrayNorm, cmap='Reds', alpha=0.4)
plt.axis('off')
plt.title ('After optimization')
plt.show()

```

Before performing the registration, I had to resize (downgrade) the resolution of the image first, even though I could not run the code, and it said some error as shown below.

RuntimeError: Exception thrown in SimpleITK ElastixImageFilter\_Execute: C:\dafne\SimpleElastix\Code\Elastix\src\sitkElastixImageFilterImpl.cxx:259:  
sitk::ERROR:  
itk::ExceptionObject (000000F2E75E78B0)  
Location: “unknown”  
File: c:\dafne\simpleelastix\build3.9\elastix\core\main\elxElastixFilter.hxx  
Line: 253  
Description: itk::ERROR: ElastixFilter(00000240605747B0): Internal elastix error: See elastix log (use LogToConsoleOn() or LogToFileOn()).

Please anyone help me to figure this out how I can perform multiresolution registration.  
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: [November 15, 2023, 2:11pm UTC](https://discourse.itk.org/t/multi-resolution-registration/6300/2 "2023-11-15T14:11:44Z")

</div>

Hello @maxtj,

The reason you are struggling to register images with different spacing is that the code above does not contain that information as part of the input to the `registration` function. The function is receiving numpy arrays and not SimpleITK images. The `fixed_image` and `moving_image` should be SimpleITK images which were read from disk. You pass these to the `elastixImageFilter`.

Please familiarize yourself with the [fundamental concepts](https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html) of ITK/SimpleITK before continuing with your work. Possibly read the [registration overview](https://simpleitk.readthedocs.io/en/master/registrationOverview.html), though you are using the SimpleElastix registration and not the ITK/SimpleITK registration framework. The basic concepts are similar, so if you understand the basic ITK/SimpleITK framework it will be easier for you to understand the SimpleElastix framework.
