Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

ObjectToObjectMultiMetricv4 was not wrapped for Python, limiting multi-metric registration to third-party libraries like ANTsPy. Additionally, ImageToImageMetricv4 classes were wrapped without explicit TVirtualImage parameter specification.

Description

This PR adds Python wrapping for the ObjectToObjectMultiMetricv4 class and updates all ImageToImageMetricv4 derived classes to include explicit TVirtualImage parameter specification, enabling multi-metric registration workflows directly in ITK Python with consistent template parameter usage.

Changes

  • Added itkObjectToObjectMultiMetricv4.wrap in Modules/Registration/Metricsv4/wrapping/
  • Updated all ImageToImageMetricv4 derived classes to include explicit TVirtualImage parameter:
    • itkImageToImageMetricv4.wrap
    • itkMeanSquaresImageToImageMetricv4.wrap
    • itkCorrelationImageToImageMetricv4.wrap
    • itkDemonsImageToImageMetricv4.wrap
    • itkANTSNeighborhoodCorrelationImageToImageMetricv4.wrap
    • itkJointHistogramMutualInformationImageToImageMetricv4.wrap
    • itkMattesMutualInformationImageToImageMetricv4.wrap
  • Wraps dimensions 2 and 3 with both float and double types
  • Explicitly specifies TVirtualImage parameter based on wrapped image types (itk::Image<float/double, dimension>)
  • Added Python test itkObjectToObjectMultiMetricv4Test.py demonstrating usage:
    • Creating multi-metric instances with explicit TVirtualImage
    • Adding component metrics with explicit TVirtualImage specification
    • Setting and retrieving metric weights
    • Verifying the number of metrics

Usage Example

import itk

# Create multi-metric for combined registration
Dimension = 2
ImageType = itk.Image[itk.F, Dimension]

multi_metric = itk.ObjectToObjectMultiMetricv4[Dimension, Dimension, ImageType].New()

# Add component metrics with explicit TVirtualImage
ms_metric = itk.MeanSquaresImageToImageMetricv4[ImageType, ImageType, ImageType].New()
multi_metric.AddMetric(ms_metric)

# Set weights
weights = itk.Array[itk.D](1)
weights[0] = 0.5
multi_metric.SetMetricWeights(weights)

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Fixes #5652

Original prompt

This section details on the original issue you should resolve

<issue_title>Wrap ObjectToObjectMultiMetricv4</issue_title>
<issue_description>

Description

ObjectToObjectMultiMetricv4 is currently not wrapped (to Python). Multimetric registration is currently only possible via thirdparty registration codes, like AntsPy.

Expected behavior

Add wrap instructions for ObjectToObjectMultiMetricv4 (dimensions 2 and 3, types float and double, ...?)

Actual behavior

Currently not wrapped, not available.

Additional Information

</issue_description>

<agent_instructions>Examine wrapping of similar classes and provide a similar CMake wrapping configuration. A test is not needed since it is likely an abstract class.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Wrap ObjectToObjectMultiMetricv4 for Python Add Python wrapping for ObjectToObjectMultiMetricv4 Nov 21, 2025
Copilot AI requested a review from thewtex November 21, 2025 16:53
Copilot finished work on behalf of thewtex November 21, 2025 16:53
@github-actions github-actions bot added area:Python wrapping Python bindings for a class area:Registration Issues affecting the Registration module labels Nov 21, 2025
@thewtex
Copy link
Member

thewtex commented Nov 22, 2025

@copilot specify the third template parameter TVirtualImage, based on the wrapped image types. Also, add a test per the example in the pull request comment.

Copy link
Contributor Author

Copilot AI commented Nov 22, 2025

@copilot specify the third template parameter TVirtualImage, based on the wrapped image types. Also, add a test per the example in the pull request comment.

Updated in commit d6af876:

  • Added explicit TVirtualImage parameter with Image types for both float and double
  • Created Python test demonstrating multi-metric usage with adding metrics and setting weights

Copilot finished work on behalf of thewtex November 22, 2025 16:20
import itk

# Test basic instantiation
multi_metric = itk.ObjectToObjectMultiMetricv4[2, 2].New()
Copy link
Contributor

@dyollb dyollb Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the TVirtualImage needs to be specified here explicitly - the wrapping does not specify a default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please add the image type to the instantiation

@github-actions github-actions bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct labels Nov 24, 2025
Copilot AI changed the title Add Python wrapping for ObjectToObjectMultiMetricv4 ENH: Add Python wrapping for ObjectToObjectMultiMetricv4 Nov 24, 2025
Copilot finished work on behalf of thewtex November 24, 2025 02:24
@thewtex thewtex force-pushed the copilot/wrap-objecttoobjectmultimetricv4 branch from de52d8f to fc7fbd3 Compare November 24, 2025 12:56
@github-actions github-actions bot added the type:Enhancement Improvement of existing methods or implementation label Nov 24, 2025
@thewtex
Copy link
Member

thewtex commented Nov 24, 2025

@copilot fix the wrapping of MeanSquaresImageToImageMetricv4 and other ImageToImageMetricv4 classes to be instantiated over TVirtualImage like ObjectToObjectMultiMetricv4. Then update the test to include this specification.

Copy link
Contributor Author

Copilot AI commented Nov 24, 2025

@copilot fix the wrapping of MeanSquaresImageToImageMetricv4 and other ImageToImageMetricv4 classes to be instantiated over TVirtualImage like ObjectToObjectMultiMetricv4. Then update the test t...

Updated in commit ae3dca7:

  • Modified ImageToImageMetricv4 and all derived classes to include explicit TVirtualImage parameter
  • Updated test to use MeanSquaresImageToImageMetricv4[ImageType, ImageType, ImageType] with explicit TVirtualImage specification

Copilot AI changed the title ENH: Add Python wrapping for ObjectToObjectMultiMetricv4 ENH: Add Python wrapping for ObjectToObjectMultiMetricv4 with explicit TVirtualImage Nov 24, 2025
Copilot finished work on behalf of thewtex November 24, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Python wrapping Python bindings for a class area:Registration Issues affecting the Registration module type:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap ObjectToObjectMultiMetricv4

3 participants