Core

MedicalVolume

voxel.MedicalVolume

The class for medical images.

Numpy Routines

Numpy operations that are supported on MedicalVolumes.

voxel.numpy_routines.all_np

See numpy.all().

voxel.numpy_routines.amax

See numpy.amax().

voxel.numpy_routines.amin

See numpy.amin().

voxel.numpy_routines.any_np

See numpy.any().

voxel.numpy_routines.argmax

See numpy.argmax().

voxel.numpy_routines.argmin

See numpy.argmin().

voxel.numpy_routines.around

Round medical image pixel data (and optionally affine) to the given number of decimals.

voxel.numpy_routines.clip

Clip the values in the array.

voxel.numpy_routines.concatenate

Concatenate medical images.

voxel.numpy_routines.expand_dims

Expand across non-spatial dimensions.

voxel.numpy_routines.may_share_memory

Determine if two medical volumes may share memory.

voxel.numpy_routines.mean_np

See numpy.mean().

voxel.numpy_routines.nan_to_num

See numpy.nan_to_num().

voxel.numpy_routines.nanargmax

See numpy.nanargmax().

voxel.numpy_routines.nanargmin

See numpy.nanargmin().

voxel.numpy_routines.nanmax

See numpy.nanmax().

voxel.numpy_routines.nanmean

See numpy.nanmean().

voxel.numpy_routines.nanmin

See numpy.nanmin().

voxel.numpy_routines.nanstd

See numpy.nanstd().

voxel.numpy_routines.nansum

See numpy.nansum().

voxel.numpy_routines.ones_like

See numpy.ones_like().

voxel.numpy_routines.pad

Implementation of numpy.pad() for MedicalVolume.

voxel.numpy_routines.shares_memory

Determine if two medical volumes share memory.

voxel.numpy_routines.squeeze

Squeeze non-spatial dimensions.

voxel.numpy_routines.stack

Stack medical images across non-spatial dimensions.

voxel.numpy_routines.std

See numpy.std().

voxel.numpy_routines.sum_np

See numpy.sum().

voxel.numpy_routines.where

See numpy.where().

voxel.numpy_routines.zeros_like

See numpy.zeros_like().

Standard universal functions that act element-wise on the array are also supported. A (incomplete) list is shown below:

numpy.power

numpy.sign

numpy.remainder

numpy.mod

numpy.abs

numpy.log

numpy.exp

numpy.sqrt

numpy.square

numpy.reciprocal

numpy.sin

numpy.cos

numpy.tan

numpy.bitwise_and

numpy.bitwise_or

numpy.isfinite

numpy.isinf

numpy.isnan

numpy.floor

numpy.ceil

Image I/O

voxel.read

Read MedicalVolume(s) from file.

voxel.write

Write MedicalVolume to file.

voxel.NiftiReader

A class for reading NIfTI files.

voxel.NiftiWriter

A class for writing volumes in NIfTI format.

voxel.DicomReader

A class for reading DICOM files.

voxel.DicomWriter

A class for writing volumes in DICOM format.

voxel.HttpReader

A class for reading DICOMs from HTTP requests with DICOMweb support.

Image Orientation

Standardized orientation convention and utilities.

Medical image orientation convention is library and image format (DICOM, NIfTI, etc.) dependent and is often difficult to interpret. This makes it challenging to intelligently and rapidly reformat images.

We adopt a human readable orientation representation for the dimensions and define utilities to convert between different orientation formats from current libraries (Nibabel, PyDicom, ITK, etc).

Orientations are represented by string axis codes:

  • "LR": left to right; "RL": right to left

  • "PA": posterior to anterior; "AP": anterior to posterior

  • "IS": inferior to superior; "SI": superior to inferior

A MedicalVolume object with orientation ("SI", "AP", "LR") has an array where the first dimension spans superior -> inferior, the second dimension spans anterior -> posterior, and the third dimension spans left -> right. Voxel at (i,j,k) index (0,0,0) would be the (superior, anterior, left) corner.

In many cases, images are not acquired in the standard plane convention, but rather in a rotated frame. In this case, the orientations correspond to the closest axis the a particular dimension.

Two general conventions are followed:

  • All orientations are in patient voxel coordinates. Image data from (i, j, k) corresponds to the voxel at array position arr[i,j,k].

  • Left: corresponds to patient (not observer) left, right: corresponds to patient (not observer) right.

We adopt the RAS+ standard (as defined by NIfTI) for orienting our images. The + in RAS+ indicates that all directions point to the increasing direction. i.e. from -x to x:.

Image spacing, direction, and global origin are represented by a 4x4 affine matrix (\(A\)) and is identical to the nibabel affine matrix (see nibabel). The affine matrix converts pixel coordinates (i, j, k) into world (NIfTI) coordinates (x, y, z).

\[\begin{split}\begin{bmatrix} x\\y\\z\\1\end{bmatrix} = A \begin{bmatrix} i\\j\\k\\1\end{bmatrix}\end{split}\]

For example,

\[\begin{split}\begin{bmatrix} x\\y\\z\\1 \end{bmatrix} = \begin{bmatrix} 0 & 0 & 1.5 & -61.6697\\-0.3125 & 0 & 0 & 50.8516\\ 0 & -0.3125 & 0 & 88.5876\\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} i\\j\\k\\1\end{bmatrix}\end{split}\]

For details on how the affine matrix is used for reformatting see voxel.MedicalVolume.

voxel.orientation.to_affine

Convert orientation, spacing, and origin data into affine matrix.

voxel.orientation.get_transpose_inds

Get indices for reordering planes from curr_orientation to new_orientation.

voxel.orientation.get_flip_inds

Get indices to flip from curr_orientation to new_orientation.

voxel.orientation.orientation_nib_to_standard

Convert Nibabel orientation to the standard voxel orientation format.

voxel.orientation.orientation_standard_to_nib

Convert standard voxel orientation format to Nibabel orientation.

Device

voxel.Device

Device class.

voxel.get_device

Get Device from input array.

voxel.to_device

Move input to device.