itasc.cellpose.native_masks¶
Capture Cellpose-SAM native masks, Qt-free, for the standalone distro.
The app’s itasc.cellpose.cellpose_runner keeps only the probability /
flow maps (_, flows, _ = model.eval(...)) because the integrated pipeline
derives its labels from divergence maps + Ultrack. The independently-shipped
itasc-cellpose tool instead wants the labelled masks Cellpose computes and
the runner throws away — that is index 0 of model.eval.
This module re-runs the same eval loop but keeps the masks, producing a canonical
(T, Z, Y, X) label stack per channel. It reuses the runner’s model loading,
gamma correction and cancellation so the two paths stay consistent; it does not
touch the runner itself, so the app’s behaviour is unchanged.
Functions
|
Yield per-frame |
|
Stack per-z 2D label images into |
|
Native cell masks for a single 2D z-slice. |
|
Process a |
|
Native masks + sigmoid prob map + RGB flow for one 2D z-slice. |
|
Native nucleus masks for one frame. |
|
Process a |
|
Write |
- itasc.cellpose.native_masks.run_nucleus_masks_frame(frame, z, params)[source]¶
Native nucleus masks for one frame.
z is Noneruns full 3D over(Z, Y, X)and returns labels(Z, Y, X); an integerzruns 2D onframe[z]and returns labels(Y, X).- Return type:
- Parameters:
frame (ndarray)
z (int | None)
params (NucleusParams)
- itasc.cellpose.native_masks.run_cell_masks_frame(frame, z, params)[source]¶
Native cell masks for a single 2D z-slice. Returns labels
(Y, X).- Return type:
- Parameters:
frame (ndarray)
z (int)
params (CellParams)
- itasc.cellpose.native_masks.run_nucleus_masks_stack(stack, params, *, progress_cb=None, cancel_cb=None)[source]¶
Process a
(T, Z, Y, X)stack into a(T, Z, Y, X)label stack.params.do_3druns a coherent 3D segmentation per frame; otherwise each z-slice is segmented in 2D and the slices are stacked with frame-unique labels (seeoffset_slice_labels()).
- itasc.cellpose.native_masks.run_cell_masks_stack(stack, params, *, progress_cb=None, cancel_cb=None)[source]¶
Process a
(T, Z, Y, X)stack slice-by-slice into(T, Z, Y, X)labels.
- itasc.cellpose.native_masks.run_nucleus_maps_frame(frame, z, params)[source]¶
Native masks + sigmoid prob map + RGB flow for one 2D z-slice.
A single
model.evalpass yields(masks (Y, X) int32, prob (Y, X) float32, flow_rgb (Y, X, 3) uint8)— the labels plus the two intermediates (probability and flow) the standalone tool surfaces so Channel 1 can be tuned. The standalone anchor is always per-plane 2D, sozis an integer slice.
- itasc.cellpose.native_masks.iter_nucleus_maps_stack(stack, params, *, progress_cb=None, cancel_cb=None)[source]¶
Yield per-frame
(t, masks, prob, flow_rgb)so results stream into a viewer.For a
(T, Z, Y, X)input each yield carries one time-frame:masksandprobare(Z, Y, X)andflow_rgbis(Z, Y, X, 3)uint8, with per-frame-unique mask labels (offset_slice_labels()). Always per-plane 2D (the standalone anchor never runs do_3d). A caller can drop each frame into a napari layer as it arrives instead of waiting for the whole stack.
- itasc.cellpose.native_masks.write_masks(masks_tzyx, output_dir, channel)[source]¶
Write
{channel}_masks.tif(int32, axesTZYX); return its path.
- itasc.cellpose.native_masks.offset_slice_labels(slices)[source]¶
Stack per-z 2D label images into
(Z, Y, X)with frame-unique labels.Each 2D Cellpose run labels its objects from
1independently, so naively stacking would collide labels across z. We offset every slice’s non-zero labels by the running maximum so a frame’s labels are globally unique; the background0is preserved. For the common single-z case this is a no-op.