# 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.

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.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 *’