{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "db2cc66a-3e23-4f4e-a1c0-81dcaf5d3ca2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import pyclesperanto_prototype as cle\n", "\n", "cle.select_device(\"RTX\")" ] }, { "cell_type": "code", "execution_count": 14, "id": "9147857e-cea5-4062-8392-5f7a2df93a76", "metadata": {}, "outputs": [], "source": [ "def generate_centroid_distance_matrix(label_image1, label_image2):\n", " centroids1 = cle.centroids_of_labels(label_image1)\n", " \n", " if label_image1 is label_image2:\n", " centroids2 = centroids1\n", " else:\n", " centroids2 = cle.centroids_of_labels(label_image1)\n", "\n", " return cle.generate_distance_matrix(centroids1, centroids2)\n" ] }, { "cell_type": "code", "execution_count": 15, "id": "0d6e3cbf-1fb8-4d73-a219-7d890987a35a", "metadata": {}, "outputs": [], "source": [ "image = np.asarray([[0,2,1,4,4],\n", " [0,2,3,4,4]])" ] }, { "cell_type": "code", "execution_count": 16, "id": "295d1bb9-d658-4c0f-96cd-085646ba6623", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "cl.Array([[0. , 0. , 0. , 0. , 0. ],\n", " [0. , 0. , 1.1180339, 1. , 1.5811388],\n", " [0. , 1.1180339, 0. , 1.1180339, 2.4999998],\n", " [0. , 1. , 1.1180339, 0. , 1.5811388],\n", " [0. , 1.5811388, 2.4999998, 1.5811388, 0. ]],\n", " dtype=float32)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generate_centroid_distance_matrix(image, image)" ] }, { "cell_type": "code", "execution_count": null, "id": "f3acb4d8-1808-4f3f-bd16-33ca02596d59", "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.8.12" } }, "nbformat": 4, "nbformat_minor": 5 }