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