autoemx.core.em_runtime.particle_segmentation_models package

Loads the available segmentation models.

This module is responsible for loading segmentation model modules that follow a specific structure and provide a segment_particles() function. To add a new segmentation model, create a new Python file in the same directory as this script, and ensure the file contains a correctly defined segment_particles() function as described below.

### Adding New Segmentation Models

See segmentation_model_template.py for a detailed description of the required structure

  1. Create a new module: In this directory, create a new Python file named your_model_name.py

  2. Define `segment_particles()`: In your new module, define a function named segment_particles() that takes the following parameters: - frame_image (np.array): A grayscale image containing particles. - powder_meas_config (PowderMeasurementConfig): A configuration object with relevant parameters for segmentation (e.g., threshold values). - save_image (bool): An optional flag to save the masked image. - EM (EM_controller): An optional object for saving the segmented image.

    The function should return a binary mask where pixel values represent detected particles, or a label image (one integer per particle).

  3. Optional dependencies (e.g. torch): import them inside segment_particles(), never at the top of the module, so that the module always imports (ledgers recorded with the model stay loadable where it is not installed). Define is_available() -> bool (whether the dependencies are installed) and INSTALL_HINT (how to install them): only installed models are offered in the GUI, and using a model that is not installed raises an ImportError with the hint.

Modules whose name starts with ‘_’ are helpers, not models.

Created on Thu Oct 9 09:34:39 2025

@author: Andrea

autoemx.core.em_runtime.particle_segmentation_models.load_models()[source]

Loads all available segmentation model modules from the specified directory.

This function will iterate through all .py files in the directory, import them, and store them in the MODEL_REGISTRY for later use.

Returns:

module_names – A list of the names of the modules that have been successfully loaded.

Return type:

list

autoemx.core.em_runtime.particle_segmentation_models.is_model_available(model_name: str) → bool[source]

Whether the dependencies of a registered model are installed (models without is_available() are).

autoemx.core.em_runtime.particle_segmentation_models.available_models()[source]

Registered models whose dependencies are installed.

autoemx.core.em_runtime.particle_segmentation_models.install_hint(model_name: str) → str[source]

How to install the dependencies of a model (’’ if none given).

autoemx.core.em_runtime.particle_segmentation_models.require_model(model_name: str)[source]

The module of a model, or ImportError (with how to install it) if its dependencies are not installed.

Submodules