gnome-nifti-preview

Display conventions

Orientation

The affine is nibabel’s “best affine”: the sform if sform_code > 0, otherwise the qform if qform_code > 0. World coordinates are NIfTI’s RAS+ (x towards the patient’s Right, y Anterior, z Superior).

For the neurological and radiological modes, each stored voxel axis is matched to its nearest world axis (nibabel.io_orientation) and the slice is a permutation/flip of the stored grid (oblique images are resampled, see below):

View Screen right Screen up Scroll up goes towards
Axial, neurological patient right (R) anterior (A) superior
Coronal, neurological patient right (R) superior (S) anterior
Axial / coronal, radiological patient left (L) as above as above
Sagittal (both modes) posterior (P), i.e. anterior on the left superior (S) right

The stored mode shows the raw voxel axes: first axis to the right, last displayed axis upwards (axial ≈ axes 0×1, coronal ≈ 0×2, sagittal ≈ 1×2).

Whatever the mode, the letters at the edges of each view are computed from the affine for the axis actually displayed, so a flipped or permuted file is never shown with misleading labels. The test suite checks this property with markers near the right, anterior and superior ends of a phantom stored in eight different orientations (reference/tests/test_orientation.py).

Intensities

The window is the 0.5th–99.5th percentile of the finite values of a deterministic strided sample of the volume shown (at most 1 M voxels), computed after scl_slope/scl_inter. When clearly non-zero voxels (|v| > 1e-6) are at least 5 % of the sample, only they are used, so that a large zero background does not pull the lower bound to zero; then exactly non-zero values; then all values. Grey levels are rint(255 · clip((v − low) / (high − low), 0, 1)), intensities are smoothed (bilinear) when magnified (see Magnification below).

Segmentations

A volume is a label map when it has identity scaling, integral non-negative values, at most 256 distinct non-zero labels (centre slices and sample) and piecewise-constant content (at most 30 % of horizontally adjacent foreground voxel pairs differ in the three centre slices). intent_code = NIFTI_INTENT_LABEL forces label mode.

A segmentation that looks like a FreeSurfer parcellation (aseg, aparc+aseg, aparc.a2009s+aseg, wmparc, SynthSeg…) is shown with FreeSurfer’s colours and names (FreeSurferColorLUT, see THIRD-PARTY-NOTICES): at least 3 labels, at least half of them in FreeSurfer’s table, and one of the structures a naive 1, 2, 3… labelling never reaches (41–54, 251–255, 1000 and above), MIQ’s rule; a tissue map 1/2/3 keeps the generic palette. Labels the table does not have, and every other segmentation, get a deterministic colour (golden-ratio hue up to 2^24, an integer bit mixer above that to preserve large identifiers, alternating saturation/brightness). A table of your own (FreeSurferColorLUT format, label-lut in the settings) gives the colours and names of your atlas. 0 is black; a binary mask is white. Label images are always magnified with nearest-neighbour filtering: colours are never blended. The L key switches between label colours and grayscale.

Pointing at a label shows its number, its name when a table has it, and its volume: the number of voxels of the volume shown with that label times the voxel volume (|det| of the affine), in cm³. The metadata panel lists every label of the volume with its colour, name and volume (collapsed under “Labels”). Spatial units missing from the header (xyzt_units = 0, common in segmentation outputs) are taken as millimetres; metres and microns are converted.

Unscaled integer labels retain all 64 bits, and unscaled float64 labels retain their stored precision, including on oblique nearest-voxel grids. Identifiers outside JavaScript’s exact integer range are transported as decimal strings and shown in full. Grayscale rendering still uses float32; two distinct large labels can therefore share a gray level when L switches off their colours. For scaled scalar data, the physical value is computed with float64 slope and intercept before conversion to float32 for display. This preserves finite physical values when large or small stored values are compensated by scaling.

Other formats

Every format is shown as NIfTI would show the same voxels in the same place: the affine maps voxels to RAS world coordinates in mm.

A sparse segmentation (labels that miss a plane through the centre) opens at the centre of its labels, and its thumbnail cuts through them. A thumbnail whose view would be a strip (an axial cut through a few coronal slices) shows the acquired plane instead. DICOM images are never taken for label maps (except segmentations, SEG), whatever their number of distinct values.

4D and higher

The preview opens on the first volume, and only it is read at first (for .nii.gz, the gzip stream is decompressed only up to the end of volume 0). A slider above the metadata panel scrubs through the volumes (also Shift + wheel on a view, comma / period, Home / End). Volumes are numbered from 0 over the dimensions after the third, in Fortran order (t for a 4D image); the time shown is the volume number times the repetition time (pixdim[4]) for a 4D series. Moving away from volume 0 in a .nii.gz starts a background decompression of the whole stream; the slider says how far it got, and the volume appears as soon as its bytes are there.

The window, the label detection and the range are those of the volume shown (a b=0 and a b=1000 volume of a diffusion series need different windows). Below the slider, the time course of the voxel under the pointer (else of the cursor) shows its value in every volume, at display precision; clicking or dragging on it shows that volume. When all the volumes do not fit in the image limit (max-image-mb), the backend decodes up to the volume asked and the time course stays incomplete.

Spectroscopy (NIfTI-MRS)

A complex image with intent_name “mrs_v…” or a NIfTI-MRS header extension (code 44, JSON) is a spectroscopy file: dimension 4 holds the time-domain signal (FID), dimensions 5 to 7 the coils, averages, dynamics…, and pixdim[4] is the dwell time.

Magnification

Intensities are smoothed when magnified, except when a voxel is larger than 6 screen pixels (spectroscopic imaging, fMRI): voxels then stay sharp. Label maps are never smoothed.