{ "cells": [ { "cell_type": "markdown", "id": "96d5e526-425b-4319-8043-828208956ef9", "metadata": {}, "source": [ "# Cluster plots\n", "Using `stackview.clusterplot` we can visualize contents of pandas DataFrames and corresponding segmented objects in an sime side-by-side. In such a plot you can select objects and visualize the selection. This might be useful for exploring feature extraction parameter spaces." ] }, { "cell_type": "code", "execution_count": 1, "id": "f4ec4d56-e298-40d8-a5b5-836cbcc2897d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.12.0'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import stackview\n", "import pandas as pd\n", "from skimage.measure import regionprops_table\n", "from skimage.io import imread\n", "from skimage.filters import threshold_otsu\n", "from skimage.measure import label\n", "import matplotlib.pyplot as plt\n", "from sklearn.preprocessing import StandardScaler \n", "from umap import UMAP\n", "\n", "stackview.__version__" ] }, { "cell_type": "markdown", "id": "dfddfa23-9290-425e-b8e5-2fd4d586db9a", "metadata": {}, "source": [ "To demonstrate this, we need an image, a segmentation and a table of extracted features." ] }, { "cell_type": "code", "execution_count": 2, "id": "e252c694-f7af-4b0d-9bbe-e6f682e8ab5c", "metadata": {}, "outputs": [], "source": [ "image = imread('data/blobs.tif')\n", "\n", "# segment image\n", "thresh = threshold_otsu(image)\n", "binary_image = image > thresh\n", "labeled_image = label(binary_image)" ] }, { "cell_type": "code", "execution_count": 4, "id": "9e84d0b9-3b2f-42a9-b28a-b61f729d2b52", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\rober\\miniforge3\\envs\\bob-env\\Lib\\site-packages\\umap\\umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.\n", " warn(\n" ] }, { "data": { "text/html": [ "
| \n", " | mean_intensity | \n", "std_intensity | \n", "centroid-0 | \n", "centroid-1 | \n", "area | \n", "feret_diameter_max | \n", "minor_axis_length | \n", "major_axis_length | \n", "UMAP1 | \n", "UMAP2 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "190.854503 | \n", "30.269911 | \n", "13.212471 | \n", "19.986143 | \n", "433.0 | \n", "36.055513 | \n", "16.819060 | \n", "34.957399 | \n", "4.446589 | \n", "0.901159 | \n", "
| 1 | \n", "179.286486 | \n", "21.824090 | \n", "4.270270 | \n", "62.945946 | \n", "185.0 | \n", "21.377558 | \n", "11.803854 | \n", "21.061417 | \n", "2.342915 | \n", "-0.930705 | \n", "
| 2 | \n", "205.617021 | \n", "29.358477 | \n", "12.568389 | \n", "108.329787 | \n", "658.0 | \n", "32.449961 | \n", "28.278264 | \n", "30.212552 | \n", "4.911047 | \n", "0.156550 | \n", "
| 3 | \n", "217.327189 | \n", "36.019565 | \n", "9.806452 | \n", "154.520737 | \n", "434.0 | \n", "26.925824 | \n", "23.064079 | \n", "24.535398 | \n", "4.941196 | \n", "-0.982479 | \n", "
| 4 | \n", "212.142558 | \n", "29.872907 | \n", "13.545073 | \n", "246.809224 | \n", "477.0 | \n", "31.384710 | \n", "19.833058 | \n", "31.162612 | \n", "5.321925 | \n", "-1.058476 | \n", "