{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial 2: Detecting Colonies\n", "\n", "In [Tutorial 1](01_your_first_plate_image.ipynb), you loaded a plate image and\n", "explored its accessors. Now let's put that plate to work — we'll detect the\n", "individual *Rhodotorula* colonies using PhenoTypic's `OtsuDetector`.\n", "\n", "**What you will learn:**\n", "\n", "1. Create an `OtsuDetector` and apply it to a plate image\n", "2. View the binary mask (`objmask`) and labeled object map (`objmap`)\n", "3. View the detection overlay on the original plate\n", "4. Count detected colonies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from phenotypic.data import load_yeast_plate\n", "from phenotypic.detect import OtsuDetector" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load the Plate\n", "\n", "Let's load our *Rhodotorula* yeast plate — the same one from Tutorial 1." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plate = load_yeast_plate()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can see the colonies as pigmented spots arranged in the 96-well grid.\n", "Our goal is to have PhenoTypic find each one automatically." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create and Apply a Detector\n", "\n", "`OtsuDetector` finds a single intensity threshold that best separates colony\n", "pixels from background. It works by minimizing the variance within each group\n", "(colonies vs. agar), which makes it effective when the two populations have\n", "distinct brightness levels.\n", "\n", "Creating and applying a detector takes two lines:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector = OtsuDetector()\n", "plate = detector.apply(plate)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That's it! The detector read from `detect_mat`, computed a threshold, and\n", "wrote the results into two new accessors on the plate:\n", "\n", "- **`objmask`** — a binary mask (`True` where colonies are, `False` for background)\n", "- **`objmap`** — a labeled map where each colony gets a unique integer (0 = background)\n", "\n", "Let's look at both." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "White regions are colonies, black is background. This is useful for a quick\n", "sanity check — do the white patches line up with where you see colonies in the\n", "RGB image?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plate.objmap.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View the Detection Overlay\n", "\n", "The most useful quality-check is the **overlay** — the detected colonies\n", "drawn on top of the original RGB image. This lets you see at a glance\n", "whether the detection matches reality." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plate.dash(overlay=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plate.dash(overlay=True, show_labels=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summary\n", "\n", "You've detected colonies on a real plate image using `OtsuDetector` and\n", "explored three ways to view the results:\n", "\n", "- **`objmask`** — binary colony mask\n", "- **`objmap`** — labeled colony map with unique IDs\n", "- **overlay** — colonies drawn on the original plate for visual validation\n", "\n", "The detection may not be perfect — some faint colonies might be missed, or\n", "background artifacts might be picked up. In the next tutorial, you'll learn\n", "how **enhancing** the detection matrix before detection can improve results.\n", "\n", "**Next up:** [Tutorial 3: Enhancing Before Detection](03_enhancing_before_detection.ipynb)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }