autoemx.core.em_runtime.particle_segmentation_models.microSAM module

Particle segmentation with micro-sam (Segment Anything for Microscopy), each particle segmented on its own:

A. Archit et al., “Segment Anything for Microscopy”, Nature Methods 22, 579–591 (2025). https://doi.org/10.1038/s41592-024-02580-4, https://github.com/computational-cell-analytics/micro-sam

Automatic instance segmentation (AIS) of the frame with a micro-sam model (default vit_b_lm, fine-tuned for light microscopy, which separates touching objects well), then the filters of _instance_filters (substrate, occluded particles). The brightness threshold is not used.

micro-sam is MIT-licensed; its model weights (CC-BY-4.0, by A. Archit and C. Pape; vit_b_lm is BioImage.IO model “SAM LM Generalist (ViT-B)”) are downloaded from BioImage.IO on first use. Install (optional): python -m autoemx.utils.install_segmentation micro-sam (installs micro-sam without PyQt6, the GPL Qt binding of its napari plugin, not needed here).

Options (PowderMeasurementConfig.par_segmentation_params), with their defaults:

  • model_type: "vit_b_lm" (other micro-sam models, e.g. "vit_l_lm", "vit_b_em_organelles");

  • device: "auto" (micro-sam’s choice: CUDA, MPS or CPU), or "cpu", "cuda", "mps";

  • tile_shape, halo: tiled segmentation of large frames (e.g. [512, 512] and [64, 64]; default: whole frame);

  • the filter options of _instance_filters.FILTER_DEFAULTS (e.g. min_visible_fraction).

Created on Sat Oct 17 2026 @author: Andrea

autoemx.core.em_runtime.particle_segmentation_models.microSAM.is_available() → bool[source]

Whether micro-sam (and torch) is installed.

autoemx.core.em_runtime.particle_segmentation_models.microSAM.get_predictor_and_segmenter(model_type: str = 'vit_b_lm', device: str = 'auto', is_tiled: bool = False)[source]

The micro-sam predictor and AIS segmenter of a model (loaded once per process).

autoemx.core.em_runtime.particle_segmentation_models.microSAM.instance_labels(frame_image: ndarray, params: Dict[str, Any]) → ndarray[source]

Label image of the objects micro-sam finds in a greyscale frame.

autoemx.core.em_runtime.particle_segmentation_models.microSAM.segment_particles(frame_image: ndarray, powder_meas_config: PowderMeasurementConfig = None, save_image: bool = False, EM: EM_controller = None) → ndarray[source]

Label image of the particles of a frame segmented by micro-sam (int32, background 0, one label per particle).

Parameters:
  • frame_image (ndarray) – Greyscale frame image.

  • powder_meas_config (PowderMeasurementConfig, optional) – Its par_segmentation_params are the options of the model (see the module documentation).

  • save_image (bool, optional) – Save the label image as a mask through EM (default: False).

  • EM (EM_controller, optional) – Used to save the mask image.