Skip to main content

Petri dish colony segmentation and morphometric analysis for fungal growth experiments

Project description

metrics-petri

Petri dish colony segmentation and morphometric analysis.

metrics-petri measures how a biological sample grows on a petri dish: area, diameter, edge roughness, crack burden, texture entropy, and time-series growth rates โ€” all in physical units calibrated from the dish geometry.


Workflow

  ๐Ÿ“ Image folder
       โ”‚
       โ–ผ
  metrics-petri-metadata          โ† optional but recommended
       Step 1 ยท select folder (dates auto-detected)
       Step 2 ยท experiment name ยท start date ยท plates
       Step 3 ยท review and assign day codes per image
       Step 4 ยท export
       โ”‚
       โ”‚ writes
       โ–ผ
  image_metadata.csv
       โ”‚ --metadata
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                               โ”‚
  ๐Ÿ“ Image folder โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ metrics-petri
                                               โ”‚
                                               โ–ผ
                                          results.zip
                                          โ”œโ”€โ”€ analysis_full.csv
                                          โ”œโ”€โ”€ overlays/
                                          โ””โ”€โ”€ charts/  โ† growth curves with day codes

metrics-petri-metadata is optional โ€” metrics-petri can run on images alone, but supplying metadata enables growth-rate calculations and day-coded charts.


Three entry points, one package

Entry point Install Use
metrics-petri pip install metrics-petri CLI batch pipeline
metrics-petri-metadata pip install metrics-petri Desktop GUI for building image_metadata.csv
metrics-petri-crop pip install metrics-petri CLI crop multi-dish images into per-dish PNGs

Model checkpoint

The package bundles the SmallUNet checkpoint (best_area_w_0.7.pt, ~23 MB) inside the wheel. No separate download is needed after pip install. The model was trained and validated using petrimodel โ€” a companion repository covering training, annotation, sweep evaluation, and manual diameter validation against model-generated masks.

At run time the checkpoint is located in this order:

  1. UNET_MODEL environment variable or --model flag
  2. models/best_area_w_0.7.pt in the current working directory
  3. The installed package location (bundled in the wheel)
  4. HuggingFace Hub auto-download (rotsl/grayleafspot-segmentation) as a last resort

CLI batch pipeline

python3.12 -m venv petrienv
source petrienv/bin/activate
pip install --upgrade pip
pip install metrics-petri
metrics-petri input_images/

Processes every image in the folder and writes a ZIP containing results, overlays, and charts.

# With metadata for growth rate calculations and day-code charts
metrics-petri input_images/ --metadata input_images/image_metadata.csv

# JSON metadata is also accepted
metrics-petri input_images/ --metadata input_images/image_metadata.json

# Custom output path
metrics-petri input_images/ --output results/run01.zip

# Adjust segmentation threshold (default 0.5)
metrics-petri input_images/ --threshold 0.45

# Custom model checkpoint
metrics-petri input_images/ --model /path/to/checkpoint.pt

Output ZIP

<user_or_experiment_name>.zip
โ”œโ”€โ”€ analysis_full.csv         one row per image, all metrics
โ”œโ”€โ”€ analysis_full.json        same data as a JSON array
โ”œโ”€โ”€ image_metadata.csv        copy of the input metadata (if supplied)
โ”œโ”€โ”€ image_metadata.json       same metadata as JSON
โ”œโ”€โ”€ overlays/                 per-image colony mask composites
โ””โ”€โ”€ charts/                   growth-rate charts (requires dates in metadata)

Metadata desktop GUI

metrics-petri-metadata is a native tkinter application for creating the image_metadata.csv that drives growth rate calculations and chart labelling.

Requirements: tkinter is part of the Python standard library.

  • macOS / Windows: bundled with the official Python installer.
  • Linux: sudo apt install python3-tk (or sudo dnf install python3-tkinter)
metrics-petri-metadata

Four-step flow:

  1. Select Folder โ€” browse to the image folder; dates are auto-detected from filenames, EXIF data, or file modification time.
  2. Settings โ€” enter experiment name, experiment start date, user name, and plate count.
  3. Review & Edit Dates โ€” a table lists every image with its date and day code (d01, d02, โ€ฆ); click any row to correct a date or set a reminder.
  4. Export โ€” writes image_metadata.csv, image_metadata.json, and optionally reminders.ics into the image folder.

Pass the exported file to the CLI with --metadata.


Dish cropper

metrics-petri-crop automatically detects and crops individual petri dishes from photos where several dishes were captured together in a single image (2โ€“8+ per photo). It is a standalone utility โ€” independent of the analysis pipeline.

metrics-petri-crop -i input_images/
Flag Description
-i, --input Image file or directory
-o, --output Output directory (default: <input>/cropped/)
-p, --padding Extra space around each dish (default: 0.05 = 5% of radius)
-d, --debug Save debug overlays showing detection circles
-D, --date Prefix output filenames: DD/MM/YYYY, DD/Mon, or DD Mon

Only fully visible dishes are extracted. Output filenames follow the pattern {stem}_dish_{NN}.png (or {YYYYMMDD}_{stem}_dish_{NN}.png with --date).


Measured metrics

Metric Unit Description
area_mm2 mmยฒ Colony area
diameter_mm mm Equivalent circle diameter
perimeter_mm mm Colony perimeter
eccentricity โ€” Shape elongation (0 = circle, 1 = line)
edge_roughness โ€” Perimeter / ideal-circle perimeter
centre_delta_mm mm Colony centroid offset from dish centre
entropy bits Shannon entropy of pixel intensities
texture_std โ€” Standard deviation of pixel intensities
crack_area_mm2 mmยฒ Crack area
crack_coverage_pct % Crack area as percentage of colony area
crack_count โ€” Number of discrete crack regions
hyph_frangi_mm mm Hyphal length (Frangi filter)
hyph_meijering_mm mm Hyphal length (Meijering filter)
hyph_hybrid_mm mm Hyphal length (hybrid filter)
rgr_per_day dayโปยน Relative growth rate (requires dates)
relative_growth_per_day mmยฒ dayโปยน Absolute area growth rate (requires dates)

Scale is derived from the detected dish circumference (default 90 mm). No calibration target required.


Diagnostics

metrics-petri doctor

Checks Python, NumPy (warns if 2.x), Torch, accelerator (MPS/CUDA/CPU), model path, and all dependencies. Exits with code 1 on any issue.


Notebook walkthrough

An interactive notebook is available in the GitHub repository at notebooks/example_metrics-petri.ipynb. It traces the full pipeline โ€” mask inference, dish detection, crack analysis, and growth metrics โ€” with inline plots at each step.

The notebook is not distributed with the pip package. Clone the repository to use it.


Requirements

  • Python โ‰ฅ 3.10
  • PyTorch โ‰ฅ 2.1 (CPU works; MPS used automatically on Apple Silicon)
  • tkinter โ€” stdlib, bundled on macOS/Windows; sudo apt install python3-tk on Linux

License

Apache 2.0 โ€” full text

Citation

@software{Rohan_R_Metrics_Petri_petri_2026,
author = {{Rohan R}},
title = {{Metrics Petri: petri dish colony segmentation and morphometric analysis}},
url = {https://github.com/rotsl/metrics-petri},
version = {2.0.0},
year = {2026}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metrics_petri-2.0.0.tar.gz (22.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metrics_petri-2.0.0-py3-none-any.whl (22.0 MB view details)

Uploaded Python 3

File details

Details for the file metrics_petri-2.0.0.tar.gz.

File metadata

  • Download URL: metrics_petri-2.0.0.tar.gz
  • Upload date:
  • Size: 22.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for metrics_petri-2.0.0.tar.gz
Algorithm Hash digest
SHA256 892383802bcc7550b7d637db0e77bc653ae926fa519133ac2bab03166a27ad1b
MD5 6a8324160299c1200c090e8704be8a5b
BLAKE2b-256 8cfe3472a4bb7124278eedb07e962786579a91e61e7ed320e69e33a3120436e4

See more details on using hashes here.

File details

Details for the file metrics_petri-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: metrics_petri-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for metrics_petri-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 293bcf86552b6ed8436409aa820f86f6d71cbf5c22447a208b7d6db18b69447b
MD5 e8d1cb3047cddbe14f904419fc41f535
BLAKE2b-256 31ea22feab55d9f4bc8aaea40972e13f01c0b86ebe6fe3167704557077a62846

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page