A viewer for OME-Zarr images that draws on the GPU. The drawing, the tile cache and the
reading are Rust (the crate micro-glancer-core); Python gets a small API and a Qt widget
(the package micro-glancer). It is new (alpha): the API may still change.
pip install "micro-glancer[qt]" # the app window and the Qt widget
pip install micro-glancer # only the off-screen viewer (needs numpy alone)
pip install "micro-glancer[save]" # also: saving translations into NGFF 0.4 / 0.5 images
There are wheels for Windows (x64), macOS (Apple silicon and Intel) and Linux (x86_64 and aarch64), for Python 3.11 and newer. The viewer draws with the GPU through Vulkan, Metal or DX12. On a machine without a usable GPU it falls back to the system's software renderer (WARP on Windows, Mesa's lavapipe on Linux), which is slower but shows the same picture.
- Open an OME-Zarr image (NGFF 0.4, 0.5 or 0.6) from a folder, or from a
.zipor.ozxfile. - Pan and zoom smoothly. The viewer picks the resolution level that fits the zoom. While finer tiles are read in the background, coarser ones stand in, so the view never waits.
- See every channel at once, each in its own colour or colour map (viridis, magma, inferno, plasma, cividis, turbo, hot, gray), with its own contrast limits and gamma. Colours, labels and contrast windows come from the image's omero metadata when it has them. Contrast can also be taken from what is in view.
- Move through z and t. The image opens at omero's default z and t. The planes next to the current one are read ahead, so stepping is quick.
- Turn the view.
- Cut a volume (an image with z) by a plane at any angle: look along y or x (XZ, YZ), or turn the plane freely through the volume. Voxels show as they are (the nearest one), or smoothly between voxel centres (trilinear), per layer. Anisotropic voxels are placed by their physical size. z is shared by all layers: the plane cuts every volume where it is in the world.
- Linked views, switched on and off: the main view, its YZ and XZ companions (all three centred on the same point, a crosshair where the planes cross) and a projection of the whole volume, in quarters of the window.
- See a volume whole, turned freely like the plane: the maximum intensity projection along the view; the volume itself, composited front to back (brighter voxels more opaque, with an adjustable density); or surfaces where each channel reaches the middle of its contrast window or at a level of its own. The volume and the surfaces are lit from their gradients (shading can be switched off). Each channel has an opacity curve for the volume. Rays jump over bricks that cannot add to the picture, which makes sparse volumes much faster.
- See each channel's histogram (of what is in view, or of the whole plane or volume) and adjust on it: drag the contrast limits, the surface level and the points of the opacity curve.
- Open several images as layers in one view. They add up, each can be hidden or made fainter, and each can be moved and turned by hand, for example to line two images up before a registration tool refines it.
- Save a layer's transform into its image, without rewriting any pixel. NGFF 0.4 and 0.5 images take a shift only. NGFF 0.6 images take the whole transform, kept apart from the image's own placement (in a coordinate system called "aligned"). Reopening the image shows it where it was saved.
- Show an image's label images (its
labels/group) over it, as filled areas or outlines, each id in its own colour. Double-click a label to highlight it, or show only that one. Ids stay exact up to 64 bits. A label image moves with its image when the image is moved or turned, on flat planes and on planes at an angle through a volume. Label images are left out of projections. - See every image where it was acquired. Positions are read both ways files hold them: in an image's own translation (NGFF 0.4 and 0.5), or in the scene of the group that owns the images (NGFF 0.6, as eubi and ozp write wells, mosaics and multi-position acquisitions). A field, a tile or a series opened alone sits at its own position, and a label image sits where its image sits. A well, or a collection of series (the tiles of a mosaic, the views or positions of an acquisition), opens whole with each image at its position, and the image under the pointer is named. Images without positions are laid out side by side, and the viewer says so. In a whole well or collection, each image lands on the nearest pixel of the shared grid (at most half a pixel off); its own pixels are never resampled.
- Open an HCS plate whole: its wells on a grid, each well with every field at its position, or one field of each well (the same field in every well, chosen by number). Zoomed out it reads the fields' coarse levels (and averages coarser ones of its own when the fields have few), zoomed in only what is in view. The well and the field under the pointer are named. A 384-well plate of 28 fields per well (10,640 fields) opens in 4 s and is sharp 4 s later; one field per well opens in a fraction of a second.
- See a store's contents as a tree (
micro_glancer.tree, and the Contents panel): a plate's wells and fields, a well's fields, an image's label images, a collection's series. Double-click a well to show it on its plate (or to open it whole), a field or a series to open it, a label image to add it. - Read the values under the pointer, for every channel of every layer (for a label image, its id).
- Save the whole view (camera, layers with their images, transforms, planes and channels) as JSON and restore it later.
On slow sources (remote stores, slow codecs, and later other file formats) the viewer
reads coarser levels while the view moves and the finer ones once it stops. To see how
it behaves, set MICRO_GLANCER_SLOW_READS_MS to add that many milliseconds to every
tile read.
micro-glancer PATH [PATH ...]
opens the app (also python -m micro_glancer), with the images as layers; File > Open,
or dropping a folder or a .zip / .ozx on the window, adds more. The toolbar switches
the views (XY, XZ, YZ), linked views, the projection and what it shows, the volume's
density, shading and smooth sampling. The layers are on the left, the current layer's
channels with their histograms on the right, its planes (z, t) at the bottom, and
Help > Keys lists the keys.
Drag to pan, scroll to zoom at the pointer, press F to fit, and press Page Up or Page Down to move through z (with Shift: t). Shift + scroll turns the view; [ and ] turn it by 90 degrees, 0 turns it back.
For a volume, Alt + drag turns the plane through it, and 1, 2 and 3 look along z, y and x. Page Up and Page Down move the plane one voxel along the view, and I switches trilinear sampling on and off. M shows the projection instead of the plane; P shows it and cycles what it shows (maximum intensity, volume, surfaces); Shift + P switches shading; - and + make the volume thinner or denser. L switches linked views on and off (dragging, the wheel and Page Up / Page Down then act in the view under the pointer).
The panel on the right shows the current layer's channels: pick a channel, show or hide it, choose its colour map, and adjust it on its histogram. Drag the solid lines for the contrast limits; with surfaces shown, drag the dashed line for the surface level; with the volume shown, drag the opacity curve's points (double-click adds one, right-click removes one). "whole image" switches the histogram from the view to the whole plane or volume, and Auto takes the contrast from the view.
With several images, Tab picks the current layer. Ctrl + drag moves it, Ctrl + scroll turns it (1 degree a notch, with Shift 0.1), Ctrl + arrow keys nudge it by a pixel, Ctrl + 0 puts it back, Ctrl + Alt + drag tilts a volume, and Ctrl + S saves its transform into its image. Two one-channel images open in green and magenta. The status bar shows the current layer, its plane, level and transform, and the values under the pointer.
The Labels button under the layers lists the current image's label images that are not open yet; the one you pick opens right above its image and follows it. For a label layer, the panel on the right holds outlines, "only the selected id", the selected id and New colours instead of the histogram. Double-click a label in the view to select it (double-click the background or press Esc to clear it), and press O to switch outlines.
A plate opens whole with every field of each well at its position; the Planes panel's "field" shows one field of every well instead ("all" goes back). The Contents panel on the left lists the wells, fields, series and label images of the store opened last.
From Python:
from micro_glancer import Viewer
from micro_glancer.save import save_transform
v = Viewer.offscreen(1024, 768)
v.open("image.ome.zarr")
v.set_position("z", 10)
v.set_channel(0, color=(0.0, 1.0, 0.0), lo=100, hi=4000, gamma=0.8)
v.auto_contrast() # or: contrast from what is in view
v.settle() # wait until the view is sharp
rgba, width, height, stats = v.render_rgba()
print(v.pick(512, 384)) # the values under the centre
v.add("moving.ome.zarr") # a second layer, now the current one
v.set_channel(0, lut="magma")
v.rotate_layer(12.5) # turn it about its centre (degrees)
v.move_layer(40, -10) # move it (screen pixels)
print(v.transform_matrix()) # the NGFF affine over the image's axes
save_transform(v) # into moving.ome.zarr
state = v.view_state() # JSON
v.open("stack.ome.zarr") # a volume
v.set_orientation("xz") # look along y: x right, z down
v.turn(30, 20) # turn the plane through the volume (degrees)
v.set_interpolation("linear") # trilinear between voxel centres
v.step_depth(5) # move the plane 5 voxels along the view
print(v.pick(512, 384)["voxel"]) # the voxel (x, y, z) under the centre
v.mip = True # the projection along the view
v.projection = "volume" # or "mip", "iso"
v.density = 0.1 # the volume's opacity per voxel at full brightness
v.set_channel(0, opacity=[(0.2, 0.0), (0.6, 0.9)]) # the opacity curve over the window
v.set_channel(0, iso=5000) # the surface level (a stored value)
h = v.histogram(0, bins=256, whole=True) # counts and edges
v.linked = True # the plane, YZ, XZ and the projection in quarters
v.label_names() # ["cells", ...] from the image's labels/ group
v.add_label("cells") # above its image, following its transform
v.set_labels(outline=True, selected=42, only_selected=False, seed=3)
print(v.pick(512, 384)["layers"][1]["values"][0]["id"]) # the exact id
v.open("plate.ome.zarr") # a plate: its wells on a grid, every field at its place
print(v.plate()["wells"][:2]) # [{"name": "A1", "path": "A/1", "fields": [...]}, ...]
v.set_field(1) # field 1 of every well
v.set_field(None) # every field again
v.show_well("B3") # zoom onto a well
print(v.pick(512, 384)["well"]) # ("B3", "B/3/7"): the well and the field under the point
v.open("plate.ome.zarr/B/3") # a well alone: its fields at their positions (micrometres)
print(v.members()["names"]) # ["field 0", "field 1", ...]
print(v.pick(512, 384)["member"]) # ("field 7", "7")
v.open("tiles.ome.zarr") # a collection of series: each at its position
from micro_glancer import tree
tree("plate.ome.zarr") # {"kind": "plate", "children": [wells > fields]}eubi's Inspect page uses micro-glancer when it is installed in eubi's environment
(EUBI_VIEWER=classic, or Settings > Viewer, switches back to eubi's classic viewer): planes at any angle and the
3-D views, linked views, the histogram panel under eubi's channel panel, moving the image
and saving its transform, image positions (plates with every field, wells and
collections whole), and the Contents tree. Several images as layers are
left out there until layers are stable. The code on eubi's side is
eubi_bridge/qt_gui/widgets/gpu_viewer.py and viewers.py.
micro_glancer.panel.ChannelPanel (and its HistogramWidget) adjusts the channels of a
ViewerWidget's current layer.
In Qt, micro_glancer.qt.ViewerWidget shows the layers. It emits viewChanged when the
camera, a plane, a layer or the channels change, picked with the values under the
pointer, saved after a transform was saved, and failed when something fails.
On Windows and macOS the core draws straight into the widget's own native window, and
frames never pass through Python. On Linux, and wherever a native window is not
available, the core draws off-screen and Qt paints the frame. A machine without a GPU
uses the system's software renderer. Set MICRO_GLANCER_MODE=native or offscreen to
choose the mode.
micro-glancer has its own virtual environment in .venv (Python 3.12, PyQt6, numpy),
with micro-glancer installed in development mode: after a change to the Rust code,
maturin develop --release (run in this folder) builds it again into the same place,
and .venv\Scripts\micro-glancer PATH starts the app. To try it inside eubi with eubi's
own venv, nothing installed into it, run .\eubi-dev.ps1 [PATH]: it puts this folder's
python directory on PYTHONPATH and starts eubi-gui.
The core reads images through ome_zarr_pyramid's crate (ome-zarr-pyramid, a git
dependency pinned to a commit). To build against a local ozp checkout instead, add a
[patch] section to .cargo/config.toml (the form is in
crates/micro-glancer-core/Cargo.toml).
The wheels contain the Rust crates and C libraries listed, with their licences, in
THIRD_PARTY_LICENSES.txt. After a change to Cargo.lock, run
python scripts/third_party_licenses.py; CI checks that the file is current.
pytest tests # needs ome_zarr_pyramid to write the test images
python bench/harness.py DIR [IMAGE ...]
The harness measures, on a 3840 x 2160 target: the time until the view is sharp after opening, after a jump and after a step in z or t, and the frames per second of cached pan and zoom. For volumes also: the time until sharp after turning the plane through the volume, and the frames per second on the turned plane, cached and while turning on.
The tests write their images with ome-zarr-pyramid, which .venv does not hold: run
them from an environment that has it, with this folder's python directory (where the
development build puts the compiled module) on PYTHONPATH.
scratch/inspect_mv.py is eubi's Inspect page with micro-glancer in its Viewer tab (and
micro-glancer's histogram panel under eubi's channel panel), to try the viewer inside
eubi without changing eubi: run it with eubi's Python and PYTHONPATH set to this
folder's python directory and the eubi checkout.