How to build ImageRegistration8 example with ITK-WASM?


I’m trying to compile the example ImageRegistration8.cxx for WebAssembly without success. I have followed the tutorial in and it works correctly. However, when I follow the same steps for ImageRegistration8.cxx I get some errors when launching

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 (1.1 KB)
package.json (623 Bytes)

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?

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 ? :slight_smile:

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

yes, it work with my own ITK build.

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

This is what I get in the docker logs:

If your ITK build is a trimmed-down version, does it still work? That was my original question.

WIth ITKGroup_Core disabled ?

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

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:

Build OK:

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.


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

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. script should be helpful with that. Also take a look at this thread.

Hi dzenanz,

Here is the result of the python script:

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

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.


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

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.

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.

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 – we will work on these.

1 Like

Thx Matt for your help :slight_smile: ,

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


Yes, the Docker image itkwasm/wasi:20230315-07caf9ca or later is needed.

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.


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,

npm run build:wasi

and found in dist/wasi-image-io/. Eventually these will be distributed in a registry (once it is available :slight_smile: ).

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

1 Like

Hi, thx you for your help :slight_smile: