phenotypic.enhance.ImageInverter#

class phenotypic.enhance.ImageInverter[source]

Bases: ImageEnhancer

Invert detect_mat pixel intensities (negate brightness).

Reverses the brightness scale so dark regions become bright and vice versa. For uint8 data the inversion is 255 - pixel; for floating-point data it is max_value - pixel. Use this when detectors expect colonies as bright regions but the source image has colonies as dark regions.

For algorithm details, see What Enhancement Actually Does.

Returns:

Input image with detect_mat intensity-inverted. rgb and gray are unchanged.

Return type:

Image

Best For:
  • Correcting inverted scan output from imaging systems that produce dark-on-bright colony images.

  • Preprocessing before detectors that expect bright colonies on dark backgrounds.

  • Plates where colony boundaries are defined by dark edges on a bright background.

Consider Also:
  • SetDetectMode when switching the detection channel (e.g., to red or green) would resolve the contrast issue.

  • UnsharpMask when the issue is low contrast rather than inverted polarity.

See also

Tutorial 3: Enhancing Before Detection for a visual walkthrough of enhancement pipelines on plate images.

Methods

__init__

Initialize the ImageInverter with no parameters.

apply

Applies the operation to an image, either in-place or on a copy.

widget

Return (and optionally display) the root widget.

__init__()[source]

Initialize the ImageInverter with no parameters.

__del__()

Automatically stop tracemalloc when the object is deleted.

__getstate__()

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.

apply(image, inplace=False)

Applies the operation to an image, either in-place or on a copy.

Parameters:
  • image (Image) – The arr image to apply the operation on.

  • inplace (bool) – If True, modifies the image in place; otherwise, operates on a copy of the image.

Returns:

The modified image after applying the operation.

Return type:

Image

widget(image: Image | None = None, show: bool = False) Widget

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.