# \[itk-python\] Wrap ITK MatchCardinalityImageToImageMetric

**URL:** https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208
**Category:** Engineering
**Tags:** python
**Created:** [June 19, 2020, 2:27am UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208 "2020-06-19T02:27:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![bdepalle](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@bdepalle](https://discourse.itk.org/u/bdepalle)
#### Post date: [June 19, 2020, 2:27am UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/1 "2020-06-19T02:27:21Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [June 19, 2020, 12:34pm UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/2 "2020-06-19T12:34:49Z")

</div>

Hello Baptiste,

> [@bdepalle](#):
>
> 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.

Yes, in general, if you create a new class, Python packages can easily be [generated and uploaded to PyPI](https://itkpythonpackage.readthedocs.io/en/master/Build_ITK_Module_Python_packages.html) by starting from the [ITKModuleTemplate cookie-cutter](https://github.com/InsightSoftwareConsortium/ITKModuleTemplate).

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

This repository may be private (I cannot access the file), but since this class is [already in ITK](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Registration/Common/include/itkMatchCardinalityImageToImageMetric.h), you can contribute the wrapping configuration to [its module wrapping directory](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Registration/Common/wrapping). For more information on how to contribute a file, see our [CONTRIBUTING.md](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md).

After it is merged, the [ITKPythonPackage ITK version is updated nightly](https://github.com/InsightSoftwareConsortium/ITKPythonPackage/commits/master), so you can build [pre-release binaries](https://itkpythonpackage.readthedocs.io/en/master/Build_ITK_Python_packages.html) until the next release.

Thanks for contributing to ITK!

Matt

---

<div class="post-metadata">

### Author: ![bdepalle](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@bdepalle](https://discourse.itk.org/u/bdepalle)
#### Post date: [September 22, 2020, 3:11am UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/3 "2020-09-22T03:11:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [September 22, 2020, 6:23am UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/4 "2020-09-22T06:23:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 23, 2020, 1:29pm UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/5 "2020-09-23T13:29:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bdepalle](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@bdepalle](https://discourse.itk.org/u/bdepalle)
#### Post date: [September 23, 2020, 2:28pm UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/6 "2020-09-23T14:28:25Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 23, 2020, 3:57pm UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/7 "2020-09-23T15:57:25Z")

</div>

Could it be [issue 2005](https://github.com/InsightSoftwareConsortium/ITK/issues/2005)?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [January 29, 2021, 7:40pm UTC](https://discourse.itk.org/t/itk-python-wrap-itk-matchcardinalityimagetoimagemetric/3208/8 "2021-01-29T19:40:59Z")

</div>

[`itk-5.2rc1` is available](https://discourse.itk.org/t/itk-5-2-release-candidate-2-available-for-testing/3810) with binary packages that include `itk.itkMatchCardinalityImageToImageMetric`.

```auto
pip install --upgrade --pre itk

```
