{
"cells": [
{
"cell_type": "markdown",
"id": "bdddcc9c-1542-4a75-8e79-3a001858b5ed",
"metadata": {},
"source": [
"# Regionale Eigenschaften von Labels\n",
"In diesem Notebook charakterisieren wir Labels anhand des Mittelwerts und der Standardabweichung ihrer Eigenschaften, wie z.B. der Gr\u00f6\u00dfe. Wenn benachbarte Objekte \u00e4hnlich gro\u00df sind, ist die Standardabweichung ihrer Gr\u00f6\u00dfe gering. Wenn Labels unterschiedlicher Gr\u00f6\u00dfe benachbart sind, ist die Standardabweichung ihrer Gr\u00f6\u00dfe h\u00f6her. Dies k\u00f6nnte genutzt werden, um Regionen in Geweben zu identifizieren, in denen Zellen unterschiedlicher Gr\u00f6\u00dfe aufeinandertreffen."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "99d59c92-609e-417b-8918-a48b731087e3",
"metadata": {},
"outputs": [],
"source": [
"from skimage.io import imread\n",
"import pyclesperanto_prototype as cle\n",
"import stackview"
]
},
{
"cell_type": "markdown",
"id": "e764b9c5-bfba-4e17-8bb3-10ee4b3697f2",
"metadata": {},
"source": [
"Die hier verwendeten Daten wurden von maize_clsm.tif abgeleitet, das von [hier](https://github.com/dlegland/mathematical_morphology_with_MorphoLibJ/blob/master/sampleImages/maize_clsm.tif) stammt, ein von David Legland unter der [CC-BY 4.0 Lizenz](https://github.com/dlegland/mathematical_morphology_with_MorphoLibJ/blob/master/LICENSE) geteiltes Bild"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3257c9f4-3794-4615-9c3f-cf29fc5a6df4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"\n",
"\n",
"shape | (640, 639) | \n",
"dtype | uint8 | \n",
"size | 399.4 kB | \n",
"min | 0 | max | 255 | \n",
" \n",
" \n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"StackViewNDArray([[50, 27, 27, ..., 26, 26, 26],\n",
" [26, 1, 2, ..., 1, 1, 1],\n",
" [27, 1, 1, ..., 1, 1, 1],\n",
" ...,\n",
" [33, 5, 4, ..., 1, 1, 1],\n",
" [36, 9, 7, ..., 1, 1, 1],\n",
" [57, 34, 34, ..., 25, 24, 25]], dtype=uint8)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"image = imread(\"../../data/maize_clsm.tif\")\n",
"\n",
"stackview.insight(image)"
]
},
{
"cell_type": "markdown",
"id": "22f5a387-1934-4d57-b683-9914444285e0",
"metadata": {},
"source": [
"Ein entsprechendes Label-Bild sieht so aus:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "db05867f-95a8-4758-813d-69c5f2a5622a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (640, 639) | \n",
"dtype | uint32 | \n",
"size | 1.6 MB | \n",
"min | 1.0 | max | 254.0 | \n",
" \n",
"\n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"cl.OCLArray([[ 1, 1, 1, ..., 244, 244, 244],\n",
" [ 1, 1, 1, ..., 244, 244, 244],\n",
" [ 1, 1, 1, ..., 244, 244, 244],\n",
" ...,\n",
" [ 6, 6, 6, ..., 234, 234, 234],\n",
" [ 6, 6, 6, ..., 234, 234, 234],\n",
" [ 6, 6, 6, ..., 234, 234, 234]], dtype=uint32)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"labels = imread(\"../../data/maize_clsm_labels.tif\")\n",
"labels = cle.exclude_small_labels(labels, maximum_size=200)\n",
"labels = cle.extend_labeling_via_voronoi(labels)\n",
"labels"
]
},
{
"cell_type": "markdown",
"id": "d9d80ea3-0b90-4d60-9d0e-d5558e4e32f5",
"metadata": {},
"source": [
"## Gr\u00f6\u00dfenmessung\n",
"Zuerst m\u00fcssen wir die Gr\u00f6\u00dfe der Objekte quantifizieren. Wir k\u00f6nnen diese Messungen sofort als parametrisches Bild visualisieren."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8c2449b4-8093-4af8-ad29-cceed245c391",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (640, 639) | \n",
"dtype | float32 | \n",
"size | 1.6 MB | \n",
"min | 201.0 | max | 14283.0 | \n",
" \n",
" \n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"cl.OCLArray([[10411., 10411., 10411., ..., 5352., 5352., 5352.],\n",
" [10411., 10411., 10411., ..., 5352., 5352., 5352.],\n",
" [10411., 10411., 10411., ..., 5352., 5352., 5352.],\n",
" ...,\n",
" [14283., 14283., 14283., ..., 12378., 12378., 12378.],\n",
" [14283., 14283., 14283., ..., 12378., 12378., 12378.],\n",
" [14283., 14283., 14283., ..., 12378., 12378., 12378.]],\n",
" dtype=float32)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"size_map_image = cle.pixel_count_map(labels)\n",
"\n",
"size_map_image"
]
},
{
"cell_type": "markdown",
"id": "18204045-8f50-4a19-85ca-697aa46f5eca",
"metadata": {},
"source": [
"## Regionale Eigenschaften\n",
"Wir k\u00f6nnen diese Messungen nun lokal zusammenfassen, z.B. indem wir die durchschnittliche Gr\u00f6\u00dfe jeder Zelle und ihrer entsprechenden benachbarten Zellen messen."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "034f080c-4578-4b0b-953a-926701b61596",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (640, 639) | \n",
"dtype | float32 | \n",
"size | 1.6 MB | \n",
"min | 369.33334 | max | 7611.5 | \n",
" \n",
" \n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"cl.OCLArray([[6178.3335, 6178.3335, 6178.3335, ..., 3341.2 , 3341.2 ,\n",
" 3341.2 ],\n",
" [6178.3335, 6178.3335, 6178.3335, ..., 3341.2 , 3341.2 ,\n",
" 3341.2 ],\n",
" [6178.3335, 6178.3335, 6178.3335, ..., 3341.2 , 3341.2 ,\n",
" 3341.2 ],\n",
" ...,\n",
" [4809.5 , 4809.5 , 4809.5 , ..., 5657. , 5657. ,\n",
" 5657. ],\n",
" [4809.5 , 4809.5 , 4809.5 , ..., 5657. , 5657. ,\n",
" 5657. ],\n",
" [4809.5 , 4809.5 , 4809.5 , ..., 5657. , 5657. ,\n",
" 5657. ]], dtype=float32)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cle.mean_of_touching_neighbors_map(size_map_image, labels)"
]
},
{
"cell_type": "markdown",
"id": "041a720a-12cf-4a80-b4b2-9ef99b0d4719",
"metadata": {},
"source": [
"Wir k\u00f6nnen auch die Standardabweichung der Gr\u00f6\u00dfe berechnen, die die Grenzen zwischen den Regionen mit Zellen unterschiedlicher Gr\u00f6\u00dfe hervorhebt."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "333a86d3-2917-4df9-bf69-5b42fa5bd7a5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"cle._ image \n",
"\n",
"shape | (640, 639) | \n",
"dtype | float32 | \n",
"size | 1.6 MB | \n",
"min | 43.538486 | max | 3917.1946 | \n",
" \n",
" \n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"cl.OCLArray([[3169.5137, 3169.5137, 3169.5137, ..., 2035.8579, 2035.8579,\n",
" 2035.8579],\n",
" [3169.5137, 3169.5137, 3169.5137, ..., 2035.8579, 2035.8579,\n",
" 2035.8579],\n",
" [3169.5137, 3169.5137, 3169.5137, ..., 2035.8579, 2035.8579,\n",
" 2035.8579],\n",
" ...,\n",
" [3431.5947, 3431.5947, 3431.5947, ..., 3472.4436, 3472.4436,\n",
" 3472.4436],\n",
" [3431.5947, 3431.5947, 3431.5947, ..., 3472.4436, 3472.4436,\n",
" 3472.4436],\n",
" [3431.5947, 3431.5947, 3431.5947, ..., 3472.4436, 3472.4436,\n",
" 3472.4436]], dtype=float32)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cle.standard_deviation_of_touching_neighbors_map(size_map_image, labels)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fde3eb53-81dd-4738-b5bb-344d1bbc7dce",
"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
}