phenotypic.measure.MeasureIntensity#
- class phenotypic.measure.MeasureIntensity(*args, **kwargs)[source]
Bases:
MeasureFeaturesMeasure grayscale intensity statistics of detected colonies.
Compute per-colony intensity metrics from the grayscale channel: integrated intensity, percentiles (min, Q1, median, Q3, max), standard deviation, coefficient of variation, and area-normalized density. These statistics reflect colony optical density, biomass accumulation, and internal heterogeneity.
- Returns:
pd.DataFrame: Object-level intensity statistics with columns:
Label, IntegratedIntensity, MinimumIntensity, MaximumIntensity, MeanIntensity, MedianIntensity.
LowerQuartileIntensity, UpperQuartileIntensity, InterquartileRangeIntensity.
StandardDeviationIntensity, CoefficientVarianceIntensity.
Density (integrated intensity / area), ConvexDensity (integrated intensity / convex area).
- Best For:
Tracking colony growth over time via integrated intensity as an optical-density proxy.
Detecting metabolically stressed or slow-growing colonies through low mean intensity.
Identifying sectored or chimeric colonies by high within-colony intensity variance.
Automated colony picking based on biomass thresholds.
- Consider Also:
MeasureSizefor lightweight area and integrated intensity without full statistics.MeasureColorfor multi-channel color statistics when pigmentation is relevant.MeasureTexturefor surface-roughness features that complement intensity metrics.
- See Also:
Tutorial 7: Measuring and Exporting for a walkthrough of measuring and exporting colony data. Measurement Metrics and Their Biological Meaning for interpreting intensity metrics in a biological context.
Category: INTENSITY# Name
Description
IntegratedIntensityThe sum of the object’s pixels
DensityThe ratio of the object’s intensity to the max possible intensity of the object
ConvexDensityThe ratio of the objects intensity to the max possible intensity of the object’s convex hull
MinimumIntensityThe minimum intensity of the object
MaximumIntensityThe maximum intensity of the object
MeanIntensityThe mean intensity of the object
MedianIntensityThe median intensity of the object
StandardDeviationIntensityThe standard deviation of the object
CoefficientVarianceIntensityThe coefficient of variation of the object
LowerQuartileIntensityThe lower quartile intensity of the object
UpperQuartileIntensityThe upper quartile intensity of the object
InterquartileRangeIntensityThe interquartile range of the object
Methods
__init__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):
Pass your processed Image (with detected objects) to measure()
The method calls your subclass’s _operate() implementation
Results are validated and returned as a pandas DataFrame
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', ...]