Skip to main content

Petri dish colony segmentation and morphometric analysis for fungal growth experiments

Project description

metrics-petri

PyPI PyPI - Python Version PyPI - License CI Docs

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
                                          โ”œโ”€โ”€ analysis_full.json
                                          โ”œโ”€โ”€ provenance.json
                                          โ”œโ”€โ”€ 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. metrics_petri/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 result tables, provenance, 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

# Use the actual outside diameter for non-standard dishes
metrics-petri input_images/ --dish-size-mm 60

# 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
โ”œโ”€โ”€ provenance.json           run settings, versions, device, and model checksum
โ”œโ”€โ”€ 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 and the configured outside dish diameter. The default is 90 mm; pass --dish-size-mm when using another size. No separate calibration target is required.


Diagnostics

metrics-petri doctor

Checks Python, NumPy, 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

MIT โ€” 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.1.2},
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.1.2.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.1.2-py3-none-any.whl (22.0 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for metrics_petri-2.1.2.tar.gz
Algorithm Hash digest
SHA256 0b8de20bcc7f6a2d96815892327d7d595d727cd2ccaac924df995c1650423a9c
MD5 902809102f089015343bb47e2a254702
BLAKE2b-256 1767863d3413b4c241c02d0c7fc14034389b570134284d340cd24c53176c9a58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: metrics_petri-2.1.2-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.13

File hashes

Hashes for metrics_petri-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9202ca70199d4451d8bc2efd11250da12f7172a4aedd5fccd0187dc9429364bc
MD5 48d1d5d5b5bab572f8b10b920b79e76b
BLAKE2b-256 3a54455166bcc72201c02f7f07b251df6651dc852b0cc25a83a648ab3b4bb4fb

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