spacr.object

Module Contents

spacr.object.merge_split_filter_masks(masks, intensity_images, settings, object_type, batch_filenames=None)[source]

Apply merge/split/filter operations directly to in-memory masks.

Skips work when no operation is enabled for object_type; otherwise processes each FOV serially so progress reporting stays in order.

Parameters:
  • masks – 2D/3D ndarray or iterable of 2D masks (one per FOV).

  • intensity_images – Matching intensity arrays for scoring merges/splits.

  • settings – Dict of pipeline settings; per-object-type suffixes control which operations run (e.g. <type>_perimeter_fraction, <type>_intensity_merge, <type>_min_area).

  • object_type – Label used to look up per-object settings ('cell', 'nucleus', 'pathogen', 'organelle').

  • batch_filenames – Optional per-FOV filenames used only for logging.

Returns:

Original masks unchanged when no operation is enabled, else a list of filtered mask arrays (one per FOV).

spacr.object.generate_cellpose_masks_sam(src, settings, object_type)[source]

Segment one object channel across all .npz batches under src using Cellpose-SAM.

Loads the cpsam pretrained model, iterates over each pre-batched .npz file, runs merge/split/filter on the resulting masks, optionally tracks timelapse objects, saves per-image .npy masks, and records per-object counts to the run’s SQLite database.

Parameters:
Returns:

None.

spacr.object.generate_cellpose_masks(src, settings, object_type)[source]

Segment one object channel across all .npz batches under src using a chosen Cellpose model.

Selects the model via spacr.utils._choose_model() (stock or custom), runs per-batch inference with the object-specific channel/threshold settings, applies spacr.utils._filter_cp_masks(), optionally tracks timelapse objects, and writes .npy masks plus per-object counts.

Parameters:
Returns:

None.

spacr.object.generate_organelle_masks_sam(src, settings, object_type)[source]

Generate organelle masks using one of several morphology-aware strategies.

Supported morphology modes and backends:

  • spots: punctate structures (lipid droplets, vesicles, peroxisomes) via otsu, adaptive, log, dog, cellpose.

  • network: filamentous/reticular structures (mitochondria, microtubules, ER tubules) via otsu, adaptive, ridge, hysteresis, cellpose, unet.

  • irregular: irregular-shaped organelles (Golgi, ER cisternae, lysosomes) via otsu, adaptive, cellpose.

  • ring: hollow/ring-shaped structures (endosomes, autophagosomes) via otsu, adaptive, dog, log, cellpose.

Parameters:
  • src – Path to the mask source directory containing .npz stacks.

  • settings – Configuration dict. Organelle-specific keys are prefixed with organelle_ and are documented in _set_organelle_defaults.

  • object_type – Object label (typically 'organelle'); drives the output folder name <object_type>_mask_stack.

Returns:

None. Masks are written as .npy files in <src>/<object_type>_mask_stack/.