{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Auswahl von Beschriftungen basierend auf ihrer Gr\u00f6\u00dfe\n", "Nachdem ein Bild segmentiert und Objekte beschriftet wurden, m\u00f6chten wir m\u00f6glicherweise Objekte entfernen, die entweder zu klein oder zu gro\u00df sind, um als Objekte, zum Beispiel _Zellkerne_, betrachtet zu werden." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\structure\\code\\pyclesperanto_prototype\\pyclesperanto_prototype\\_tier0\\_device.py:77: UserWarning: No OpenCL device found with GTX in their name. Using gfx1035 instead.\n", " warnings.warn(f\"No OpenCL device found with {name} in their name. Using {device.name} instead.\")\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pyclesperanto_prototype as cle\n", "\n", "from skimage.io import imread\n", "import matplotlib\n", "import numpy as np\n", "import stackview\n", "\n", "# initialize GPU\n", "cle.select_device(\"GTX\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Wir beginnen mit einer beschrifteten Version des Blobs-Bildes." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
shape(254, 256)
dtypeuint32
size254.0 kB
min0
max63
\n", "\n", "
" ], "text/plain": [ "StackViewNDArray([[0, 0, 0, ..., 5, 5, 5],\n", " [0, 0, 0, ..., 5, 5, 5],\n", " [0, 0, 0, ..., 5, 5, 5],\n", " ...,\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0]], dtype=uint32)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# load data\n", "label_image = imread('../../data/blobs_labeled.tif')\n", "\n", "stackview.insight(label_image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nehmen wir an, wir sind nicht an sehr kleinen Objekten interessiert, da sie m\u00f6glicherweise das Ergebnis einer falschen Segmentierung von Rauschen sind. Wir wissen, dass die von uns abgebildeten Objekte eine bestimmte Mindestgr\u00f6\u00dfe haben. Ausgehend von dieser physikalischen Annahme m\u00fcssen wir eine Anzahl von Pixeln (in 2D) oder Voxeln (in 3D) sch\u00e4tzen, die die Objekte gro\u00df sind. Wir k\u00f6nnen dann diese Zahl als `size_threshold` in Pixeln oder Voxeln verwenden." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "cle._ image
\n", "\n", "\n", "\n", "\n", "\n", "
shape(254, 256)
dtypeuint32
size254.0 kB
min0.0
max52.0
\n", "\n", "
" ], "text/plain": [ "cl.OCLArray([[0, 0, 0, ..., 5, 5, 5],\n", " [0, 0, 0, ..., 5, 5, 5],\n", " [0, 0, 0, ..., 5, 5, 5],\n", " ...,\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0]], dtype=uint32)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "size_threshold = 200 # pixels\n", "\n", "large_labels_only = cle.exclude_small_labels(label_image, maximum_size=size_threshold)\n", "\n", "large_labels_only" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Wir k\u00f6nnen eine \u00e4hnliche Funktion verwenden, um die Objekte, die oben entfernt wurden, in einem separaten Beschriftungsbild zu visualisieren." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "cle._ image
\n", "\n", "\n", "\n", "\n", "\n", "
shape(254, 256)
dtypeuint32
size254.0 kB
min0.0
max11.0
\n", "\n", "
" ], "text/plain": [ "cl.OCLArray([[0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " ...,\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0]], dtype=uint32)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "small_labels_only = cle.exclude_large_labels(label_image, minimum_size=size_threshold)\n", "\n", "small_labels_only" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.15" } }, "nbformat": 4, "nbformat_minor": 4 }