# Compute Mean Squares Metric Between Two Images¶

## Synopsis¶

Compute the mean squares metric between two images.

## Results¶

Input image 1.

Input image 2.

Data from 2 images passed through Output:

```[-10, -10]: 23101.7
[-10, -5]: 23205.7
[-10, 0]: 23260.4
[-10, 5]: 23064.5
[-10, 10]: 22914.5
[-5, -10]: 23271.1
[-5, -5]: 23351.3
[-5, 0]: 23401
[-5, 5]: 23185.1
[-5, 10]: 23026.5
[0, -10]: 23486.5
[0, -5]: 23538.2
[0, 0]: 23566.2
[0, 5]: 23352.1
[0, 10]: 23175.2
[5, -10]: 23590.7
[5, -5]: 23625.7
[5, 0]: 23633.4
[5, 5]: 23401.1
[5, 10]: 23196.7
[10, -10]: 23723.5
[10, -5]: 23762.9
[10, 0]: 23767.1
[10, 5]: 23504.9
[10, 10]: 23298.3
```

## Code¶

### C++¶

```#include "itkImage.h"
#include "itkMeanSquaresImageToImageMetric.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkTranslationTransform.h"

int
main(int argc, char * argv[])
{
using ImageType = itk::Image<double, 2>;

if (argc < 3)
{
std::cout << "Usage: " << argv[0] << " imageFile1 imageFile2" << std::endl;
return EXIT_FAILURE;
}

ImageType::Pointer fixedImage = fixedReader->GetOutput();
ImageType::Pointer movingImage = movingReader->GetOutput();

using MetricType = itk::MeanSquaresImageToImageMetric<ImageType, ImageType>;
using InterpolatorType = itk::LinearInterpolateImageFunction<ImageType, double>;
using TransformType = itk::TranslationTransform<double, 2>;

MetricType::Pointer    metric = MetricType::New();
TransformType::Pointer transform = TransformType::New();

InterpolatorType::Pointer interpolator = InterpolatorType::New();
interpolator->SetInputImage(fixedImage);

metric->SetFixedImage(fixedImage);
metric->SetMovingImage(movingImage);
metric->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());
metric->SetTransform(transform);
metric->SetInterpolator(interpolator);

TransformType::ParametersType params(transform->GetNumberOfParameters());
params.Fill(0.0);

metric->Initialize();
for (double x = -10.0; x <= 10.0; x += 5.0)
{
params(0) = x;
for (double y = -10.0; y <= 10.0; y += 5.0)
{
params(1) = y;
std::cout << params << ": " << metric->GetValue(params) << std::endl;
}
}

return EXIT_SUCCESS;
}
```

## Classes demonstrated¶

template<typename `TFixedImage`, typename `TMovingImage`>
class `MeanSquaresImageToImageMetric` : public itk::ImageToImageMetric<TFixedImage, TMovingImage>

TODO.

ITK Sphinx Examples:

See itk::MeanSquaresImageToImageMetric for additional documentation.