Skip to content

Rendering ​

Static rendering is a first-class Python operation for notebooks, QA, debugging, analysis, and figures:

python
from microscope import Slide
with Slide('case.svs') as slide:
    image = slide.render(
        region=(12000, 8000, 2048, 2048),
        layers=['cells', 'tumor_mask'], size=(1600, 1600),
        annotations=True, output='figures/roi.png',
    )

No matplotlib setup is required. Return values are ordinary RGB PIL images suitable for notebook display(image). PNG, JPEG, WebP, and TIFF output are supported. Source ICC profiles are converted to sRGB when present; transparent slide pixels composite over white. Exports are fresh ordinary image files without WSI properties, associated images, or transform metadata embedded. The local output filename is caller-controlled.

The native adapter uses OpenSlide's primary image pyramid. Associated label/macro images are not accessed. ImageBackend is the replaceable protocol; supply a compatible backend instance to Slide(path, backend=...). It must expose dimensions, level dimensions/downsamples, properties, read_region, and close. A supplied backend is owned/closed by Slide.

Layer rendering preserves stack order, scalar palette interpolation, nearest raster sampling, polygon holes, GeoJSON point/line/polygon geometry, visibility, opacity, and annotation class/ROI styles. Binary masks use foreground color; label masks use repeating display colors, with transparent zero. Coordinate shapes remain in level-0 pixels; line widths and point radii are preview pixels.

Python output is a useful static interpretation, not pixel-for-pixel deck.gl parity. Scatter points, polygon/GeoJSON geometry, masks, probabilities, and editable annotations render directly. GridLayer counts use fixed slide-space bins. HeatmapLayer uses an approximate smoothed count density; ContourLayer uses threshold-bin outlines rather than GPU interpolated contours. These approximations are included in image.info['microscope']['warnings']. Synthetic browser preview recipes are skipped with warnings, not presented as model results.

Bounds: at most 8192 pixels per output axis, 16,777,216 output pixels, and 33,554,432 pixels per native decoder read. Default output fits inside 2048 pixels without enlarging the requested region. Choosing a larger export is explicit. Limits bound allocation, not total runtime: source assets remain bounded but load/validate in full, polygon queries/rendering scan geometry, and many overlapping shapes can be expensive. No spatial index, chunked source reader, or whole-slide publication atlas is implied.