Skip to main content

napari-mlarray

PyPI Python Version Tests napari hub License

A napari reader and writer for MLArray (.mla) files that shows every image where it physically is, in the orientation radiologists expect.

pip install napari-mlarray            # into an existing napari installation
pip install "napari-mlarray[all]"     # with napari and Qt

Drag a .mla file into napari, or File > Open. To convert NIfTI, NRRD, MetaImage, MGH or DICOM to .mla, use MedVol: medvol convert ct.nii.gz ct.mla.

What you see

napari knows nothing about patient anatomy: a layer is an array plus an affine into "world" coordinates, and the 2-D canvas shows the last two world dims (down and right). napari-mlarray chooses the world so that the default camera gives the familiar picture, with no flips or rotations to fix by hand:

plane (viewer.dims.order) screen up screen right
axial (0, 1, 2) anterior patient left (radiological)
coronal (1, 0, 2) superior patient left (radiological)
sagittal (2, 0, 1) superior posterior
  • The world axes of a patient image point to I, P, L (labelled in napari's dims slider). This frame is right-handed, so the 3-D view is not mirrored. With the neurological convention they point to I, P, R (patient left on the screen's left) and the plugin flips the 3-D camera depth to keep 3-D unmirrored.
  • Every voxel is placed exactly from the file's geometry (spaces[0]): any storage order (axial, sagittal, coronal, flipped) gives the same picture, and images of different grids overlay correctly. The array is reordered for display only, never resampled, unless the grid is oblique (below).
  • World coordinates are millimetres. Convert the cursor position back to the file's patient coordinates (DICOM LPS) with napari_mlarray.letters_to_lps(viewer.dims.axis_labels[-3:]).T @ viewer.cursor.position[-3:].

This is verified on screen by scripts/verify_orientation.py (napari 0.10): a letter phantom stored axially, RAS-flipped, sagittally and obliquely gives the same, correct picture in all three planes and an unmirrored 3-D view, in both conventions. Other spaces work the same way: earth-observation spaces are shown north up and east right, spaces without direction words in reversed axis order (z, y, x), so an identity matrix shows the array as NumPy does.

Oblique images

napari cannot slice an affine that rotates the displayed axes against the slicing axis in 2-D (it drops the out-of-plane rotation). For grids that are oblique to the world axes, choose:

oblique effect
resample (default) resampled onto a world-aligned grid (linear for images, nearest neighbour for labels): exact positions
nearest axes snapped to the closest world axes, as ITK-SNAP and MRIcroGL do: upright, but positions are approximate
keep the exact affine: correct in 3-D, approximate in 2-D slices

Settings

import napari_mlarray

napari_mlarray.set_display(convention="neurological", oblique="nearest")   # for files opened from now on
layers = napari_mlarray.add_mlarray(viewer, "ct.mla", convention="radiological")   # one file, explicit options

or set NAPARI_MLARRAY_CONVENTION / NAPARI_MLARRAY_OBLIQUE before starting napari.

Layers

content of the file napari layer
values.kind measurement (and others) Image; values.scale/offset applied (e.g. Hounsfield units), contrast limits from ml statistics when present
values.kind label or instance Labels, with names, colours and codes of values.labels (shown when hovering)
a channel axis one Image layer per channel, named after the axis labels (ct [T1], ct [T2], ...)
time and other axes sliders; time is in its unit (start, step)
a 2-D grid in a 3-D space (a single DICOM slice) a one-slice volume at its position, so it overlays with volumes
profiles.ml.boxes (3-D) Labels layer of box outlines: every slice in every plane shows the box, and so does 3-D; hovering shows label and score
profiles.ml.boxes (2-D) Shapes rectangles with label and score

Boxes are drawn by napari-bboxes, which you can also use on its own for boxes from any source.

Files larger than 1 GiB are read slice by slice and stay on disk. Labels are always loaded, so you can paint.

Saving

File > Save Selected Layer(s) with a .mla name writes Image and Labels layers:

  • A layer opened from a .mla file is written in its original array order with all its metadata: axes, values and label table, profiles, user metadata, source headers and history (plus an edited entry). Value scaling applied for display is undone when that is exact. The geometry comes from the layer's current transform, so a layer you moved is saved where it is shown.
  • A new layer (for example labels you painted on an image) is written in the patient frame (LPS) when the viewer shows patient axes (I, P, L or I, P, R), so it lines up with the image in any other tool. Label names from the layer's features (index, name) become the label table.

Development

pip install -e . --group dev
pytest

The tests check every voxel's world position for axial, sagittal, flipped and RAS-stored grids in both conventions, oblique grids, labels, channels, time, single slices, boxes and save/load round trips. xvfb-run python scripts/verify_orientation.py OUTDIR checks the picture on screen.

License

Distributed under the terms of the MIT license.

Acknowledgments

    

This repository is developed and maintained by the Applied Computer Vision Lab (ACVL) of Helmholtz Imaging and the Division of Medical Image Computing at DKFZ.

Metadata

Release files for napari-mlarray 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for napari-mlarray 1.0.0
File Size Uploaded Provenance Actions
napari_mlarray-1.0.0.tar.gz 40.5 kB With provenance Details for napari_mlarray-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for napari-mlarray 1.0.0
File Interpreter ABI Platform Actions
napari_mlarray-1.0.0-py3-none-any.whl Python 3 none any Details for napari_mlarray-1.0.0-py3-none-any.whl

Total release size: 66.3 kB

Release files / napari_mlarray-1.0.0.tar.gz

Download URL napari_mlarray-1.0.0.tar.gz
Size 40.5 kB
Tags Source
SHA-256 checksum
How to use checksums
22471150c7f705e9530d11a966dc7cee59dacf5f2aa4fa23644bd7577770f400
BLAKE2b-256 checksum
How to use checksums
baadbca0a18c8221df2c3e4e10dddb2551f253f06f67cd36061c91ff6237e3ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / napari_mlarray-1.0.0-py3-none-any.whl

Download URL napari_mlarray-1.0.0-py3-none-any.whl
Size 25.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac69e5ae901fbb1dae470fbc4570a9cb0ac9b46efefeac3f3a2a27192970b67e
BLAKE2b-256 checksum
How to use checksums
276bbe7ef4dfa4bdfaddbb8da192d810c68ebf7b1a5b0c219d537c13004f9187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for napari-mlarray 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for napari_mlarray-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page