{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How To: Crop and Pad Images for Batch Consistency\n", "\n", "Use `ImageCropper` to remove scanner borders and `ImagePadder` to make\n", "images a uniform size for batch processing." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:47:55.491664Z", "start_time": "2026-04-21T02:47:53.080606Z" } }, "outputs": [], "source": [ "from phenotypic.data import load_yeast_plate_full\n", "from phenotypic.correction import ImageCropper, ImagePadder" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:47:56.888576Z", "start_time": "2026-04-21T02:47:55.492351Z" } }, "outputs": [], "source": [ "plate = load_yeast_plate_full()\n", "print(f\"Original size: {plate.shape}\")\n", "plate.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Crop Scanner Borders\n", "\n", "Remove unwanted borders by specifying pixels to trim from each edge." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:47:57.711587Z", "start_time": "2026-04-21T02:47:56.907121Z" } }, "outputs": [], "source": [ "cropper = ImageCropper(top=450, bottom=450, left=450, right=450)\n", "cropped = cropper.apply(plate)\n", "print(f\"Cropped size: {cropped.shape}\")\n", "cropped.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pad to Uniform Size\n", "\n", "When batch-processing plates of different sizes, pad them to a consistent\n", "dimension." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2026-04-21T02:47:58.302812Z", "start_time": "2026-04-21T02:47:57.726570Z" } }, "outputs": [], "source": [ "padder = ImagePadder(top=20, bottom=20, left=20, right=20, mode=\"constant\",\n", " constant_value=0)\n", "padded = padder.apply(cropped)\n", "print(f\"Padded size: {padded.shape}\")\n", "padded.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Both operations can be included in an `ImagePipeline` for batch\n", "processing. Place `ImageCropper` first, then `ImagePadder`, before\n", "any detection steps." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }