npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@niivue/dicom-loader

v1.0.0

Published

a module to load DICOM files into a format that can be used by niivue

Readme

@niivue/dicom-loader

A minimal TypeScript/JavaScript utility for converting DICOM files to NIfTI format in the browser, using @niivue/dcm2niix.

Features

  • Converts one or more DICOM files into .nii or .nii.gz
  • Returns NIfTI files as ArrayBuffers, ready for further processing (e.g., display with Niivue)
  • Lightweight and browser-friendly

Installation

npm install @niivue/dicom-loader

This automatically installs the @niivue/dcm2niix dependency.

Usage


import { dicomLoader } from '@niivue/dicom-loader';

// Suppose you have a file input in the browser
const fileInput = document.getElementById('dicomInput') as HTMLInputElement

fileInput.addEventListener('change', async () => {
  if (!fileInput.files) return

  const files = Array.from(fileInput.files) // An array of `File` objects

  // Call dicomLoader with an array of Files (or DicomInput objects)
  const loadedFiles = await dicomLoader(files)
  // NOTE: loadedFiles ArrayBuffer data will be in NIFTI format (due to using dcm2niix under the hood)

  // `loadedFiles` is an array of objects: { name: string, data: ArrayBuffer }
  console.log('loaded files:', loadedFiles)
})

You can also pass an array of DicomInput objects (with { name: string; data: ArrayBuffer }), which will be converted internally to File objects before processing.

Usage in NiiVue

import { dicomLoader } from "@niivue/dicom-loader"
import { Niivue } from "@niivue/niivue"

const nv = new Niivue()

nv.useDicomLoader({
    loader: dicomLoader
})

nv.loadDicoms([
    // dicom manifest example
    { url: "../tests/images/dicom/niivue-manifest.txt", isManifest: true},
    // single file example (enhanced dicom)
    // { url: "../demos/images/enh.dcm"}
])

// NOTE: if you register the dicomLoader with Niivue, drag and drop of dicom folders is supported out of the box. Just drop a folder onto the canvas

NiiVue drag and drop

It may be useful to use the callback in NiiVue when handling multiple returned images from the dicomLoader

// Import libs if needed
// 
// import { dicomLoader } from "@niivue/dicom-loader"
// import { Niivue } from "@niivue/niivue"

const myDicomLoaderHandler = async (images) => {
    // images is and Array of NVImage (e.g. NVImage[])
    // demonstration of how a user could choose which volume to add
    const choice = window.prompt(
        images
        .map((image, index) => `${index}: ${image.name}`)
        .join("\n"),
        "0"
    )

    if (choice === null) {
        return
    }
    const imageIndex = parseInt(choice)
    if (isNaN(imageIndex)) {
        return
    }
    if (imageIndex < 0 || imageIndex >= images.length) {
        return
    }

    // add the volume and show it in the NiiVue canvas
    nv.addVolume(images[imageIndex])
}

const nv = new Niivue({
    onDicomLoaderFinishedWithImages: myDicomLoaderHandler
})

Setup

You may need to ensure that your module bundler and build system handles the @niivue/dcm2niix WASM and WebWorker dependency correctly.

Vite example

Add the following lines to vite.config.js

// ... snip ...
optimizeDeps: {
    exclude: ['@niivue/dcm2niix']
  },
  worker: {
    format: 'es'
  }
// ... snip ...

API

dicomLoader(data: Array<File | DicomInput>): Promise<ConvertedFile[]>
  • data: An array containing either:
    • Browser File objects
    • Or objects with { name: string; data: ArrayBuffer }
  • returns: A Promise resolving to an array of { name: string; data: ArrayBuffer }, where data is a NIfTI file ArrayBuffer.

License

BSD-2-Clause