|
| 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 | +# http://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 sys |
| 22 | + |
| 23 | +import itk |
| 24 | + |
| 25 | +if len(sys.argv) < 3: |
| 26 | + raise Exception(f"Usage: {sys.argv[0]} imageFile1 imageFile2") |
| 27 | + |
| 28 | +fixed_image = itk.imread(sys.argv[1], itk.F) |
| 29 | +moving_image = itk.imread(sys.argv[2], itk.F) |
| 30 | + |
| 31 | +metric = itk.MeanSquaresImageToImageMetric[type(fixed_image), type(moving_image)].New() |
| 32 | +transform = itk.TranslationTransform[itk.D, fixed_image.GetImageDimension()].New() |
| 33 | +interpolator = itk.LinearInterpolateImageFunction[type(fixed_image), itk.D].New() |
| 34 | + |
| 35 | +metric.SetFixedImage(fixed_image) |
| 36 | +metric.SetMovingImage(moving_image) |
| 37 | +metric.SetFixedImageRegion(fixed_image.GetLargestPossibleRegion()) |
| 38 | +metric.SetTransform(transform) |
| 39 | +metric.SetInterpolator(interpolator) |
| 40 | +metric.Initialize() |
| 41 | + |
| 42 | +params = itk.OptimizerParameters[itk.D]() |
| 43 | +params.SetSize(2) |
| 44 | + |
| 45 | +for x in range(-10, 15, 5): |
| 46 | + params.SetElement(0, x) |
| 47 | + for y in range(-10, 15, 5): |
| 48 | + params.SetElement(1, y) |
| 49 | + print(f"{list(params)}: {metric.GetValue(params):.1f}") |
0 commit comments