PostProcessors
Overview
The PostProcessor module defines a framework for applying various postprocessing operations to numpy.ndarray data, primarily used in image segmentation, classification, and data normalization workflows.
Base Class
- class PostProcessor
Abstract base class for all postprocessing methods.
- name()
Returns the class name.
- __call__(data, **kwargs)
Invokes the process() method.
- process(data, **kwargs)
Ensures data is a NumPy array and dispatches to _process.
- _process(data, **kwargs)
Abstract method to be implemented by subclasses.
- to_dict()
Serializes instance attributes to a dictionary.
- dtype
Returns the target NumPy dtype of the processed output.
- is_segmentation
Boolean indicating if output represents a segmentation map.
PostProcessor Subclasses
DefaultPostprocessor
- class DefaultPostprocessor(clip_min=-1.0, clip_max=1.0, bias=1.0, multiplier=127.5)
Clips, biases, and scales the data. Converts to uint8.
clip_min: Minimum clipping value
clip_max: Maximum clipping value
bias: Value added after clipping
multiplier: Scaling factor
ThresholdPostprocessor
- class ThresholdPostprocessor(threshold=0.5)
Applies a threshold to binarize data. Produces uint8 output.
threshold: Threshold for binarization
ArgmaxPostprocessor
- class ArgmaxPostprocessor(threshold=None, ids=None)
One channel of label ids from a model’s channels of scores, for a model whose channels are classes that exclude
each other (one softmax over them) or sigmoids that do not overlap: each voxel’s id is the index of its
highest-scoring channel plus 1 (or that channel’s id in ids), so the dashboard draws one segmentation layer
and blockwise writes one label volume. Put a ChannelSelection ahead of it to choose which channels compete; the
ids then count in its order. A tie goes to the lowest channel. A NaN never wins, and a voxel that is NaN in
every channel is 0. The ids are uint8 for up to 255 channels, else uint16; with ids, the smallest of
uint8, uint16 and uint32 that holds them. Each voxel is its own, so it runs per chunk, in the
browser too. A blockwise task writes the ids as one output, which its output_channels names as a mapping
(output_channels: {classes: 0}): left out, it would write one output per model channel, and the chain leaves
only one.
threshold: voxels whose highest score is below it are 0, background; without one (
None, the default) every voxel gets its best channel’s idids: the label id each channel it is given gets, in channel order (after any ChannelSelection), one per channel, as a list or comma- or space-separated (
"50,51,37","50 51 37"); for a model’s classes as a dataset numbers them, e.g. 12 class channels asids: 50,51,37,40,41,42,43,44,49,55,2,1. An id of 0 makes its channel background too; ids must be 0 or more. A count that is not the channels’ is refused when the dashboard applies the chain, if it can tell how many reach the step (the model’s, as its server reports them, or a ChannelSelection’s ahead of it), and fails each chunk otherwise.None(the default) numbers the channels from 1
LabelPostprocessor
- class LabelPostprocessor(channel=0, connectivity=1, min_size=0, per_slice=False)
Labels the connected objects of a selected channel (post.segment.connected_components),
an id per object, within the chunk. connectivity is which neighbours touch: 1 faces only
(the default, as scipy.ndimage.label), 2 faces and edges, 3 corners too. Objects of fewer
than min_size voxels become background. per_slice labels each z slice on its own, for
2D models. Ids are unique within a chunk; follow it with MortonSegmentationRelabeling for ids
unique across chunks.
CellposeMasksPostprocessor
- class CellposeMasksPostprocessor(flow_threshold=0.4, cellprob_threshold=0.0, min_size=15, stitch_threshold=0.0, niter=200)
Cellpose’s masks, made from a Cellpose model’s output: flows (channels flow_y, flow_x, cell) by
following each pixel’s flow, as Cellpose does, slice by slice; stitch_threshold above 0 joins
objects across slices by IoU. Put it first in the chain, on a Cellpose server (it needs Cellpose).
Unlike output: masks, its thresholds can be changed from the dashboard without restarting the
model; it sees each chunk without the context the server’s own masks are followed over, so objects
at chunk edges can differ. Ids are unique within the chunk: follow it with
MortonSegmentationRelabeling.
MortonSegmentationRelabeling
- class MortonSegmentationRelabeling(channel=0)
Relabels segmentation data using Morton-order encoding to ensure chunk-wise uniqueness.
channel: Channel to operate on
Uses pymorton.interleave for chunk-based ID uniqueness
AffinityPostprocessor
- class AffinityPostprocessor(bias=0.5, neighborhood=...)
Uses multi-scale watershed (mwatershed) to generate segmentations from affinity graphs.
bias: the affinity above which neighbours join (0.5 by default, the midpoint of a sigmoid’s probabilities)
neighborhood: List of offset vectors for affinity connectivity
SimpleBlockwiseMerger
- class SimpleBlockwiseMerger(channel=0, face_erosion_iterations=0)
Merges chunk boundaries using edge voxel consistency and neuroglancer.equivalence_map.
face_erosion_iterations: Controls erosion on boundary faces before merge
Maintains a dictionary of voxel ID equivalences between chunks
ChannelSelection
- class ChannelSelection(channels='0')
Selects a subset of channels from the input array.
channels: Comma-separated list of channel indices (e.g., “0,1,2”)
LambdaPostprocessor
- class LambdaPostprocessor(expression)
Applies a user-defined lambda expression to each data point.
expression: A numpy expression in x (e.g., “x * 2”, “np.clip(x, 0, 1)”). Arithmetic, comparisons, indexing, abs, whitelisted np.* functions and dtypes, and a few array methods such as astype and clip are allowed, with the keyword arguments axis, keepdims, dtype, a_min and a_max. Anything else, including repeating a list ([x] * n), is rejected, because expressions arrive in layer URLs.