Monocle - a Python interface to the Monocle viewer
monocle is a Python interface to Monocle, a browser-based radiology viewer for
interacting with 3D medical data. It targets clinical, multimodal imaging as well
as research-related viewing requirements. Load a study from Python (or the command
line), and monocle emits a self-contained HTML page and opens it in the browser.
pip install monocle-viewer
Command line
Pip installs a monocle console command that opens the viewer on files
from the shell:
monocle t1.nii.gz t2.nii.gz # positional image arguments
monocle t1.nii.gz -s tumor.nii.gz # image + segmentation
monocle t1.nii.gz -m pial.surf # image + mesh
monocle -i t1.nii.gz -i t2.nii.gz # -i is the explicit image flag
monocle t1.nii.gz --html scan.html # write a shareable file (no browser)
Positionals are images; -i/--image adds more; -s/--seg adds segmentation
label masks; -m/--mesh adds triangular meshes. Without --html it opens the
browser via the one-shot local server.
The Monocle python builder
For per-volume display options and session-wide viewing config within python,
use the builder class. Monocle(...) sets session config, each .image(...)
adds a scan:
import monocle
m = monocle.Monocle(title='Patient 123')
t1 = m.image(t1, name='T1')
m.image(flair, name='FLAIR')
m.segmentation(label, name='Tumor', apply=t1)
m.mesh(surface, name='Cortex', apply=t1)
m.show() # open in browser (no file, see below)
m.write('scan.html') # write a persistent file
html = m.html() # or get the HTML string
.image(...) returns the added image, and .segmentation(apply=...)
takes one (or a list) to open with the mask already overlaid on those
images' panels — or apply=True to overlay every populated panel.
The return values are session references rather than replacements for the objects supplied by nibabel, voxel, or surfa:
image: monocle.ImageHandle = m.image(t1)
annotation: monocle.AnnotationHandle = m.segmentation(mask, apply=image)
.image(...) and .segmentation(...) accept a range of sources and handle
the conversion:
voxelvolumesnibabelimagestorchtensorsnumpyarrays- File paths
Segmentation label metadata is passed through to the viewer automatically when
an in-memory volumes have a populated .labels lookup. You can override it,
or provide labels for an array or file source, with labels=:
m.segmentation(
mask,
labels={
0: 'background', # omitted from the viewer label table
1: 'tumor',
2: ('edema', (255, 128, 0)), # RGB can be 0..255
3: ('necrosis', (0.8, 0.1, 0.2)), # or 0..1
},
)
.mesh(...) accepts voxel/trimesh objects, (vertices, faces) pairs, OBJ/STL/PLY
paths, and FreeSurfer meshes. Mesh vertices must use world / scanner-RAS coordinates.
Convenience methods
monocle.show(sources, ...) is a one-liner for a quick look. It builds a Monocle
instance, adds each source (with optional names= and affine=), and serves the
page in the browser. Session config kwargs (title=, mode=, …) pass straight through.
monocle.show(t1, flair, names=['T1', 'FLAIR'], title='Patient 123')
Payload interoperability
The payload adapters are available when a backend needs Monocle's normalized transfer representation directly:
payload = monocle.as_voxel_payload(nib_image)
mesh_payload = monocle.as_mesh_payload((vertices, faces))
monocle.decode_voxel_payload(entry, data) performs the inverse operation for
a voxel manifest entry and its raw byte block. Payloads contain geometry and
binary data only; display settings and annotation relationships live on the
session handles.
If you work with voxel Volumes, they carry a built-in volume.show() that
visualizes the scan through monocle directly — monocle ships with voxel by
default, so there's nothing extra to install.
The embedded viewer bundle
Offline mode (the default, inline=True) pastes the viewer's UMD bundle into
the HTML so the file works from file:// with no network. That bundle ships as
package data at monocle/static/monocle.umd.js.
License
Monocle is free for noncommercial use and distribution, and for internal use by commercial organizations. Commercial distribution or use in a customer-facing product or service requires a separate commercial license. See LICENSE for the complete terms.
Metadata
Release files for monocle-viewer 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| monocle_viewer-0.2.0.tar.gz | 621.2 kB | Without provenance | Details for monocle_viewer-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| monocle_viewer-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for monocle_viewer-0.2.0-py3-none-any.whl |
Total release size: 1.2 MB
Release files / monocle_viewer-0.2.0.tar.gz
| Download URL | monocle_viewer-0.2.0.tar.gz |
|---|---|
| Size | 621.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a253379bbe83b5dd7bd3f24addfba9180dc6a07638501e570dd5acda65cec9d0
|
|
BLAKE2b-256 checksum How to use checksums |
fbc911f8c8dfb03ba2130d1c3f41645f4d740ae5ae5796462d66d5895938d9ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / monocle_viewer-0.2.0-py3-none-any.whl
| Download URL | monocle_viewer-0.2.0-py3-none-any.whl |
|---|---|
| Size | 622.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9447baf5818d4491af3b62f1a47d39a443c711580b4374fc576d0a412e7f2bb6
|
|
BLAKE2b-256 checksum How to use checksums |
85ea796c336916c006b9e3f52ba806c6217b488b06a1eb3c1d2b8895b1a71852
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for monocle-viewer 0.2.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.