Compute a MSE metric for a fixed and moving image (manual registration)

Hi,

I’m new to ITK and image registration in general. And I’m facing a problem I barely know how to solve.

Before applying 2D/2D image registration on two images, I want to know if my registration is more likely to converge to the solution. The idea here is to plot a 3d map of the metrics when modifying two parameters (in my case the (x0,y0) origin of the moving image).

I want to build a double four-loop for (x0,y0) and compute the MSE between the superposition area of the two images, I suppose my fixed image origin is (0,0). Is there an easy way to do that with elastix?

I know the spacing of my two images.

This way I could estimate if the good solution of the desired registration is a global minimum and not some local minimum.

I apologize for my broken english, it’s not my native language.

Best Regards

I don’t know whether that is easy using elastix, but it should not be hard using ITK directly. In your double for loop update the origin of the moving image, then manually evaluate the metric. See some related discussions, such as this and this.

I use found my way using Itk library on python, though, I have a problem with the setting of the fixed image mask.

fixed_image = itk.imread(optical)
moving_image = itk.imread(mri)
fixed_mask = itk.imread(optical_mask)

metric = itk.MeanSquaresImageToImageMetric[type(fixed_image), type(moving_image)].New()
transform = itk.TranslationTransform[itk.D, fixed_image.GetImageDimension()].New()
interpolator = itk.LinearInterpolateImageFunction[type(fixed_image), itk.D].New()

metric.SetFixedImage(fixed_image)
metric.SetFixedImageMask(fixed_mask)
metric.SetMovingImage(moving_image)
metric.SetFixedImageRegion(fixed_image.GetLargestPossibleRegion())
metric.SetTransform(transform)
metric.SetInterpolator(interpolator)
metric.Initialize()

params = itk.OptimizerParametersitk.D
params.SetSize(2)

When I run the code, it returns me the following answer :

TypeError: in method ‘itkImageToImageMetricIF2IF2_SetFixedImageMask’, argument 2 of type ‘itkSpatialObject2 *’
Additional information:
Wrong number or type of arguments for overloaded function ‘itkImageToImageMetricIF2IF2_SetFixedImageMask’.
Possible C/C++ prototypes are:
itkImageToImageMetricIF2IF2::SetFixedImageMask(itkSpatialObject2 *)
itkImageToImageMetricIF2IF2::SetFixedImageMask(itkSpatialObject2 const *)

Knowing that my mask type is

<itk.itkImagePython.itkImageF2; proxy of <Swig Object of type ‘itkImageF2 *’ at 0x7f073d400db0> >

Is there a way with itk python library to convert the type of the mask? I’m totally beginner with C++.

You probably need to involve ImageMaskSpatialObject. Set image to it, and it to metric.