{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How To: Denoise Low-Light Images\n", "\n", "Low-light or high-ISO plate images contain noise that confuses detectors.\n", "PhenoTypic offers several denoising approaches, each with different\n", "tradeoffs between speed and quality." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:48:31.962620Z", "start_time": "2026-04-21T02:48:29.957604Z" } }, "outputs": [], "source": [ "from phenotypic.data import load_fungi_plate\n", "from phenotypic.enhance import GaussianBlur, MedianFilter, VisuShrinkEnhancer\n", "from phenotypic.correction import StableDenoise" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:48:32.689774Z", "start_time": "2026-04-21T02:48:31.966699Z" } }, "outputs": [], "source": [ "plate = load_fungi_plate()\n", "plate.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 1: GaussianBlur (fastest)\n", "\n", "Simple and fast. Blurs noise but also softens colony edges." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:48:32.792218Z", "start_time": "2026-04-21T02:48:32.705123Z" } }, "outputs": [], "source": [ "result1 = GaussianBlur(sigma=2.0).apply(plate.copy())\n", "result1.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 2: MedianFilter (edge-preserving)\n", "\n", "Removes salt-and-pepper noise while keeping colony boundaries sharp." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:48:32.983868Z", "start_time": "2026-04-21T02:48:32.793013Z" } }, "outputs": [], "source": [ "result2 = MedianFilter(width=5).apply(plate.copy())\n", "result2.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 3: VisuShrinkEnhancer (wavelet)\n", "\n", "Wavelet-based denoising. Preserves fine details better than spatial\n", "filters at the cost of speed." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:48:33.071784Z", "start_time": "2026-04-21T02:48:32.987789Z" } }, "outputs": [], "source": [ "result3 = VisuShrinkEnhancer(wavelet=\"db2\", mode=\"soft\").apply(plate.copy())\n", "result3.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 4: StableDenoise (BM3D, highest quality)\n", "\n", "Variance-stabilized BM3D denoising. Best quality but slowest. Use for\n", "critical experiments where accuracy matters more than speed." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:48:36.315657Z", "start_time": "2026-04-21T02:48:33.073624Z" } }, "outputs": [], "source": [ "result4 = StableDenoise(stage_arg=\"hard_thresholding\").apply(plate.copy())\n", "result4.detect_mat.dash()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Choosing a Method\n", "\n", "| Method | Speed | Edge preservation | Best for |\n", "|--------|-------|-------------------|----------|\n", "| `GaussianBlur` | Fastest | Low | Quick preprocessing |\n", "| `MedianFilter` | Fast | High | Salt-and-pepper noise |\n", "| `VisuShrinkEnhancer` | Moderate | High | General noise, fine details |\n", "| `StableDenoise` | Slow | Highest | Critical experiments |" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }