Tutorial 8: Using Prefab Pipelines#

Building a pipeline from scratch gives you full control, but PhenoTypic also ships prefab pipelines — pre-configured ImagePipeline subclasses tuned for common organisms and plate types. In this tutorial you will survey the available prefabs, apply one, and compare results.

What you will learn:

  1. What prefab pipelines are and when to use them

  2. Survey the available prefabs

  3. Apply a prefab pipeline

  4. Compare results from different prefabs

Imports#

[1]:
from phenotypic.data import load_synth_yeast_plate

Available Prefab Pipelines#

Each prefab is an ImagePipeline subclass with operations and measurements already configured. Choose based on your organism and plate conditions.

Prefab

Best for

Strategy

HeavyOtsuPipeline

General-purpose yeast, clean plates

Multi-stage Otsu with refinement

HeavyWatershedPipeline

Touching or clustered colonies

Watershed segmentation

RoundPeaksPipeline

Round colonies, lightweight

Peak detection

HeavyRoundPeaksPipeline

Round colonies needing refinement

Extended peak detection

FilamentousFungiPipeline

Filamentous fungi (Neurospora, etc.)

BM3D denoise + specialized detector

GridSectionPipeline

Pre-tiled grid sections

Section-level processing

Apply HeavyOtsuPipeline#

Let’s start with the most general-purpose option — HeavyOtsuPipeline. It chains Gaussian blur, CLAHE, median filtering, Sobel edge enhancement, Otsu detection, and several refinement steps (morphological opening, border removal, small-object removal, mask fill).

[2]:
from phenotypic.prefab import HeavyOtsuPipeline

plate = load_synth_yeast_plate()
heavy_otsu = HeavyOtsuPipeline()
result_otsu = heavy_otsu.apply(plate)
result_otsu.dash(overlay=True)
PNG file does not have exif data.
[3]:
print(f"HeavyOtsuPipeline detected {result_otsu.num_objects} colonies")
HeavyOtsuPipeline detected 88 colonies

Apply RoundPeaksPipeline#

Now let’s try RoundPeaksPipeline — a lighter approach that uses peak detection to find circular colonies. It is faster but may miss irregular or faint colonies.

[4]:
from phenotypic.prefab import RoundPeaksPipeline

plate2 = load_synth_yeast_plate()
round_peaks = RoundPeaksPipeline()
result_rp = round_peaks.apply(plate2)
result_rp.dash(overlay=True)
PNG file does not have exif data.
[5]:
print(f"RoundPeaksPipeline detected {result_rp.num_objects} colonies")
RoundPeaksPipeline detected 88 colonies

Compare#

Different prefabs produce different results on the same plate. The best choice depends on your colonies, your imaging conditions, and what you need to measure. A quick visual comparison and colony count helps you decide.

[6]:
print(f"HeavyOtsuPipeline:   {result_otsu.num_objects} colonies")
print(f"RoundPeaksPipeline:  {result_rp.num_objects} colonies")
HeavyOtsuPipeline:   88 colonies
RoundPeaksPipeline:  88 colonies

Prefabs Include Measurements#

Prefab pipelines come with measurements pre-configured, so you can call .apply_and_measure() directly — no need to add your own meas list.

[7]:
plate3 = load_synth_yeast_plate()
df = heavy_otsu.apply_and_measure(plate3)
print(f"{len(df)} colonies measured across {df.shape[1]} features")
df.head()
PNG file does not have exif data.
/home/runner/work/PhenoTypic/PhenoTypic/.venv/lib/python3.12/site-packages/mahotas/morph.py:322: SyntaxWarning: invalid escape sequence '\s'
  with ``1``\s, while the ``0``\s line up with ``0``\s (``2``\s correspond to
/home/runner/work/PhenoTypic/PhenoTypic/.venv/lib/python3.12/site-packages/mahotas/features/texture.py:111: SyntaxWarning: invalid escape sequence '\|'
  Feature 10 (index 9) has two interpretations, as the variance of \|x-y\|
/home/runner/work/PhenoTypic/PhenoTypic/.venv/lib/python3.12/site-packages/mahotas/features/texture.py:223: SyntaxWarning: invalid escape sequence '\|'
  Feature 10 (index 9) has two interpretations, as the variance of \|x-y\|
88 colonies measured across 133 features
[7]:
Size_Area Size_IntegratedIntensity Size_Perimeter Size_ConvexArea Size_BboxArea Size_MajorAxisLength Size_MinorAxisLength Size_MinFeretDiameter Size_MaxFeretDiameter Size_InscribedRadius ... Bbox_MaxRR Bbox_MaxCC Bbox_IntensityWeightedCenterRR Bbox_IntensityWeightedCenterCC Bbox_DistWeightedCenterRR Bbox_DistWeightedCenterCC Grid_RowNum Grid_ColNum Grid_RowMajorIdx Grid_ColMajorIdx
0 2746.0 1999.503036 192.752309 2696.0 3480.0 59.729151 58.558136 57.000000 59.908263 28.861739 ... 96 705 65.577126 675.117063 65.687209 675.177970 0 9 9 72
1 2804.0 2025.865270 194.994949 2760.0 3600.0 60.055746 59.463745 58.689863 60.539243 29.274562 ... 98 153 67.158223 122.557819 67.191776 122.542560 0 1 1 8
2 2181.0 1550.900332 172.267027 2138.0 2756.0 53.152625 52.249089 51.000000 53.009433 25.632011 ... 91 275 63.812682 248.465178 63.866256 248.428227 0 3 3 24
3 2313.0 1648.472903 177.681241 2272.5 2970.0 54.744154 53.808546 53.000000 54.644304 26.627054 ... 92 583 64.928982 554.744857 64.973582 554.700651 0 7 7 56
4 2675.0 1965.160503 191.338095 2633.0 3364.0 58.544810 58.200860 57.000000 58.830264 28.284271 ... 97 90 66.665330 60.434904 66.841375 60.565583 0 0 0 0

5 rows × 133 columns

Summary#

Prefab pipelines are the fastest path from plate image to results:

  • ``HeavyOtsuPipeline`` — robust general-purpose detection with refinement

  • ``RoundPeaksPipeline`` — lightweight peak-based detection for round colonies

  • ``HeavyWatershedPipeline`` — for touching or clustered colonies

  • ``FilamentousFungiPipeline`` — specialized for branching fungal morphology

  • All prefabs support .apply(), .apply_and_measure(), .to_json(), etc.

Choose based on your organism, plate conditions, and desired accuracy. When a prefab is close but not quite right, use it as a starting point and customize the parameters.

Next up: Tutorial 9: Diagnosing Image Quality — assess plate quality before choosing a pipeline.