{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How To: Assess Image Quality Before Pipeline Design\n", "\n", "Run diagnostics on a plate image to objectively assess noise, contrast,\n", "and structure before choosing enhancers and detectors." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from phenotypic.data import load_yeast_plate\n", "from phenotypic.plotting import PlotDiagnostics\n", "from phenotypic.util import ImageMetricsCalculator\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plate = load_yeast_plate()\n", "fig = PlotDiagnostics().inspect(plate)\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Decision Guide\n", "\n", "| Metric | Threshold | Action |\n", "|--------|-----------|--------|\n", "| Low SNR (< 10) | Noisy image | Add `StableDenoise` or `BlurGauss` |\n", "| Low RMS contrast | Faint colonies | Add `CLAHE` or `ContrastStretching` |\n", "| Low dynamic range | Under-exposed | Add `ContrastStretching` |\n", "| Low gradient mean | Soft edges | Add `UnsharpMask` or `FocusEdgeSobel` |\n", "| Long correlation length | Uneven illumination | Add `HomomorphicFilter` |" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "calculator = ImageMetricsCalculator(plate.detect_mat[:])\n", "metrics = {\n", " \"noise\": calculator.compute_noise_metrics(),\n", " \"contrast\": calculator.compute_contrast_metrics(),\n", " \"structure\": calculator.compute_structure_metrics(),\n", " \"background\": calculator.compute_background_metrics(),\n", "}\n", "for category, values in metrics.items():\n", " print(f\"\\n{category}:\")\n", " for key, val in values.items():\n", " if isinstance(val, (int, float)):\n", " print(f\" {key}: {val:.4f}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.close(\"all\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }