Software

neuroimjs

npm

Volumetric neuroimaging data, NIfTI I/O, spatial transforms and WebGL orthogonal slice viewers in JavaScript

Installnpm install neuroimjs

Sagittal, coronal and axial views of the MNI152 template with a thresholded simulated statistic map: positive values in red-orange, negative in blue

A simulated statistic map on the MNI152 template, drawn by neuroimjs 0.6.0 as three SingleSliceViewer views linked by ViewSynchronizer (demo/hero.js in the showcase source).

Classes NeuroSpace · NeuroVol · NeuroVec · ROIVol

Input / output NIfTI-1/2 read in the browser and Node (qform-only NIfTI-2 not yet); NIfTI-1 write in Node

Viewers Orthogonal and single-slice views, drawn with WebGL through PIXI.js

Analysis building blocks Group statistics, searchlights, ROIs, filtering

Try it

Still image of the interactive viewer: axial, coronal and sagittal views of the template with the statistic map, crosshair on a positive cluster

The same template and statistic map, in a SimpleOrthogonalViewer. Click a view to move the crosshair in all three; the line below the viewer reports its position in millimetres and the z value there. The mouse wheel steps through slices and is captured while the pointer is over a view, so the page does not scroll there; Ctrl/⌘ + wheel zooms, double-click resets the zoom, and ← / → step slices in the view the pointer last entered. On a phone, tap a view to move the crosshair; the viewer is best on a wider screen.

Loading it downloads 1.5 MB: 0.9 MB of JavaScript (the neuroimjs 0.6.0 browser bundle, which includes PIXI.js, MobX and Lit, and the 2 KB loader) and 0.5 MB of NIfTI data.

Works with

NeuroSpace, NeuroVol, NeuroVec, ROIVol and the searchlight iterators play the same roles in both libraries, and neuroimjs’s design notes treat neuroim2 as its R counterpart. Functions are renamed to camel case: read_vol → readVol, read_vec → readVec, grid_to_coord → gridToCoord; class names are unchanged. The statistic map on this page was written by neuroim2 and read by neuroimjs. Differences that matter when moving between them:

  • Grid indices are 0-based. gridToCoord([0, 0, 0]) is neuroim2’s grid_to_coord(sp, c(1, 1, 1)); add 1 to a neuroimjs index to get the R index.
  • readVec() is time-first. It returns [T, X, Y, Z] data, and its 3D geometry is on vec.volumeSpace; neuroim2 uses c(x, y, z, t).
  • Transform choice. When a file’s qform code exceeds its sform code, neuroimjs uses the qform where neuroim2 uses the sform; when a file has neither transform, neuroimjs uses diag(pixdim) where neuroim2 uses a centred, x-flipped affine.

Using it

Browser applications import everything from the self-contained neuroimjs/browser entry: viewers, layers, colormaps and readNiftiArrayBuffer(). Node code imports from neuroimjs, which adds readVol(), readVec(), writeVol() and the processing classes. The library is pre-1.0; the stability matrix lists the status of each module.

import { readNiftiArrayBuffer, SimpleOrthogonalViewer }
  from 'neuroimjs/browser';

Every figure on this page is rendered by neuroimjs 0.6.0 in headless Chromium by software/showcase/neuroimjs/make-figures.mjs in the site’s source, and the code shown with each figure is the code that drew it. make-data.R in the same folder writes the two NIfTI files with neuroim2. Template: MNI152NLin2009cAsym (Fonov et al., 2009, 2011; © 1993–2009 Louis Collins, McConnell Brain Imaging Centre, Montreal Neurological Institute, McGill University), via TemplateFlow; licence.