{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How To: Enhance Low-Contrast Images\n", "\n", "When colonies are faint or the agar background is uneven, detection suffers.\n", "Use `CLAHE`, `ContrastStretching`, or `HomomorphicFilter` to boost local\n", "contrast in `detect_mat` before detection." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from phenotypic.data import load_yeast_plate\n", "from phenotypic.enhance import CLAHE, ContrastStretching, HomomorphicFilter" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plate = load_yeast_plate()\n", "plate.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 1: CLAHE\n", "\n", "Adaptive histogram equalization that boosts local contrast. Best for plates\n", "with locally varying brightness." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "enhanced = CLAHE(clip_limit=0.02).apply(plate.copy())\n", "enhanced.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 2: Contrast Stretching\n", "\n", "Linearly maps the intensity range to fill the full dynamic range. Simple\n", "and effective when the histogram is narrow but unimodal." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "enhanced2 = ContrastStretching().apply(plate.copy())\n", "enhanced2.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 3: Homomorphic Filter\n", "\n", "Separates illumination from reflectance in the frequency domain.\n", "Best for correcting uneven illumination gradients across the plate." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "enhanced3 = HomomorphicFilter(sigma=200.0, gamma_low=0.5, gamma_high=1.5).apply(plate.copy())\n", "enhanced3.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Choose based on the root cause: CLAHE for general low contrast,\n", "`ContrastStretching` for narrow histograms, `HomomorphicFilter` for\n", "uneven illumination." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }