Skip to content

Conversation

@thewtex
Copy link
Member

@thewtex thewtex commented May 16, 2025

No description provided.

@thewtex
Copy link
Member Author

thewtex commented May 16, 2025

@N-Dekker WIP for #341 but reviews welcome!

@thewtex thewtex requested a review from N-Dekker May 16, 2025 16:59
@thewtex thewtex force-pushed the downsample-register-example branch 4 times, most recently from aee7c1e to f5f8aff Compare May 16, 2025 20:05
@thewtex
Copy link
Member Author

thewtex commented May 19, 2025

We still have the issue:

ENH: Add transformix wasm pipeline
Resamples the input with the transform.

The test fails with:

7: itk::ExceptionObject (0x5c4199ce1e70)
7: Location: "unknown"
7: File: /home/matt/bin/ITKElastix-GCC-Release/_deps/elx-src/Core/Main/itkTransformixFilter.hxx
7: Line: 377
7: Description: ITK ERROR: No entry Spacing found in transformParameterMap

Should we be adding the output spacing as a parameter?

@N-Dekker
Copy link
Collaborator

We still have the issue:

ENH: Add transformix wasm pipeline
Resamples the input with the transform.

The test fails with:

7: itk::ExceptionObject (0x5c4199ce1e70)
7: Location: "unknown"
7: File: /home/matt/bin/ITKElastix-GCC-Release/_deps/elx-src/Core/Main/itkTransformixFilter.hxx
7: Line: 377
7: Description: ITK ERROR: No entry Spacing found in transformParameterMap

Should we be adding the output spacing as a parameter?

Just checked: "Spacing" should indeed specify the spacing of the output image.

I think the idea is that it important that users explicitly specify the spacing, rather than leave it (1, 1, 1), for example, because for realistic images, it is very relevant. Right, Stefan and Marius (@stefanklein, @mstaring)?

@thewtex thewtex force-pushed the downsample-register-example branch from f5f8aff to 8410990 Compare May 27, 2025 21:38
@thewtex thewtex force-pushed the downsample-register-example branch from 8410990 to 6cb5d47 Compare June 2, 2025 14:02
@thewtex thewtex force-pushed the downsample-register-example branch 3 times, most recently from e55ba4a to aec106b Compare June 24, 2025 16:45
@thewtex
Copy link
Member Author

thewtex commented Jun 24, 2025

Should we be adding the output spacing as a parameter?

I ended up keeping maintaining the behavior of transformix by using the moving image parameters that elastix will output to a transform parameter file, by default. If the ParameterObject entries are not available, use reasonable default. And allow explicit overrides / specification by the caller.

@thewtex thewtex marked this pull request as ready for review June 25, 2025 21:12
@thewtex thewtex force-pushed the downsample-register-example branch from 8cb4a15 to 4370ecc Compare June 25, 2025 21:13
@thewtex
Copy link
Member Author

thewtex commented Jun 25, 2025

@N-Dekker this is ready for review! There are a number of related to Typescript, Javascript, artifacts, etc. that do not need much attention.

@N-Dekker
Copy link
Collaborator

N-Dekker commented Jul 4, 2025

@thewtex It appears that your last commit ENH: Base wasm on ITK-Wasm 1.0b192 is not on the branch of your fork! Looking at https://github.com/thewtex/ITKElastix/tree/downsample-register-example

Do you know how that is possible? I was reviewing based on your fork, but now your fork seems out of date!

Comment on lines +63 to +64
pipeline.add_option("-i,--initial-transform", initialTransform, "Initial transform to apply before registration")
->type_name("INPUT_TRANSFORM");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, the elastix.exe command-line interface has "-t0" for the initial transform of a registration, whereas elastix-wasm now has both "-i" and "-t" (but not "-t0"). Should these command-line flags still be brought in sync, one way or another? Or are they different for a fundamental reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can/should bring them into sync! I will update this one -- please let me know if you see any others that should be updated.

@thewtex
Copy link
Member Author

thewtex commented Jul 14, 2025

Do you know how that is possible? I was reviewing based on your fork, but now your fork seems out of date!

@N-Dekker GitHub has a hard time with PR's from my fork, so I have to push this up to this repository to make a PR. But I also updated the same branch on my fork 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thewtex I think ITKElastix should still be adjusted to use TOML, instead of JSON, for parameter files. You know, we discussed JSON vs YAML vs TOML parameter files earlier this year. TOML appeared preferable to JSON, because unlike JSON, TOML allows users to add comments to their parameter files. (I think you suggested TOML to us 😃) So from February, elastix and transformix fully support TOML parameter files, both as input and output.

I think ITKElastix wasm executables (like "default-parameter-map.cxx") can output an elastix parameter map to stream as follows:

#include "Install/elxConversion.h"
...

  itk::wasm::OutputTextStream outputTextStream;
  outputTextStream.Get() <<
    elastix::Conversion::ParameterMapToString(parameterMap,
                                              elastix::ParameterMapStringFormat::Toml);

Right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker yes, for the pipelines like write-parameter-files, we should output the awesome new TOML support instead of the bespoke elastix parameter file format ✨ 🥇 .

For the elastix-wasm pipeline we want to output JSON from the wasm executable. This is for JavaScript / Python binding that transforms the JSON into JavaScript Objects and Python dict's for working with the data in JavaScript and Python. When the goal is to save or load the result to file, these are serialized / deserialized with read-parameter-file, write-parameter-file (soon in TOML!).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thewtex Sorry, can you please clarify? Would it be OK to you to replace JSON parameter files like "wasm/test/data/input/CT_3D_lung.json" with the equivalent TOML parameter files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker We will add wasm/test/data/input/CT_3D_lung.toml, and use this for the data format with read-parameter-files, write-parameter-files. I would like to also keep the wasm/test/data/input/CT_3D_lung.json file to help add tests with native binaries / in the CLI the same codepath used in the JavaScript and Python wrapping. This may be easier to understand after the toml support has been added.

Based on current sources.
For deployment, we also needed to add pip to the build environment.
Note: we support std::variant for the ValueVector to support, for
example, the actual boolean or number types being specified in python or
typescript.
More efficient and enables use in bindings.
More efficient, enables bindings, and improves wasm module size.
Resamples the input with the transform.
The `elastix` function's signature changed (returns transform outputs).
Required for transform interface type support.
Generated by VS Code.
This is generated based on the javascript module contents.
Addresses:

 test/test_write_parameter_files_async.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   pyodide.ffi.JsException: DataCloneError: Failed to execute 'postMessage' on 'Worker': [object Map] could not be cloned.

/lib/python3.12/site-packages/itkwasm_elastix_emscripten/write_parameter_files_async.py:36: JsException

via:

  InsightSoftwareConsortium/ITK-Wasm@f805bf2
Shows how to:

1. Register with elastix
2. Apply the resulting transform with transformix
3. Downsample the input images.
4. Register the downsampled images.
5. Apply the resulting transform at the original resolution.
Improved Transform support.
@thewtex thewtex force-pushed the downsample-register-example branch from 1f23b48 to 5cc7e7a Compare September 2, 2025 19:36
Through:

- Bump itk-wasm to 1.0.0-b.196
- Bump itkwasm python package dependency
- Bump of supporting Docker images
- Rebuild wasm packages
Python and Typescript/JavaScript and downsample register example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants