Skip to content

Commit ab311bf

Browse files
Copilotthewtex
authored andcommitted
ENH: Add Python wrapping for ObjectToObjectMultiMetricv4
Add wrapping for ObjectToObjectMultiMetricv4 with explicit TVirtualImage template parameter. Also add TVirtualImage to ImageToImageMetricv4 and its derived classes (MeanSquares, Mattes, Correlation, Demons, ANTS Neighborhood Correlation, Joint Histogram MI) so they can be used together correctly. Includes a Python test exercising instantiation, metric composition, and weight configuration. Co-authored-by: thewtex <25432+thewtex@users.noreply.github.com>
1 parent d53c803 commit ab311bf

10 files changed

Lines changed: 100 additions & 9 deletions
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
itk_wrap_class("itk::ANTSNeighborhoodCorrelationImageToImageMetricv4" POINTER)
2-
itk_wrap_image_filter("${WRAP_ITK_REAL}" 2 2+)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
6+
endforeach()
7+
endforeach()
38
itk_end_wrap_class()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
itk_wrap_class("itk::CorrelationImageToImageMetricv4" POINTER)
2-
itk_wrap_image_filter("${WRAP_ITK_REAL}" 2 2+)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
6+
endforeach()
7+
endforeach()
38
itk_end_wrap_class()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
itk_wrap_class("itk::DemonsImageToImageMetricv4" POINTER)
2-
itk_wrap_image_filter("${WRAP_ITK_REAL}" 2 2+)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
6+
endforeach()
7+
endforeach()
38
itk_end_wrap_class()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
itk_wrap_class("itk::ImageToImageMetricv4" POINTER_WITH_SUPERCLASS)
2-
foreach(d ${ITK_WRAP_DIMS})
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
33
foreach(t ${WRAP_ITK_REAL})
4-
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}"
5-
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
66
endforeach()
77
endforeach()
88
itk_end_wrap_class()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
itk_wrap_class("itk::JointHistogramMutualInformationImageToImageMetricv4" POINTER)
2-
itk_wrap_image_filter("${WRAP_ITK_REAL}" 2 2+)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
6+
endforeach()
7+
endforeach()
38
itk_end_wrap_class()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
itk_wrap_class("itk::MattesMutualInformationImageToImageMetricv4" POINTER_WITH_2_SUPERCLASSES)
2-
itk_wrap_image_filter("${WRAP_ITK_REAL}" 2 2+)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
6+
endforeach()
7+
endforeach()
38
itk_end_wrap_class()
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
itk_wrap_class("itk::MeanSquaresImageToImageMetricv4" POINTER_WITH_2_SUPERCLASSES)
2-
itk_wrap_image_filter("${WRAP_ITK_REAL}" 2 2+)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${ITKM_${t}}${d}${ITKM_${t}}${d}I${ITKM_${t}}${d}"
5+
"itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >, itk::Image< ${ITKT_${t}}, ${d} >")
6+
endforeach()
7+
endforeach()
38
itk_end_wrap_class()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
itk_wrap_class("itk::ObjectToObjectMultiMetricv4" POINTER)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${d}${d}I${ITKM_${t}}${d}" "${d},${d},itk::Image< ${ITKT_${t}}, ${d} >")
5+
endforeach()
6+
endforeach()
7+
itk_end_wrap_class()

Modules/Registration/Metricsv4/wrapping/test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ if(ITK_WRAP_PYTHON)
5959
EXPRESSION "instance = itk.MeanSquaresImageToImageMetricv4.New()"
6060
)
6161

62+
itk_python_add_test(
63+
NAME itkObjectToObjectMultiMetricv4PythonTest
64+
COMMAND
65+
${CMAKE_CURRENT_SOURCE_DIR}/itkObjectToObjectMultiMetricv4Test.py
66+
)
67+
6268
itk_python_expression_add_test(
6369
NAME itkPointSetToPointSetMetricv4PythonTest
6470
EXPRESSION "instance = itk.PointSetToPointSetMetricv4.New()"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# ==========================================================================
2+
#
3+
# Copyright NumFOCUS
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0.txt
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# ==========================================================================
18+
19+
import itk
20+
21+
# Test with float images
22+
Dimension = 2
23+
ImageType = itk.Image[itk.F, Dimension]
24+
25+
# Test basic instantiation
26+
multi_metric = itk.ObjectToObjectMultiMetricv4[Dimension, Dimension, ImageType].New()
27+
assert multi_metric is not None
28+
29+
# Create a simple metric to add - now with explicit TVirtualImage
30+
ms_metric = itk.MeanSquaresImageToImageMetricv4[ImageType, ImageType, ImageType].New()
31+
assert ms_metric is not None
32+
33+
# Add metric to the multi-metric
34+
multi_metric.AddMetric(ms_metric)
35+
36+
# Test that we can get the number of metrics
37+
assert multi_metric.GetNumberOfMetrics() == 1
38+
39+
# Set metric weights
40+
weights = itk.Array[itk.D](1)
41+
weights[0] = 0.5
42+
multi_metric.SetMetricWeights(weights)
43+
44+
# Verify weights were set
45+
retrieved_weights = multi_metric.GetMetricWeights()
46+
assert retrieved_weights.GetSize() == 1
47+
48+
print("Test passed!")

0 commit comments

Comments
 (0)