phenotypic.tools_.mixin package#

Mixin classes for PhenoTypic operations.

This subpackage provides reusable mixin classes that add specific capabilities to ImageOperation subclasses and other PhenoTypic components.

Available mixins: - FootprintMixin: Generate morphological footprints (structuring elements) - GridInferenceMixin: Infer grid structure from binary masks using peak detection - LazyWidgetMixin: Generate interactive Jupyter widgets for parameter tuning - ClipControlMixin: Control output clipping behavior in composite operations

class phenotypic.tools_.mixin.ClipControlMixin[source]#

Bases: object

Mixin for operations that need to control clipping behavior of inner operations.

Provides a method to create copies of ImageEnhancer or ImagePipeline instances with clipping disabled. This is useful for composite operations where an inner enhancer operates on non-normalized data (e.g., variance-stabilized values from the Generalized Anscombe Transform, typically in the range ~1-32).

The mixin uses duck typing to check for a clip attribute on operations. If an operation has clip=True, the _disable_clipping method will create a shallow copy with clip=False. This preserves the original operation unchanged while allowing the copy to operate without output clipping.

Example

Creating a clip-disabled copy of an enhancer:

>>> from phenotypic.tools_ import ClipControlMixin
>>> from phenotypic.enhance import BilateralDenoise
>>>
>>> enh = BilateralDenoise(sigma_spatial=5, clip=True)
>>> copied = ClipControlMixin._disable_clipping(enh)
>>> # Original unchanged, copy has clip=False
>>> enh.clip, copied.clip
(True, False)

Creating a clip-disabled copy of a pipeline:

>>> from phenotypic import ImagePipeline
>>> from phenotypic.enhance import GaussianBlur, BilateralDenoise
>>>
>>> pipeline = ImagePipeline([
...     GaussianBlur(sigma=1.0),
...     BilateralDenoise(sigma_spatial=5, clip=True)
... ])
>>> copied_pipe = ClipControlMixin._disable_clipping(pipeline)
>>> # Only BilateralDenoise has clip attribute, so only it is affected
>>> # _ops is a dict with operation names as keys
>>> list(copied_pipe._ops.values())[1].clip
False
class phenotypic.tools_.mixin.FootprintMixin[source]#

Bases: object

Provides a mixin for creating morphological footprints for image processing.

The FootprintMixin class contains a static utility method to generate structuring elements (footprints) used in various image processing tasks. This functionality is particularly helpful in the context of analyzing microbial colonies on solid media agar plates. Morphological footprints are used to highlight specific features in images, such as colony edges, shapes, or connectivity, and can assist in segmentation, noise reduction, and feature extraction.

None#
class phenotypic.tools_.mixin.GridInferenceMixin[source]#

Bases: object

Mixin providing grid inference capabilities from binary masks.

Provides static methods for inferring grid structure from colony patterns using peak detection on row/column projections. Used by detectors and refiners that work with gridded plate images (96-well, 384-well formats, pinned cultures).

All methods are static to support parallelization in pipeline operations.

This is an internal utility for advanced users creating custom grid-based operations. Most users should use RoundPeaksDetector for detection or GridAlignmentRefiner for post-detection refinement directly.

class phenotypic.tools_.mixin.LazyWidgetMixin[source]#

Bases: object

Mixin providing a lazy ipywidget interface.

This mixin allows ImageOperation classes to automatically generate a Jupyter widget interface for parameter tuning and visualization.

__getstate__()[source]#

Prepare the object for pickling by disposing of any widgets.

This ensures that UI components (which may contain unpickleable objects like input functions or thread locks) are cleaned up before serialization.

Note

This method modifies the object state by calling dispose_widgets(). Any active widgets will be detached from the object.

widget(image: Image | None = None, show: bool = False) Widget[source]#

Return (and optionally display) the root widget.

Parameters:
  • image (Image | None) – Optional image to visualize. If provided, visualization controls will be added to the widget.

  • show (bool) – Whether to display the widget immediately. Defaults to False.

Returns:

The root widget.

Return type:

ipywidgets.Widget

Raises:

ImportError – If ipywidgets or IPython are not installed.