Skip to content

dcm2niix

View as Markdown

NiiVue does not read DICOM directly. dcm2niix converts it to NIfTI, and @niivue/dcm2niix runs it as WebAssembly in the browser. It is a separate package: NiiVue loads the NIfTI it returns.

The demo converts a single-file enhanced DICOM T1w scan, a classic series of 120 slice files, or files you choose or drop on it. Nothing leaves your computer.

Install

Terminal window
npm install @niivue/dcm2niix

Convert and show

import { convert } from '@niivue/dcm2niix'
// <input id="dicomFolder" type="file" webkitdirectory multiple />
input.addEventListener('change', async () => {
// A nonzero exit still returns the series that converted.
const { series } = await convert(input.files)
await nv.loadVolumes([{ url: series[0].image }])
})

Each series carries its NIfTI image, its json sidecar and any bval/bvec. For a dropped folder, filesFromDataTransfer(e.dataTransfer.items) collects the files first; listSeries lists series without converting them.

dcm2niix groups files into series by folder. Files fetched one by one have no folder, so give each the same one through _webkitRelativePath, as the demo does:

const file = new File([bytes], name)
file._webkitRelativePath = `series/${name}`

Full control

The Dcm2niix class sets any dcm2niix flag:

import { Dcm2niix } from '@niivue/dcm2niix'
const dcm2niix = new Dcm2niix()
await dcm2niix.init()
const result = await dcm2niix.input(files).compressionLevel(9).bids('n').run()