Web Browser Input/Output

These Input/Output (IO) functions can be used from within a web browser’s JavaScript runtime. itk.js is best tested in Chrome, but it is used and designed to work on Chrome, Firefox, Microsoft Edge, Safari, and other browsers, including mobile browsers. In general, older browsers will function, but users on newer browsers will experience improved performance.

The itk.js IO functions convert native brower objects, File‘s, Blob‘s, and ArrayBuffer‘s to / from JavaScript objects with TypedArray‘s for binary data.

Most of these functions return a Promise.

These functions return the WebWorker used for computation. They also optionally accept a web worker from a previous execution as their first argument – pass the worker generated from execution or null if one is not available.


readFile(webWorker, file) -> { webWorker, image or mesh }

Read an image or mesh from a File.

readBlob(webWorker, blob, fileName, mimeType) -> { webWorker, image or mesh }

Read an image or mesh from a Blob. fileName is a string with the file name. mimeType is an optional mime-type string.

readArrayBuffer(webWorker, arrayBuffer, fileName, mimeType) -> { webWorker, image or mesh }

Read an image or mesh from an ArrayBuffer. fileName is a string with the file name. mimeType is an optional mime-type string.

writeArrayBuffer(webWorker, useCompression, imageOrMesh, fileName, mimeType) -> { webWorker, arrayBuffer }

Write an image or mesh to a an ArrayBuffer.

useCompression: compress the pixel data when possible
imageOrMesh: itk/Image or itk/Mesh instance to write
fileName: name that would be used for the resulting file
mimeType: optional mime-type for the resulting file


readImageFile(webWorker, file) -> { webWorker, image }

Read an image from a File.

readImageBlob(webWorker, blob, fileName, mimeType) -> { webWorker, image }

Read an image from a Blob. fileName is a string with the file name. mimeType is an optional mime-type string.

readImageArrayBuffer(webWorker, arrayBuffer, fileName, mimeType) -> { webWorker, image }

Read an image from an ArrayBuffer. fileName is a string with the file name. mimeType is an optional mime-type string.

readImageHTTP(url) -> image

Read a server-side generated image created with itk::JSONImageIO. The primary *.json file should be served at the given url and the pixel buffer file served at url + ".data"

readImageDICOMFileSeries(webWorker, fileList) -> { webWorker, image }

Read an image from a series of DICOM File‘s stored in an Array or FileList.

writeImageArrayBuffer(webWorker, useCompression, image, fileName, mimeType) -> { webWorker, arrayBuffer }

Write an image to a an ArrayBuffer.

useCompression: compress the pixel data when possible
image: itk/Image instance to write
fileName: name that would be used for the resulting file
mimeType: optional mime-type for the resulting file


readMeshFile(webWorker, file) -> { webWorker, mesh }

Read a mesh from a File.

readMeshBlob(webWorker, blob, fileName, mimeType) -> { webWorker, mesh }

Read an mesh from a Blob. fileName is a string with the file name. mimeType is an optional mime-type string.

readMeshArrayBuffer(webWorker, arrayBuffer, fileName, mimeType) -> { webWorker, mesh }

Read an mesh from an ArrayBuffer. fileName is a string with the file name. mimeType is an optional mime-type string.

writeMeshArrayBuffer(webWorker, useCompression, mesh, fileName, mimeType) -> { webWorker, arrayBuffer }

Write an mesh to a an ArrayBuffer.

useCompression: compress the pixel data when possible
mesh: itk/Mesh instance to write
fileName: name that would be used for the resulting file
mimeType: optional mime-type for the resulting file


readPolyDataFile(webWorker, file) -> { webWorker, polyData }

Read a vtk.js PolyData from a File.

readPolyDataBlob(webWorker, blob, fileName, mimeType) -> { webWorker, polyData }

Read a vtk.js PolyData from a Blob. fileName is a string with the file name. mimeType is an optional mime-type string.

readPolyDataArrayBuffer(webWorker, arrayBuffer, fileName, mimeType) -> { webWorker, polyData }

Read a vtk.js PolyData from an ArrayBuffer. fileName is a string with the file name. mimeType is an optional mime-type string.