{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Segmentation\n", "Segmentation describes the process of finding cells in an image. This can be done either on the nucleus or on whole cell level. Spatialproteomics provides wrappers for StarDist, mesmer and cellpose." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [], "source": [ "import spatialproteomics\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import xarray as xr" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [], "source": [ "# loading the input data\n", "ds = xr.open_zarr(\"../../data/segmentation_example.zarr\").pp[1000:1300, 1000:1300].pp.drop_layers(keep=\"_image\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 367kB\n", "Dimensions: (channels: 4, y: 301, x: 301)\n", "Coordinates:\n", " * channels (channels) <U11 176B 'DAPI' 'Na/K ATPase' 'CD68' 'CD11c'\n", " * x (x) int64 2kB 1000 1001 1002 1003 1004 ... 1297 1298 1299 1300\n", " * y (y) int64 2kB 1000 1001 1002 1003 1004 ... 1297 1298 1299 1300\n", "Data variables:\n", " _image (channels, y, x) uint8 362kB dask.array<chunksize=(4, 301, 301), meta=np.ndarray>
<xarray.Dataset> Size: 555kB\n", "Dimensions: (channels: 4, y: 301, x: 301, cells: 282, features: 2)\n", "Coordinates:\n", " * channels (channels) <U11 176B 'DAPI' 'Na/K ATPase' 'CD68' 'CD11c'\n", " * x (x) int64 2kB 1000 1001 1002 1003 ... 1297 1298 1299 1300\n", " * y (y) int64 2kB 1000 1001 1002 1003 ... 1297 1298 1299 1300\n", " * cells (cells) int64 2kB 1 2 3 4 5 6 7 ... 277 278 279 280 281 282\n", " * features (features) <U10 80B 'centroid-0' 'centroid-1'\n", "Data variables:\n", " _image (channels, y, x) uint8 362kB dask.array<chunksize=(4, 301, 301), meta=np.ndarray>\n", " _segmentation (y, x) uint16 181kB 0 0 0 0 0 0 0 ... 274 274 274 274 274 0\n", " _obs (cells, features) float64 5kB 1.009e+03 ... 1.004e+03
<xarray.Dataset> Size: 820kB\n", "Dimensions: (channels: 3, y: 301, x: 301)\n", "Coordinates:\n", " * channels (channels) <U11 132B 'CD11c' 'CD68' 'DAPI'\n", " * x (x) int64 2kB 1000 1001 1002 1003 ... 1298 1299 1300\n", " * y (y) int64 2kB 1000 1001 1002 1003 ... 1298 1299 1300\n", "Data variables:\n", " _image (channels, y, x) uint8 272kB dask.array<chunksize=(3, 301, 301), meta=np.ndarray>\n", " _cellpose_segmentation (channels, y, x) uint16 544kB 0 0 0 ... 309 309 309
<xarray.Dataset> Size: 1MB\n", "Dimensions: (channels: 3, y: 301, x: 301)\n", "Coordinates:\n", " * channels (channels) <U11 132B 'CD11c' 'CD68' 'DAPI'\n", " * x (x) int64 2kB 1000 1001 1002 1003 ... 1298 1299 1300\n", " * y (y) int64 2kB 1000 1001 1002 1003 ... 1298 1299 1300\n", "Data variables:\n", " _image (channels, y, x) uint8 272kB dask.array<chunksize=(3, 301, 301), meta=np.ndarray>\n", " _cellpose_segmentation (channels, y, x) uint16 544kB 0 0 0 ... 309 309 309\n", " _merged_segmentation (y, x) uint16 181kB 0 11 11 11 ... 301 301 301 301
<xarray.Dataset> Size: 1MB\n", "Dimensions: (labels: 3, la_props: 2, channels: 3, x: 301,\n", " y: 301, cells: 306, features: 3)\n", "Coordinates:\n", " * labels (labels) int64 24B 1 2 3\n", " * la_props (la_props) <U6 48B '_color' '_name'\n", " * channels (channels) <U11 132B 'CD11c' 'CD68' 'DAPI'\n", " * x (x) int64 2kB 1000 1001 1002 1003 ... 1298 1299 1300\n", " * y (y) int64 2kB 1000 1001 1002 1003 ... 1298 1299 1300\n", " * cells (cells) int64 2kB 1 2 3 4 5 ... 302 303 304 305 306\n", " * features (features) <U10 120B '_labels' ... 'centroid-1'\n", "Data variables:\n", " _la_properties (labels, la_props) object 48B '#A3C8C9' ... 'Macr...\n", " _image (channels, y, x) uint8 272kB dask.array<chunksize=(3, 301, 301), meta=np.ndarray>\n", " _cellpose_segmentation (channels, y, x) uint16 544kB 0 0 0 ... 309 309 309\n", " _merged_segmentation (y, x) uint16 181kB 0 11 11 11 ... 301 301 301 301\n", " _obs (cells, features) float64 7kB 1.0 ... 1.004e+03\n", " _segmentation (y, x) uint16 181kB 0 11 11 11 ... 301 301 301 301
<xarray.Dataset> Size: 1MB\n", "Dimensions: (channels: 4, y: 301, x: 301)\n", "Coordinates:\n", " * channels (channels) <U11 176B 'DAPI' 'Na/K ATPase' 'CD68' 'CD11c'\n", " * x (x) int64 2kB 1000 1001 1002 1003 ... 1297 1298 1299 1300\n", " * y (y) int64 2kB 1000 1001 1002 1003 ... 1297 1298 1299 1300\n", "Data variables:\n", " _image (channels, y, x) uint8 362kB dask.array<chunksize=(4, 301, 301), meta=np.ndarray>\n", " dapi_seg (y, x) int64 725kB 11 11 11 11 11 11 ... 344 344 344 344 344\n", " macro_seg (y, x) uint16 181kB 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0\n", " dendritic_seg (y, x) uint16 181kB 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0