{ "cells": [ { "cell_type": "markdown", "id": "ca4f7690-018d-4442-9037-d96de2ebd3aa", "metadata": {}, "source": [ "# Voronoi-Otsu-Labeling auf bin\u00e4ren Bildern\n", "Der Voronoi-Otsu-Labeling-Algorithmus kann auch auf bin\u00e4re Bilder angewendet werden und f\u00fchrt zu \u00e4hnlichen Ergebnissen wie der bin\u00e4re Watershed in ImageJ. Er trennt rundliche Objekte, falls sie zusammenkleben." ] }, { "cell_type": "code", "execution_count": 1, "id": "f2e65070-7047-43e0-8cb5-798dc2dad5ec", "metadata": {}, "outputs": [], "source": [ "from skimage.io import imread\n", "from napari_segment_blobs_and_things_with_membranes import voronoi_otsu_labeling, threshold_otsu\n", "import stackview" ] }, { "cell_type": "markdown", "id": "71c1a312-26a4-4cf1-8ece-f621f2e08331", "metadata": {}, "source": [ "Um dies zu demonstrieren, beginnen wir mit einem bin\u00e4ren Bild." ] }, { "cell_type": "code", "execution_count": 2, "id": "488052cc-7a36-4797-9d19-6741a4a31635", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "nsbatwm made image
\n", "\n", "\n", "\n", "\n", "\n", "
shape(254, 256)
dtypeint32
size254.0 kB
min0
max1
\n", "\n", "
" ], "text/plain": [ "StackViewNDArray([[0, 0, 0, ..., 1, 1, 1],\n", " [0, 0, 0, ..., 1, 1, 1],\n", " [0, 0, 0, ..., 1, 1, 1],\n", " ...,\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0]])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "blobs_image = imread(\"../../data/blobs.tif\")\n", "binary_image = threshold_otsu(blobs_image)\n", "\n", "binary_image" ] }, { "cell_type": "markdown", "id": "29ea255c-6c01-465c-8413-55729d4b3223", "metadata": {}, "source": [ "Wir wenden nun Voronoi-Otsu-Labeling auf das bin\u00e4re Bild an." ] }, { "cell_type": "code", "execution_count": 3, "id": "40a18c69-f042-4efc-bb62-64fa0fa1a60d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "nsbatwm made image
\n", "\n", "\n", "\n", "\n", "\n", "
shape(254, 256)
dtypeint32
size254.0 kB
min0
max67
\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]])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "label_image = voronoi_otsu_labeling(binary_image, spot_sigma=3.5)\n", "\n", "label_image" ] }, { "cell_type": "markdown", "id": "a85451b3-5572-4186-bc95-ce03f422d8e0", "metadata": {}, "source": [ "## \u00dcbung\n", "Unten sehen Sie das Ergebnis des Watershed in ImageJ. Wie m\u00fcssen Sie das `label_image`-Ergebnis oben modifizieren, um es wieder in ein bin\u00e4res Bild wie das Ergebnis von ImageJ zu verwandeln?" ] }, { "cell_type": "code", "execution_count": 4, "id": "36ad7baf-7d26-473f-a428-6f2096341c8f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
shape(254, 256)
dtypeuint8
size63.5 kB
min0
max255
\n", "\n", "
" ], "text/plain": [ "StackViewNDArray([[ 0, 0, 0, ..., 255, 255, 255],\n", " [ 0, 0, 0, ..., 255, 255, 255],\n", " [ 0, 0, 0, ..., 255, 255, 255],\n", " ...,\n", " [ 0, 0, 0, ..., 0, 0, 0],\n", " [ 0, 0, 0, ..., 0, 0, 0],\n", " [ 0, 0, 0, ..., 0, 0, 0]], dtype=uint8)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binary_watershed_imagej = imread(\"../../data/blobs_otsu_watershed.tif\")\n", "\n", "stackview.insight(binary_watershed_imagej)" ] }, { "cell_type": "code", "execution_count": null, "id": "74ce16b1-98ae-4e5a-b774-8c3a6e91c0fd", "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.13" } }, "nbformat": 4, "nbformat_minor": 5 }