itk-wasm and SimpleITK

Hi Everyone,

Is it possible to use SimpleITK in JavaScript? Did anyone try the SWIG wrapping to JS? Or is itk-wasm the current way to use ITK from JS?

Thanks so much!
Daniel

Hello @haehn,

Your observation is correct, itk.js is currently the only javascript option.

To follow up, this package should be helpful itk-image-io - npm

It is npm package providing ITK image io capabilities for use in the web browser.

Consider also looking at the following:

@matt.mccormick Is there example of use for the new itk-image-io ? This could provide material for anyone that could like to help working on the documentation :pray:

Hi,

Yes, to read an image file with readImageFile:

<script src="https://cdn.jsdelivr.net/npm/itk-wasm@1.0.0-a.10/dist/umd/itk-wasm.min.js"></script>
[...]
const { webWorker, image } = await itk.readImageFile(null, file)
webWorker.terminate()

Full UMD example that also supports meshes.

Or, packaged:

import { readImageFile } from "itk-wasm/dist/browser/index.js"

const { webWorker, image } = await itk.readImageFile(null, file)
webWorker.terminate()

Full Webpack example that also supports meshes..

Is there example of use for the new itk-image-io ?

The itk-image-io package provides the WebAssembly modules for image io. It is provided as a separate package in itk-wasm so you do have to pull down all these files when installing itk-wasm if they are not needed. This allows you to bundle the WebAssembly modules with your application. However, if fetching from the network is fine, you do not need it – with itk-wasm the package is configured to fetch these modules on-demand from the jsDelivr content delivery
network
by default.

1 Like

Thank you, these are great pointers!