{
"cells": [
{
"cell_type": "markdown",
"id": "cef9a48c-33df-4296-9380-c0c9a1dbad95",
"metadata": {},
"source": [
"# Identifizierung von Beschriftungen, die den Hintergrund ber\u00fchren\n",
"In der Entwicklungsbiologie ist es eine h\u00e4ufige Aufgabe, Zellschichten zu unterscheiden, zum Beispiel in epithelialem Gewebe. Daher kann es n\u00fctzlich sein zu wissen, ob eine Zelle Teil einer \u00e4u\u00dferen Schicht ist, ob sie den Hintergrund ber\u00fchrt. In diesem Notebook messen und visualisieren wir dies.\n",
"\n",
"Zur Demonstration simulieren wir einen Zellhaufen."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5c01c538-6ad9-47b7-93bd-c58fbcf81006",
"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": "code",
"execution_count": 2,
"id": "66703104-00a4-4a86-ba1c-bf25a2dacd96",
"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 | 41.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": "bf18c763-9eee-409f-aa18-a8efa4a21d8a",
"metadata": {},
"source": [
"## Bestimmen, welche Zellen den Hintergrund ber\u00fchren\n",
"Um festzustellen, welche Zellen den Hintergrund ber\u00fchren, m\u00fcssen wir eine Ber\u00fchrungsmatrix erstellen, die uns anzeigt, welche Objekte welche anderen ber\u00fchren."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dfdb2c9b-71db-475a-8861-6b235352746b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (42, 42) | \n",
"dtype | float32 | \n",
"size | 6.9 kB | \n",
"min | 0.0 | max | 1.0 | \n",
" \n",
" \n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"cl.OCLArray([[0., 1., 1., ..., 1., 1., 1.],\n",
" [1., 0., 1., ..., 0., 0., 0.],\n",
" [1., 1., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [1., 0., 0., ..., 0., 0., 1.],\n",
" [1., 0., 0., ..., 0., 0., 1.],\n",
" [1., 0., 0., ..., 1., 1., 0.]], dtype=float32)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"touch_matrix = cle.generate_touch_matrix(cells)\n",
"touch_matrix"
]
},
{
"cell_type": "markdown",
"id": "8b5d8105-c5e2-4388-a3cd-13f118feecb7",
"metadata": {},
"source": [
"Die erste Zeile und Spalte in diesem Bild repr\u00e4sentieren Objekte, die den Hintergrund ber\u00fchren. Wir k\u00f6nnen diese erste Zeile oder Spalte wie folgt auslesen:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e1005bb2-5399-42bc-bf1e-f554a2519c10",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"cle.array([0. 1. 1. 1. 0. 1. 1. 1. 0. 1. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 1.\n",
" 0. 0. 1. 0. 0. 1. 0. 1. 1. 0. 0. 1. 1. 0. 0. 1. 1. 1.], dtype=float32)
"
],
"text/plain": [
"cl.OCLArray([0., 1., 1., 1., 0., 1., 1., 1., 0., 1., 0., 0., 1., 0., 0., 0., 0.,\n",
" 1., 0., 0., 0., 0., 1., 1., 0., 0., 1., 0., 0., 1., 0., 1., 1., 0.,\n",
" 0., 1., 1., 0., 0., 1., 1., 1.], dtype=float32)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"touching_background = touch_matrix[0]\n",
"touching_background"
]
},
{
"cell_type": "markdown",
"id": "5c3ee386-78fc-46d3-96ce-26da761990d7",
"metadata": {},
"source": [
"Und wir k\u00f6nnen es in den urspr\u00fcnglichen Bildkoordinaten visualisieren."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f4b208ac-fe4c-4cb8-b03b-2ad7835738f1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (200, 200) | \n",
"dtype | float32 | \n",
"size | 156.2 kB | \n",
"min | 0.0 | max | 1.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=float32)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cle.replace_intensities(cells, touching_background)"
]
},
{
"cell_type": "markdown",
"id": "da0904ae-369b-41eb-9a7b-05ff688e955e",
"metadata": {},
"source": [
"Oder wir k\u00f6nnen ein Beschriftungsbild erhalten, das diese Objekte darstellt."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "1737ff2a-3d2a-45fe-a1cf-8d86780a51c4",
"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 | 20.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": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cle.exclude_labels(cle.binary_not([touching_background]), cells)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3f8ca5c-f4fb-456b-8e73-11f4d87f7166",
"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": 5
}