ABC Hierarchy Deep-Dive#
PhenoTypic’s operation system is built on a hierarchy of abstract base classes (ABCs). Understanding this hierarchy is essential for writing correct custom operations.
The Hierarchy#
ImageOperation (root ABC)
├── ImageEnhancer — modifies detect_mat
├── ImageCorrector — transforms the entire image
├── ObjectDetector — writes to objmask and objmap
│ └── ThresholdDetector — convenience base for threshold methods
│ └── GridObjectDetector — grid-aware detection
├── ObjectRefiner — cleans up objmask and objmap
├── MeasureFeatures — extracts features → DataFrame
│ └── GridMeasureFeatures — grid-aware measurements
└── PostMeasurement — transforms measurement DataFrames
What Each ABC Enforces#
ABC |
Must implement |
Reads |
Writes |
|---|---|---|---|
|
|
|
|
|
|
all |
all |
|
|
|
|
|
|
|
|
|
|
|
(returns DataFrame) |
The _operate() Contract#
Every operation implements a single method:
def _operate(self, image: Image) -> Image:
Input: An
ImageorGridImageinstanceOutput: The same image (possibly modified in place)
Parameters: Accessed via
self(set in__init__)
The base class handles:
Copying (when
inplace=False)GridImage preservation (grid state, nrows, ncols)
Serialization (parameters → JSON)
Benchmarking
Serialization#
Operations are serializable to JSON by default. The serializer captures
all __init__ parameters that are not prefixed with _. Ensure your
parameters are JSON-compatible types (int, float, str, list, dict, bool,
None).
Registration#
Custom operations are automatically discoverable by ImagePipeline
when they are importable. The pipeline’s from_json() method resolves
class names using Python’s import system.