{ "cells": [ { "cell_type": "markdown", "id": "8bfa86fc-d854-419e-a91f-da1dbc91e390", "metadata": { "tags": [] }, "source": [ "# Skalierung von Koordinatenlisten\n", "\n", "Nehmen wir an, Sie haben eine Liste von Koordinaten, die von einem Bild abgeleitet wurden. Falls das Bild eine spezifizierte Pixelgr\u00f6\u00dfe hat, k\u00f6nnen Sie Pixelkoordinaten in physische Koordinaten umwandeln." ] }, { "cell_type": "code", "execution_count": 1, "id": "b2f0de47-ecf1-413e-922e-acbe01b8fc19", "metadata": { "tags": [] }, "outputs": [], "source": [ "from skimage.io import imread\n", "import pyclesperanto_prototype as cle\n", "import stackview" ] }, { "cell_type": "raw", "id": "abfa82f9-6a82-4367-af0f-53991061642e", "metadata": {}, "source": [ "Unser Ausgangspunkt f\u00fcr diese Demonstration ist ein Labelbild." ] }, { "cell_type": "code", "execution_count": 2, "id": "d6680458-dbc7-4967-824e-761224c5bad0", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n",
" | \n",
"\n",
"cle._ image \n", "
| \n",
"
cle.array([[ 0.7586207 7.7894735 17.849672 24.59091 29.01266 43.57143 ]\n", " [26.275862 44.63158 17.79085 4.071429 47.02532 26.266666 ]], dtype=float32)" ], "text/plain": [ "cl.OCLArray([[ 0.7586207, 7.7894735, 17.849672 , 24.59091 , 29.01266 ,\n", " 43.57143 ],\n", " [26.275862 , 44.63158 , 17.79085 , 4.071429 , 47.02532 ,\n", " 26.266666 ]], dtype=float32)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "centroids = cle.centroids_of_labels(label_image)\n", "centroids" ] }, { "cell_type": "markdown", "id": "00f4ca87-0593-45e7-a7f3-70590256cd48", "metadata": { "tags": [] }, "source": [ "Eine solche Punktliste hat d mal n Zahlen f\u00fcr d Dimensionen (\u00fcblicherweise 2 oder 3) und n Punkte." ] }, { "cell_type": "code", "execution_count": 4, "id": "3b1979ab-36e9-42fb-865a-4253b004f6fa", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "(2, 6)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "centroids.shape" ] }, { "cell_type": "markdown", "id": "f3b3541c-ed8f-4095-8c51-a3ca9c4c96fc", "metadata": { "tags": [] }, "source": [ "Falls die Pixelgr\u00f6\u00dfe bekannt ist, k\u00f6nnen wir die Schwerpunktkoordinaten in physischen Einheiten berechnen." ] }, { "cell_type": "code", "execution_count": 5, "id": "a1ba4332-a51a-45c4-a81d-64e6376e2eed", "metadata": { "tags": [] }, "outputs": [], "source": [ "pixel_size_in_microns = [0.1, 0.1]" ] }, { "cell_type": "code", "execution_count": 6, "id": "b1db7b9a-352b-4d75-afe3-2c5e2359317b", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
cle.array([[0.07586207 0.77894735 1.7849673 2.459091 2.9012659 4.357143 ]\n", " [2.6275861 4.463158 1.779085 0.40714288 4.702532 2.6266668 ]], dtype=float32)" ], "text/plain": [ "cl.OCLArray([[0.07586207, 0.77894735, 1.7849673 , 2.459091 , 2.9012659 ,\n", " 4.357143 ],\n", " [2.6275861 , 4.463158 , 1.779085 , 0.40714288, 4.702532 ,\n", " 2.6266668 ]], dtype=float32)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "centroids_in_microns = centroids * cle.asarray([pixel_size_in_microns]).T\n", "\n", "centroids_in_microns" ] }, { "cell_type": "code", "execution_count": null, "id": "ffe27c58-9219-4edd-a99d-9151514d98f7", "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 }