[itk-python] Wrap ITK MatchCardinalityImageToImageMetric

Hi everyone,

I have been using ITK in the past and I recently started a python project. In this project I would like to use the MatchCardinalityImageToImageMetric metric. However, the metric has not been ported yet to python so I am trying to find out how this can be done.
I am new to ITK development so I am not sure I understand how to proceed and I would appreciate a bit of guidance.

Form what I gathered form other function, I wrote a .wrap file and uploaded is to GitHub (https://github.com/bdepalle/ITKMatchCardinalityImageToImageMetric/blob/master/itkMatchCardinalityImageToImageMetric.wrap).

I have looked into cookiecutter but I am not sure how to proceed from there and how to make it work with the itk package I installed with pip.

What am I missing here? Am I on the right track to get the metric I need in python? If so, what should I do next? If not, what should I do instead?

Thanks for you help,

Baptiste

Hello Baptiste,

Yes, in general, if you create a new class, Python packages can easily be generated and uploaded to PyPI by starting from the ITKModuleTemplate cookie-cutter.

This repository may be private (I cannot access the file), but since this class is already in ITK, you can contribute the wrapping configuration to its module wrapping directory. For more information on how to contribute a file, see our CONTRIBUTING.md.

After it is merged, the ITKPythonPackage ITK version is updated nightly, so you can build pre-release binaries until the next release.

Thanks for contributing to ITK!

Matt

1 Like

Hi everyone,

It has been a while since my first post and in the meantime, thanks to Matt’s help, I managed to add the file itkMatchCardinalityImageToImageMetric.wrap to ITK-master/Modules/Registration/Common. I thought this was enough to make the metric available in python but when installing the last version of ITK (5.1.1 with pip) which contain the wrap file, the metric is not available. All other ITK components in the wrapping folder are working properly.
Can you help me figure out what I am missing to make this metric work in python?

Thanks,

Baptiste

Hi @bdepalle, thanks for your contribution!
Are you sure v5.1.1 contains the itkMatchCardinalityImageToImageMetric.wrap file?
I see it on master, but I don’t think it made it on time for v5.1.1. You could wait for the next update, or compile the wrappings yourself using the master branch.

v5.1.1 was not cut from master, but from v5.1.0+select patches.

Thank you for the answers.
I saw the wrap file in v5.1.1 master so I thought it would be available in the compiled version.

Now I am trying to compile the master branch in Ubuntu 18.04.5 LTS using the following direction: https://itkpythonpackage.readthedocs.io/en/master/Build_ITK_Python_packages.html.

I checked all requirement and I as far as I know, everything should be installed on my system. My python version is 3.6.9. Though the compilation crash with the following error:

-- Installing: /work/_skbuild/linux-x86_64-3.5/cmake-install/./itkLazy.py
-- Installing: /work/_skbuild/linux-x86_64-3.5/cmake-install/./itkHelpers.py
CMake Error at /work/ITK-cp35-cp35m-manylinux1_x64/Wrapping/Generators/Python/PyBase/cmake_install.cmake:41 (file):
  file INSTALL cannot find
  "/work/ITK-cp35-cp35m-manylinux1_x64/Wrapping/Generators/Python/itk/pyBasePython.py":
  No such file or directory.
Call Stack (most recent call first):
  /work/ITK-cp35-cp35m-manylinux1_x64/Wrapping/cmake_install.cmake:43 (include)
  /work/ITK-cp35-cp35m-manylinux1_x64/cmake_install.cmake:804 (include)
  ITKPythonPackage-build/cmake_install.cmake:105 (include)
  cmake_install.cmake:41 (include)


FAILED: CMakeFiles/install.util 
cd /work/_skbuild/linux-x86_64-3.5/cmake-build && /usr/bin/cmake -P cmake_install.cmake
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/opt/python/cp35-cp35m/lib/python3.5/site-packages/skbuild/setuptools_wrap.py", line 551, in setup
    cmkr.make(make_args, env=env)
  File "/opt/python/cp35-cp35m/lib/python3.5/site-packages/skbuild/cmaker.py", line 482, in make
    os.path.abspath(CMAKE_BUILD_DIR)))

An error occurred while building with CMake.
  Command:
    "cmake" "--build" "." "--target" "install" "--config" "Release" "--"
  Source directory:
    /work
  Working directory:
    /work/_skbuild/linux-x86_64-3.5/cmake-build
Please see CMake's output for more information.
+ exit 1
~/Documents/ITK/ITKPythonPackage

From what I understand, the file pyBasePython.py is missing but I have no clue where to get it from.
Do you have any suggestion?

Thanks,

Baptiste

Could it be issue 2005?

itk-5.2rc1 is available with binary packages that include itk.itkMatchCardinalityImageToImageMetric.

pip install --upgrade --pre itk