# 3D multi-modal medical image registration using user defined function for similarity metric computation

**URL:** https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064
**Category:** Beginner Questions
**Tags:** registration, python, simpleitk
**Created:** [June 7, 2022, 10:09am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064 "2022-06-07T10:09:04Z")
**Posts on this page:** 20
**Page:** 2

<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: [July 4, 2022, 12:50pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/22 "2022-07-04T12:50:30Z")

</div>

You might be running into a mismatch between versions of ITK and SimpleITK. It is best to see which version of ITK [SimpleITK’s superbuild](https://github.com/SimpleITK/SimpleITK/blob/v2.2rc3/SuperBuild/External_ITK.cmake#L65) uses.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [July 5, 2022, 1:53pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/23 "2022-07-05T13:53:49Z")

</div>

If you are rebuilding SimpleITK super build, and recently updated the source code from git, the ITK git tag may be out of sync. The easiest is to start with an empty build directly for the super build.

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 6, 2022, 5:25am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/24 "2022-07-06T05:25:06Z")

</div>

The ITK that I cloned from Github has `GIT_TAG = c44a7731f22bd5d241ac8f9369018671800f5cd9`, as mentioned in the `ITK\.git\logs\HEAD` file.

The `GIT_TAG` mentioned in `SITK\SuperBuild\External_ITK.cmake` file is `ee664da6bb1a83cdf82e2582126e65119a4de1a4`.

Where can I get ITK with `GIT_TAG = ee664da6bb1a83cdf82e2582126e65119a4de1a4` ?

I cloned ITK from [here](https://github.com/InsightSoftwareConsortium/ITK) and SimpleITK (SITK) from [here](https://github.com/SimpleITK/SimpleITK/tree/12c5683f02e5bd90688f0105fed0cf9b84432c43)

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 6, 2022, 1:48pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/25 "2022-07-06T13:48:46Z")

</div>

Hello @debapriya,

You already have it. This is just an older commit. You can branch off this commit add your new ITK code, build it and then point SimpleITK to that.

```auto
git branch new_branch_name ee664da6bb1a83cdf82e2582126e65119a4de1a4
git checkout new_branch_name
work...

```

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 7, 2022, 3:23pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/26 "2022-07-07T15:23:10Z")

</div>

Thank you @zivy, @dzenanz and @blowekamp. I could match versions of ITK and SITK. I have configured and generated SITK, pointing to my modified version of ITK. While building SITK on Visual Studio 2019, however, a few errors are showing. Below is a screenshot of the error page.

 ![SITK_BUILD_ERROR](https://discourse.itk.org/uploads/default/original/2X/e/e6f46fd2617a554899d90f788a582c5143dda4ae.png)

As far as the last error is concerned, `sitkDICOMOrientImageFilter.h` is indeed not present anywhere in the SITK folder. I have no idea what the other errors mean. Please help.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 7, 2022, 6:48pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/27 "2022-07-07T18:48:55Z")

</div>

Hello @debapriya,

When you say SITK folder, I assume you mean the SimpleITK source directory.

You will not find this file there because it is automatically generated from its json description (see figure 1 in “The Design of SimpleITK” [paper](https://www.frontiersin.org/articles/10.3389/fninf.2013.00045/full) for details).

You should be able to find it in your build directory (assuming you are doing an [out of source build](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Getting%20Started.html#directory-structure)).

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 8, 2022, 11:32am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/28 "2022-07-08T11:32:37Z")

</div>

Yes, by SITK folder I meant the SimpleITK source directory. I am doing an out of source build. I checked the SITK build directory also. `sitkDICOMOrientImageFilter.h` is not generated.

In the CMakeCache.txt file, however, I found this line:  
`SimpleITKBasicFiltersGeneratedSource_SimpleITKFilters:INTERNAL=sitkDICOMOrientImageFilter_Support.cxx;sitkPasteImageFilter.cxx`

What might have gone wrong? Did I miss to put values in some variables during configuration?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [July 8, 2022, 1:53pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/29 "2022-07-08T13:53:33Z")

</div>

> [@debapriya](#):
>
> As far as the last error is concerned, `sitkDICOMOrientImageFilter.h` is indeed not present anywhere in the SITK folder. I have no idea what the other errors mean. Please help.

This filter is contained in the ITK remote module “SimpleITKFilter”. The CMake variable “Module\_SimpleITKFilters” should be set to ON in the ITK build to enable the remote module.

It is strongly recommended to use the SimpleITK Superbuild with the ITK configured for SimpleITK, you can see the Superbuild script [here](https://github.com/SimpleITK/SimpleITK/blob/master/SuperBuild/External_ITK.cmake) which may give some insights as to how to configure your ITK build manually.

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 9, 2022, 12:29pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/30 "2022-07-09T12:29:09Z")

</div>

Thank you @blowekamp . I could build SITK with 0 error this time 😀

I want to run 3D image registration codes in python, for example, the ones given in SITK tutorial jupyter notebook `05_basic_registration`, but using my own metric.

Please tell me the process.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 9, 2022, 3:14pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/31 "2022-07-09T15:14:33Z")

</div>

Hello @debapriya,

If you followed the guidance from the [post above](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/11), then all you need to do is replace the current `SetMetricAsX` invocation in the code with the one you have added.

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 11, 2022, 7:13am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/32 "2022-07-11T07:13:14Z")

</div>

Yes, I have done the changes given [here](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/11).

My query is,  
in SITK tutorial jupyter notebook, `import SimpleITK as sitk`, does not point to my modified SITK. How can I make it point to my modified version?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 11, 2022, 12:35pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/33 "2022-07-11T12:35:56Z")

</div>

Hello @debapriya,

If you used the `environment.yml` or `requirements.txt` files that are part of the notebook repository to create a virtual environment, those will use/install an official SimpleITK version (\>=2.1.0).

To install the custom SimpleITK version you built, activate the virtual environment and install as [described here](https://simpleitk.readthedocs.io/en/master/building.html#python-installation-1).

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 12, 2022, 9:36am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/34 "2022-07-12T09:36:55Z")

</div>

Done that. It is recognizing my metric now.  
However, `ModuleNotFoundError` is showing for `downloaddata`, `gui` and `registration_gui`. Hence, I cannot see the output of registration.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 12, 2022, 1:31pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/35 "2022-07-12T13:31:07Z")

</div>

Hello @debapriya,

Those are utility modules that are part of the SimpleITK jupyter notebook repository. Just copy them to the location where you have your notebook (assuming you are not working with a clone of the notebook repository - that should work out of the box without any changes in which case I’m not sure what is causing the problem).

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [July 12, 2022, 4:45pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/36 "2022-07-12T16:45:34Z")

</div>

It worked!! 😇

Thank you @zivy, @blowekamp and @dzenanz. Your help was vital at each step.

 ![Result1](https://discourse.itk.org/uploads/default/original/2X/f/ff1e64ab5fee85c3afc7489eac4673f2fe977882.png)

 ![Result2](https://discourse.itk.org/uploads/default/original/2X/b/b85e1c4ac9d5e996c0ebfd1324c2fe122707d513.jpeg)

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [July 13, 2022, 12:16pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/37 "2022-07-13T12:16:00Z")

</div>

Congratulations on your success! 🥳 🎉

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [September 3, 2022, 7:40am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/38 "2022-09-03T07:40:56Z")

</div>

Hello,  
I am trying to configure ITK and SimpleITK in another laptop (different configuration). I followed the same procedure as I did the previous time. ITK configuration happened smoothly. However, SimpleITK configuration is showing the following error

 ![ERROR](https://discourse.itk.org/uploads/default/original/2X/2/2487ee3f15df7ed8a0efa4646a940d2fc8f57787.png)

Please tell me what is going wrong.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 3, 2022, 11:04am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/39 "2022-09-03T11:04:33Z")

</div>

That error message does not look familiar to me.

Have you tried creating a new and empty binary directory to do an initial configuration?

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [September 3, 2022, 4:03pm UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/40 "2022-09-03T16:03:22Z")

</div>

Source and Build directories for SimpleITK are respectively `D:\SimpleITK` and `D:\SITK_Build`

Source and Build directories for ITK are `D:\ITK` and `D:\ITK_Build` respectively.

Lua, Swig and GTest are located in `D:\`

Still I am getting same error.

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [September 9, 2022, 6:24am UTC](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064/41 "2022-09-09T06:24:57Z")

</div>

Hello,  
I have been able to resolve the above error. I uninstalled CMake and Python, and reinstalled older versions of them (CMake 3.23.3 and Python 3.10.5). With these versions, no error is showing, though I do not know what actually went wrong.

However, I am stuck again. During `Build Solution`, I am getting `out of memory` error in Visual Studio 2022. I have tried a few solutions suggested on the internet, but none helped. Please help.

 ![ERROR2](https://discourse.itk.org/uploads/default/original/2X/8/895992eae435969202b1e85903dc81e7636c90fc.png)

[Previous page](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064.md?page=1)

[Next page](https://discourse.itk.org/t/3d-multi-modal-medical-image-registration-using-user-defined-function-for-similarity-metric-computation/5064.md?page=3)
