phenotypic.measure.MeasureSize#

class phenotypic.measure.MeasureSize(*args, **kwargs)[source]

Bases: MeasureFeatures

Measure colony area and integrated intensity as lightweight size proxies.

Extract two fundamental size metrics per detected colony: pixel area (biomass extent) and integrated grayscale intensity (total brightness, a proxy for optical density). This is a convenience class for rapid size assessment without the overhead of full shape or intensity statistical analysis.

Returns:

pd.DataFrame: Object-level size measurements with columns:

  • Label: unique object identifier.

  • Area: number of pixels occupied by the colony.

  • IntegratedIntensity: sum of grayscale pixel values (proxy for biomass / optical density).

Best For:
  • Quick quality-control screening of colony size distributions.

  • Time-course growth tracking via area at successive time points.

  • Filtering colonies by minimum size to exclude debris or aborted growth before downstream measurement.

Consider Also:
  • MeasureShape for comprehensive morphological metrics (circularity, convex hull, Feret diameters).

  • MeasureIntensity for full intensity statistics (percentiles, variance, coefficient of variation).

  • MeasureGridSpread for detecting multi-object wells in arrayed assays.

See Also:

Tutorial 7: Measuring and Exporting for a walkthrough of measuring and exporting colony data. Measurement Metrics and Their Biological Meaning for interpreting size metrics in a biological context.

Category: SIZE#

Name

Description

Area

Total number of pixels occupied by the microbial colony.Larger areas typically indicate more robust growth or longer incubation times.

IntegratedIntensity

The sum of the object's grayscale pixels. Calculated as$sum{pixel values}*area$

Methods

__init__

measure

Execute the measurement operation on a detected-object image.

__del__()

Automatically stop tracemalloc when the object is deleted.

measure(image, include_meta=False)

Execute the measurement operation on a detected-object image.

This is the main public API method for extracting measurements. It handles: input validation, parameter extraction via introspection, calling the subclass-specific _operate() method, optional metadata merging, and exception handling.

How it works (for users):

  1. Pass your processed Image (with detected objects) to measure()

  2. The method calls your subclass’s _operate() implementation

  3. Results are validated and returned as a pandas DataFrame

  4. If include_meta=True, image metadata (filename, grid info) is merged in

How it works (for developers):

When you subclass MeasureFeatures, you only implement _operate(). This measure() method automatically:

  • Extracts __init__ parameters from your instance (introspection)

  • Passes matched parameters to _operate() as keyword arguments

  • Validates the Image has detected objects (objmap)

  • Wraps exceptions in OperationFailedError with context

  • Merges grid/object metadata if requested

Parameters:
  • image (Image) – A PhenoTypic Image object with detected objects (must have non-empty objmap from a prior detection operation).

  • include_meta (bool, optional) – If True, merge image metadata columns (filename, grid position, etc.) into the results DataFrame. Defaults to False.

Returns:

Measurement results with structure:

  • First column: OBJECT.LABEL (integer IDs from image.objmap[:])

  • Remaining columns: Measurement values (float, int, or string)

  • One row per detected object

If include_meta=True, additional metadata columns are prepended before OBJECT.LABEL (e.g., Filename, GridRow, GridCol).

Return type:

pd.DataFrame

Raises:

OperationFailedError – If _operate() raises any exception, it is caught and re-raised as OperationFailedError with details including the original exception type, message, image name, and operation class. This provides consistent error handling across all measurers.

Notes

  • This method is the main entry point; do not override in subclasses

  • Subclasses implement _operate() only, not this method

  • Automatic memory profiling is available via logging configuration

  • Image must have detected objects (image.objmap should be non-empty)

Examples

Basic measurement extraction:

>>> from phenotypic import Image
>>> from phenotypic.measure import MeasureSize
>>> from phenotypic.detect import OtsuDetector
>>> # Load and detect
>>> image = Image('plate.jpg')
>>> image = OtsuDetector().operate(image)
>>> # Extract measurements
>>> measurer = MeasureSize()
>>> df = measurer.measure(image)
>>> print(df.head())

Include metadata in measurements:

>>> # With image metadata (filename, grid info)
>>> df_with_meta = measurer.measure(image, include_meta=True)
>>> print(df_with_meta.columns)
# Output: ['Filename', 'GridRow', 'GridCol', 'OBJECT.LABEL',
#          'Area', 'IntegratedIntensity', ...]