cellmap_flow.dashboard.routes.finetune.instance_correction
HTTP handlers for instance-correction workflows.
Three routes:
POST
/api/viewer/create-instance-correction: seed or reattach a paintable annotation layer for a ROI (fresh-seed or reuse-existing modes)POST
/api/viewer/sync-instance-correction: snapshot the paintable zarr from MinIO to a local destinationPOST
/api/viewer/cc3d-relabel-annotation: split a fused label via 26-connectivity cc3d
The volumes are ordinary annotation volumes (type: annotation_volume),
registered under the id their MinIO bucket key names, so the periodic sync,
the pull before every mirror, session listing and the overlay handle them
like any other.
Attributes
Functions
Create or reattach a paintable annotation layer for a ROI. |
|
Snapshot a paintable instance-correction zarr from MinIO to a local |
|
Split a single label in a paintable instance-correction zarr via |
Module Contents
- cellmap_flow.dashboard.routes.finetune.instance_correction.logger
- cellmap_flow.dashboard.routes.finetune.instance_correction.create_instance_correction()
Create or reattach a paintable annotation layer for a ROI.
Two modes:
Fresh seed (default, reuse_existing=False): reads an instance zarr, computes a dilation shell around each instance as “confident background”, and writes a uint16 annotation zarr in cellmap-flow’s AffinityTargetTransform label scheme (0=unannotated, 1=background shell, 2+=instance IDs). Then serves via MinIO and wires a writable SegmentationLayer into the viewer.
Reuse existing (reuse_existing=True): skips the seeding step entirely and reattaches to an already-annotation-formatted zarr. Used by the multi-ROI workflow to load any dated snapshot as the current paintable layer without redoing the dilation/labeling pass. Either:
pass source_zarr_path to load from an explicit path (the preferred path for dated-snapshot workflows), or
omit source_zarr_path and the route falls back to the conventional <output_dir>/<roi_name>_annotation.zarr location.
The path must already exist and contain annotation/s0/; instance_zarr_path is ignored in this mode. Strokes MinIO already holds under the ROI’s bucket key are pulled into that zarr before it is mirrored, as for every annotation volume, so reattaching never drops unsaved edits; to start again from an older snapshot, give it a new roi_name.
The MinIO bucket object is always named <roi_name>_annotation.zarr regardless of the source path on disk. This keeps the bucket name stable across sessions so save / sync routes can always target the same bucket key without knowing which snapshot was loaded. The volume is registered as <roi_name>_annotation, the key without “.zarr”.
- POST body:
roi_name: str, required (short label, e.g. “roi3”) reuse_existing: bool, default False instance_zarr_path: str, required if reuse_existing=False source_zarr_path: str, optional (reuse_existing=True only)
explicit path to an existing annotation zarr
dilation_radius_voxels: int, default 5 (fresh-seed mode only) model_name: str, required if reuse_existing=False: the
model whose geometry the volume records
annotation_dtype: “uint16” (default) or “uint32” (fresh-seed only) output_dir: str, default = sibling/instance_corrections/
(required if reuse_existing=True without source_zarr_path)
layer_name: NG layer name, default “{roi_name}_annotation”
- Returns:
- {success, volume_id, zarr_path, minio_url, neuroglancer_url,
layer_name, reload_page, mode: “fresh_seed” or “reuse_existing”}
- cellmap_flow.dashboard.routes.finetune.instance_correction.sync_instance_correction()
Snapshot a paintable instance-correction zarr from MinIO to a local destination.
Copies the MinIO object that brush edits land in, metadata and all, to a zarr on disk: a dated snapshot for rollback or audit, or a copy to train from. The served volume itself is kept current by the periodic sync, like any annotation volume. Uses s3fs, not mc.
- POST body:
- zarr_path: str, required. The volume, e.g.
/…/instance_corrections/roi3_annotation.zarr, or the zarr_path create answered: the MinIO bucket key is that of the volume registered for it, else its basename.
- dst_path: str, optional. Where to write the copy: a .zarr in the
same directory as zarr_path, new or an existing zarr. Defaults to zarr_path. Prefer a fresh dated path (e.g. …/roi3_annotation_<ts>.zarr), which leaves the volume as it was to roll back to.
- Returns:
{success, zarr_path, dst_path, keys_copied, keys_skipped, bytes_copied}
- cellmap_flow.dashboard.routes.finetune.instance_correction.cc3d_relabel_annotation()
Split a single label in a paintable instance-correction zarr via 26-connectivity cc3d.
Typical workflow: the user has erased a thin bridge between two fused mitos in NG’s brush tool (still sharing target_label), then POSTs this route with that label. The server reads the MinIO-backed annotation/s0, snapshots it to a local DirectoryStore for rollback, runs cc3d on the target mask, keeps the largest component under target_label, and reassigns all smaller components to fresh unused instance IDs starting at max(existing) + 1. Then writes the full array back to MinIO. After the POST completes, the user must hard reload the NG tab to see the new split colors (NG does not auto- invalidate segmentation chunks on back-channel writes).
- POST body:
- zarr_path: str, required. Absolute path to the user-visible zarr,
as for sync-instance-correction.
target_label: int, required. The instance ID to split (must be >= 2). snapshot_dir: str, optional. Where to drop rollback snapshots: a
directory beside zarr_path. Defaults to <parent_of_zarr>/snapshots/.
- Returns:
- {success, zarr_path, target_label, n_components, kept_voxels,
splits: [{new_label, voxels}, …], snapshot_path, reload_hint: “hard reload NG tab to see split”}