# How to build ImageRegistration8 example with ITK-WASM?

**URL:** https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800
**Category:** Engineering
**Tags:** registration, itk-wasm
**Created:** [March 14, 2023, 10:24am UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800 "2023-03-14T10:24:06Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 14, 2023, 10:24am UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/1 "2023-03-14T10:24:06Z")

</div>

Hello,

I’m trying to compile the example ImageRegistration8.cxx for WebAssembly without success. I have followed the tutorial in [https://wasm.itk.org/tutorial/inputs\_outputs](https://wasm.itk.org/tutorial/inputs_outputs) and it works correctly. However, when I follow the same steps for ImageRegistration8.cxx I get some errors when launching

```auto
npx itk-wasm -i itkwasm/wasi -b ./wasi-build/ build

```

A example of the errors I get:  
" … /ITK/Modules/Registration/Metricsv4/include/itkMattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader.hxx:210:35: error: no member named ‘m\_JointPDFDerivativesLock’ in ‘itk::MattesMutualInformationImageToImageMetricv4\<itk::Image\<float, 3\>, itk::Image\<float, 3\>\>’  
&this-\>m\_MattesAssociate-\>m\_JointPDFDerivativesLock, …"

I suppose that the problem comes from the CMakeLists.txt file I use (see attached files), could anybody tell me what I am doing wrong?:

Thanks a lot!

[CMakeLists.txt](https://discourse.itk.org/uploads/short-url/yuuyNeocNfXi18l3DfmfuUdnTyr.txt) (1.1 KB)  
[package.json](https://discourse.itk.org/uploads/short-url/a1tAqqLk5zyQ8Y39MVazOYSWLjE.json) (623 Bytes)

---

<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: [March 14, 2023, 1:49pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/2 "2023-03-14T13:49:26Z")

</div>

One way to debug this is to build ITK with just the components you declared as your dependencies. In CMake, turn off `ITK_BUILD_DEFAULT_MODULES`, and group Core, then enable these individual modules. Does your project build against such trimmed-down ITK?

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 14, 2023, 2:18pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/3 "2023-03-14T14:18:29Z")

</div>

Hi Dzenanz,  
Sorry but, i understand that itkwasm/wasi docker image contains ITK build and i don’t have the hand on ITK build options. But maybe I didn’t understand your answer ? 🙂

---

<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: [March 14, 2023, 2:28pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/4 "2023-03-14T14:28:48Z")

</div>

Try to compile your program the usual way, in C++, without WASM/WASI. Does that work?

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 14, 2023, 2:36pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/5 "2023-03-14T14:36:47Z")

</div>

yes, it work with my own ITK build.  
 ![image](https://discourse.itk.org/uploads/default/original/2X/6/6a853f8d5101fe053272b720bbc67c87b62e0986.png)

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 14, 2023, 3:03pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/6 "2023-03-14T15:03:32Z")

</div>

do i have a way to use my own ITK build to do my wasi build?

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 14, 2023, 3:26pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/7 "2023-03-14T15:26:49Z")

</div>

This is what I get in the docker logs:

 ![image](https://discourse.itk.org/uploads/default/original/2X/a/a7d8c136a53b0bbceef90cd902882b3c5b1788c6.png)

---

<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: [March 14, 2023, 4:38pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/8 "2023-03-14T16:38:50Z")

</div>

If your ITK build is a [trimmed-down version](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/2), does it still work? That was my original question.

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 15, 2023, 9:39am UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/9 "2023-03-15T09:39:23Z")

</div>

> [@dzenanz](#):
>
> One way to debug this is to build ITK with just the components you declared as your dependencies. In CMake, turn off `ITK_BUILD_DEFAULT_MODULES`, and group Core, then enable these individual modules. Does your project build against such trimmed-down ITK?

WIth ITKGroup\_Core disabled ?

---

<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: [March 15, 2023, 12:53pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/10 "2023-03-15T12:53:16Z")

</div>

Yes, with `ITK_BUILD_DEFAULT_MODULES` and `ITKGroup_Core` turned off. Group options show up after you disable default modules.

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 15, 2023, 3:34pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/11 "2023-03-15T15:34:26Z")

</div>

Hi, here is the result:  
By disabling ITK\_BUILD\_DEFAULT\_MODULE and ITKGroup\_Core, the imageRegistration8 sample does not work.  
To make it work, it was necessary to activate the following modules:  
-ITKGroup\_IO  
-ITKGroup\_Registration

 ![image](https://discourse.itk.org/uploads/default/original/2X/6/60cbb75b703c6b44c21e2c24ee8aa6f8ce8ed7b0.png)

Build OK:

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

On the other hand, I modified the CMakeLists.txt to remove all the dependent modules and add the path of ITK-build so that it works.

![image](https://discourse.itk.org/uploads/default/original/2X/a/aa0a6e3dd68f27bc850d205336d9b7b252d5a560.png)

1/ Cool, everything works with cmake locally, but now what should be done to make it work with ITK-WASM?  
2/ Is it possible to modify the optional modules in itkwasm/wasi docker container itk-build?  
3/ Are the examples provided in the kit all supposed to work?

Thx in advance

---

<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: [March 15, 2023, 4:56pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/12 "2023-03-15T16:56:52Z")

</div>

> [@David\_SAMSONOFF](#):
>
> [CMakeLists.txt](https://discourse.itk.org/uploads/short-url/yuuyNeocNfXi18l3DfmfuUdnTyr.txt)

The proper solution is to list ALL the dependent modules in the list. When compiling programs for the web, we should be careful about not including unnecessary libraries.

Enabling entire groups in your ITK build is not overly helpful in identifying the exact dependent module. [WhatModulesITK.py](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Utilities/Maintenance/WhatModulesITK.py) script should be helpful with that. Also take a look at this [thread](https://discourse.itk.org/t/trimming-down-itk-build-to-just-used-parts/1995).

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 16, 2023, 2:02pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/13 "2023-03-16T14:02:38Z")

</div>

Hi dzenanz,

Here is the result of the python script:

 ![image](https://discourse.itk.org/uploads/default/original/2X/d/dba4b68584c27d52f01212644de527267db8309f.png)

I copied these modules into my CMakeLists.txt and still got the same errors. I do not know what to think ☹

---

<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: [March 16, 2023, 2:34pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/14 "2023-03-16T14:34:54Z")

</div>

If you build ITK with only these modules turned on, does the example with against it? I would like to eliminate this variable before needing to look into the wasi build process.

---

<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: [March 16, 2023, 3:06pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/15 "2023-03-16T15:06:21Z")

</div>

Hi @David_SAMSONOFF ,

You are not doing anything wrong – improvements are required to make the Metricsv4 code used in ImageRegistration8.cxx work with the WASI toolchain 🙂

There is a bit of documentation on how to build / test / contribute to the WASI toolchain in the _Docs → Development → Hacking itk-wasm_ section of the [itk-wasm documentation](https://wasm.itk.org).

I created an example from _ImageRegistration8_, called it _mean-squares-versor-registration_, addressed the associated build issues, and added it to our CI testing [in this PR](https://github.com/InsightSoftwareConsortium/itk-wasm/pull/795).

The example will build / run / produce the same output as a native build, although it is currently not the fastest (we will add multi-threading) and there is a [backtrace that occurs on exit](https://github.com/InsightSoftwareConsortium/itk-wasm/issues/794) – we will work on these.

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 16, 2023, 4:01pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/16 "2023-03-16T16:01:03Z")

</div>

Thx Matt for your help 🙂 ,

This example works very well, the difference comes from the docker image used?

---

<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: [March 16, 2023, 4:12pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/17 "2023-03-16T16:12:00Z")

</div>

Yes, the Docker image [itkwasm/wasi:20230315-07caf9ca](https://hub.docker.com/r/itkwasm/wasi/tags) or later is needed.

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 17, 2023, 9:43am UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/18 "2023-03-17T09:43:38Z")

</div>

Hi matt and dzenanz,

Are there good practices that we must respect to make a web assembly dev? For example, I see the mean-squares-versor-registration example has different code than ImageRegistration8.  
Can an example that works in server side always work in web assembly?  
I am asking because currently if running the wasi build on ImageRegistration8 from the kit then I am getting errors.

 ![image](https://discourse.itk.org/uploads/default/original/2X/0/014d33f59c25c62fb9a9d0de737346e2e7ccc2fb.png)

---

<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: [March 21, 2023, 1:37pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/19 "2023-03-21T13:37:03Z")

</div>

Hi @David_SAMSONOFF ,

For WASI builds, nearly all the IO’s are supported but HDF5 ImageIO is currently not supported. I see GDCM related errors, although we do have GDCM WASI ImageIO.

I general, it is best to not build support for all the ImageIO code into wasm executable – it bloats their size. If possible build support for only the IO’s needed. Or, use the dedicated IO modules, built with,

```auto
npm run build:wasi

```

and found in `dist/wasi-image-io/`. Eventually these will be distributed in a [registry](https://github.com/bytecodealliance/SIG-Registries) (once it is available 🙂 ).

Convert the images from their original format to `.iwi.cbor`, which is supported by all `WebAssemblyInterface` modules.

---

<div class="post-metadata">

### Author: ![David\_SAMSONOFF](https://discourse.itk.org/user_avatar/discourse.itk.org/david_samsonoff/32/3318_2.png) [@David\_SAMSONOFF](https://discourse.itk.org/u/David_SAMSONOFF)
#### Post date: [March 21, 2023, 2:23pm UTC](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800/20 "2023-03-21T14:23:51Z")

</div>

Hi, thx you for your help 🙂

[Next page](https://discourse.itk.org/t/how-to-build-imageregistration8-example-with-itk-wasm/5800.md?page=2)
