ITK-Wasm (Insight Toolkit WebAssembly)
repository·main·Indexed 42 days ago
https://github.com/insightsoftwareconsortium/itk-wasmEnables high-performance spatial analysis by bringing the Insight Toolkit (ITK) and C++ code to WebAssembly. It supports execution in web browsers, Node.js, Python, and WASI runtimes, providing efficient data bridging and parallel pipeline execution. Includes tools like itk-convert for image and mesh format transcoding, as well as packages for regression testing such as @itk-wasm/compare-images and @itk-wasm/compare-meshes.
What's inside ITK-Wasm
- This tutorial series covers the end-to-end workflow for developing scientific C++ processing pipelines compiled to WebAssembly (Wasm). The process involves setting up a build system, creating C++ pipelines, and executing them across different environments including the command line, Node.js, and the browser. It also covers advanced topics like handling complex data types and debugging Wasm pipelines.
Overview of ITK-Wasm
mainITK-Wasm combines the Insight Toolkit (ITK) with WebAssembly to enable high-performance spatial analysis across multiple environments. It allows you to execute ITK or arbitrary C++ code in a web browser, Node.js, Python, or via WASI runtimes.
Key capabilities include:
- Building C/C++ to WebAssembly: Tools to compile C++ code for Wasm targets.
- Data Bridging: Bridging local filesystems, JavaScript/TypeScript/Python data structures, and traditional file formats.
- Efficient Data Transfer: High-performance data movement in and out of the WebAssembly runtime.
- Parallel Execution: Asynchronous, parallel execution of processing pipelines using a worker pool.
Available @itk-wasm packages and capabilities
mainThe following packages are built with
itk-wasmand provide various scientific and medical imaging capabilities for both JavaScript/TypeScript and Python environments:- @itk-wasm/compare-images: Compare images with a tolerance for regression testing.
- @itk-wasm/compress-stringify: Zstandard compression/decompression and base64 encoding/decoding in WebAssembly.
- @itk-wasm/dicom: Read files and images related to the DICOM file format.
- @itk-wasm/downsample: Pipelines for downsampling images.
- @itk-wasm/elastix: A toolbox for rigid and nonrigid registration of images.
- @itk-wasm/htj2k: Wasm-SIMD accelerated decoding and encoding of High-throughput JPEG2000 (HTJ2K) images.
- @itk-wasm/image-io: Input and output for scientific and medical image file formats.
- @itk-wasm/mesh-filters: Mesh filters to repair, remesh, subdivide, decimate, smooth, triangulate, etc.
- @itk-wasm/mesh-io: Input and output for scientific and medical mesh file formats.
- @itk-wasm/morphological-contour-interpolation: Morphological contour interpolation for scientific and medical mesh file formats.
Install the itkwasm Python interface
mainTheitkwasmpackage provides a Python interface to itk-wasm WebAssembly modules. For detailed usage and API references, refer to the official project documentation.Compare meshes and polydata for regression testing with @itk-wasm/compare-meshes
mainThe@itk-wasm/compare-meshespackage provides utilities to compare meshes and polydata. This is primarily intended for use in regression testing environments to ensure that mesh processing outputs remain consistent over time.Use the TypeScript / JavaScript core tooling
mainThe
itk-wasmNPM package provides the core infrastructure for using ITK-Wasm in Node.js and browser environments. It includes:- Runtime Support: Works in both Node.js and web browsers.
- Web Worker Pool: Enables parallel processing for performance.
- CLI: A command line interface used to drive builds, generate language bindings/package configurations, and test wasm binaries.
npm install itk-wasmUse the Python core library
mainThe
itkwasmPython package provides idiomatic and performant interfaces for using ITK-Wasm modules in Python. It acts as a bridge to NumPy and ITK and includes a plugin system for accelerator packages.Execution Modes:
- System Execution: Enabled via
wasmtime-py. - Browser Execution: Enabled via
Pyodide.
pip install itkwasm- System Execution: Enabled via
What is a TransformList?
mainATransformListis an ordered sequence of spatialTransformobjects. In the context ofitk-wasm, aTransformListis implemented as a standard JavaScript array containingTransformobjects.Access transform parameters via the transform__parameters slot
mainIn the ITK-Wasm model, a
transformobject provides access to its internal parameters through thetransform__parametersslot. This slot returns the parameters of the transform asBinaryData.- Domain:
None(no input required to access the slot) - Range:
[1..1] [BinaryData](returns exactly oneBinaryDataobject representing the parameters)
- Domain:
Understand the Mesh data model
mainThe
Meshclass is anInterfaceTypeused to represent an N-dimensional mesh. It serves as a structured way to pass mesh data between WebAssembly modules and the host environment. AMeshconsists of spatial coordinates (points), connectivity information (cells), and optional attribute data associated with either the points or the cells.Key components of a
Meshinclude:- Points: The spatial coordinates of the mesh vertices.
- Cells: The connectivity information defining how points form cells (e.g., triangles, tetrahedrons).
- Point Data: Attributes associated with individual points (e.g., scalars, vectors).
- Cell Data: Attributes associated with individual cells (e.g., cell volumes, normals).
The name slot in ITK-Wasm transforms
mainIn the ITK-Wasm transform model, thenameslot is used to provide a unique identifier for a transform. It is a required property (cardinality 1..1) and must be aString.Understand the Date type representation
mainIn the ITK-Wasm data model, thedatetype represents a year, month, and day in an idealized calendar. It is based on theXSDDateroot builtin type and is represented as a string (str) in its serialized form.