Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasm jpegls and j2k/htj2k support #910

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

hanayik
Copy link
Collaborator

@hanayik hanayik commented Jan 19, 2025

This PR enables WASM builds of dcm2niix that have support for both jpegls and j2k/htj2k using an emscripten build of openjpeg.

An environment manager pixi, has been added to support the WASM build workflow across platforms (macOS/Linux). Note that on macOS-arm64 emscripten must still be installed/managed outside of pixi. Use a tool like homebrew to install it.

Here's the dcm2niix version string, printed to the browser console, where it reports the compiled jpeg support:

Chris Rorden's dcm2niiX version v1.0.20241231  (JP2:OpenJPEG) (JP-LS:CharLS) Clang20.0.0  (32-bit Windows)

The WASM output files with jpeg support are roughly 1.8x the size of the base dcm2niix WASM build (a difference of 397K)

-rwxr-xr-x  1 taylor  staff   879K 19 Jan 21:52 dcm2niix.jpeg.wasm
-rwxr-xr-x  1 taylor  staff   482K 19 Jan 21:52 dcm2niix.wasm

This size increase seems to track well with other browser implementations such as @cornerstonejs/codec-openjpeg which only compiles openjpeg (not combined with something like dcm2niix) and its size is 367 kB

I have also tested the jpeg build of dcm2niix WASM in the browser using the Aliza-DICOM-viewer-HTJ2k/HTJ2K-YBR_ICT.dcm test image that was tested in issue #897. The resulting NIFTI file renders in niivue the same as Slicer3D:

Screenshot 2025-01-19 at 21 51 06

To test this PR locally

You will need:

  • NodeJS/NPM
  • Emscripten (only needed separately from pixi if on macOS-arm64)
  • Pixi
  • Make/Cmake

Pixi is used to create the environment for building the WASM port of dcm2niix. To install pixi, follow their instructions.

Note: on macos-arm64, you can get emscripten using homebrew since there is not yet a native arm64 version of emscripten on conda-forge (which is where pixi searches for packages).

Building dcm2niix WASM

# from repo root
pixi run wasm

clean up after build

# from repo root
pixi run clean

@hanayik hanayik requested a review from neurolabusc January 19, 2025 22:22
@neurolabusc neurolabusc merged commit ef9f53a into development Jan 20, 2025
3 checks passed
@neurolabusc
Copy link
Collaborator

Great job.

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.

2 participants