{
"cells": [
{
"cell_type": "markdown",
"id": "20746a3f-2a1a-4c94-ab88-d7b0572ccab4",
"metadata": {},
"source": [
"# Modifizieren von Gewebegrenzen\n",
"Bei der Segmentierung von Objektansammlungen, wie zum Beispiel Zellen in einem Organoid, kann es vorkommen, dass die segmentierten Zellen am Gewebebereich, die den Hintergrund ber\u00fchren, nicht korrekt segmentiert werden. Um nur diese zu modifizieren, kann es sinnvoll sein, ein Beschriftungsbild nachzubearbeiten, indem man nur die Objektgrenzen in der N\u00e4he des Hintergrunds ver\u00e4ndert."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "efe83c42-9303-43d0-9084-cd2f511ed83a",
"metadata": {},
"outputs": [],
"source": [
"import pyclesperanto_prototype as cle\n",
"\n",
"# import a function from a file in the same folder\n",
"from simulated_cell_clumb import simulate_data"
]
},
{
"cell_type": "markdown",
"id": "c17126e1-5731-4cde-942d-84df26dd1850",
"metadata": {},
"source": [
"Zur Demonstration simulieren wir eine Ansammlung von Zellen."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8b964cbb-0f1b-489d-bbf8-6096614cd00c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (200, 200) | \n",
"dtype | uint32 | \n",
"size | 156.2 kB | \n",
"min | 0.0 | max | 40.0 | \n",
" \n",
"\n",
" | \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": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cells = simulate_data()\n",
"cells"
]
},
{
"cell_type": "markdown",
"id": "6a89d831-4dca-45d3-9238-f4105ba11f89",
"metadata": {},
"source": [
"Wir k\u00f6nnen das gesamte Feld von Beschriftungen erodieren, als ob es ein Bin\u00e4rbild w\u00e4re, w\u00e4hrend die Pixel beschriftet bleiben. Dadurch werden nur die Beschriftungen an der Grenze zum Hintergrund modifiziert."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5f966526-8f00-4316-bb3a-b6fa41b48633",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (200, 200) | \n",
"dtype | uint32 | \n",
"size | 156.2 kB | \n",
"min | 0.0 | max | 40.0 | \n",
" \n",
"\n",
" | \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": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eroded_cells = cle.erode_connected_labels(cells, radius=5)\n",
"eroded_cells"
]
},
{
"cell_type": "markdown",
"id": "385ea1b7-d861-45b4-ac35-efd5038166a2",
"metadata": {},
"source": [
"Nur zum Vergleich, wie sich dies von der Beschriftungserosion unterscheidet:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7f69b7ab-1641-43dc-9aed-4bd47229395a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (200, 200) | \n",
"dtype | uint32 | \n",
"size | 156.2 kB | \n",
"min | 0.0 | max | 40.0 | \n",
" \n",
"\n",
" | \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": [
"eroded_cells2 = cle.erode_labels(eroded_cells, radius=5)\n",
"eroded_cells2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d4908b5-f238-48d1-bee4-c4095ba1924d",
"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.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}