ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Code.py
1 #!/usr/bin/env python3
2 
3 # =========================================================================
4 #
5 # Copyright NumFOCUS
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # https://www.apache.org/licenses/LICENSE-2.0.txt
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 # =========================================================================*/
20 
21 import itk
22 import argparse
23 
24 parser = argparse.ArgumentParser(description="Compute Mean Square Between Two Images.")
25 parser.add_argument("input_image_1")
26 parser.add_argument("input_image_2")
27 args = parser.parse_args()
28 
29 fixed_image = itk.imread(args.input_image_1, itk.F)
30 moving_image = itk.imread(args.input_image_2, itk.F)
31 
32 metric = itk.MeanSquaresImageToImageMetric[type(fixed_image), type(moving_image)].New()
33 transform = itk.TranslationTransform[itk.D, fixed_image.GetImageDimension()].New()
34 interpolator = itk.LinearInterpolateImageFunction[type(fixed_image), itk.D].New()
35 
36 metric.SetFixedImage(fixed_image)
37 metric.SetMovingImage(moving_image)
38 metric.SetFixedImageRegion(fixed_image.GetLargestPossibleRegion())
39 metric.SetTransform(transform)
40 metric.SetInterpolator(interpolator)
41 metric.Initialize()
42 
43 params = itk.OptimizerParameters[itk.D]()
44 params.SetSize(2)
45 
46 for x in range(-10, 15, 5):
47  params.SetElement(0, x)
48  for y in range(-10, 15, 5):
49  params.SetElement(1, y)
50  print(f"{list(params)}: {metric.GetValue(params):.1f}")
itk::OptimizerParameters
Class to hold and manage different parameter types used during optimization.
Definition: itkOptimizerParameters.h:36
itk::LinearInterpolateImageFunction
Linearly interpolate an image at specified positions.
Definition: itkLinearInterpolateImageFunction.h:51
itk::TranslationTransform
Translation transformation of a vector space (e.g. space coordinates)
Definition: itkTranslationTransform.h:43
itk::MeanSquaresImageToImageMetric
TODO.
Definition: itkMeanSquaresImageToImageMetric.h:41
New
static Pointer New()