{ "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": [ "ds = xr.load_dataset('../../data/segmentation_example.zarr', engine='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>\n", "Dimensions: (channels: 4, y: 301, x: 301)\n", "Coordinates:\n", " * channels (channels) <U11 'DAPI' 'Na/K ATPase' 'CD68' 'CD11c'\n", " * x (x) int64 1000 1001 1002 1003 1004 ... 1296 1297 1298 1299 1300\n", " * y (y) int64 1000 1001 1002 1003 1004 ... 1296 1297 1298 1299 1300\n", "Data variables:\n", " _image (channels, y, x) uint8 86 83 80 80 70 90 75 63 ... 9 5 5 3 5 6 2 4
<xarray.Dataset>\n", "Dimensions: (channels: 2, y: 301, x: 301)\n", "Coordinates:\n", " * channels (channels) <U11 'Na/K ATPase' 'DAPI'\n", " * x (x) int64 1000 1001 1002 1003 ... 1298 1299 1300\n", " * y (y) int64 1000 1001 1002 1003 ... 1298 1299 1300\n", "Data variables:\n", " _image (channels, y, x) uint8 28 25 27 32 ... 64 59 48 35\n", " _cellpose_segmentation (y, x) uint16 0 1 1 1 1 1 ... 324 324 324 324 324 0
<xarray.Dataset>\n", "Dimensions: (channels: 4, y: 301, x: 301, cells: 330, features: 2)\n", "Coordinates:\n", " * channels (channels) <U11 'DAPI' 'Na/K ATPase' 'CD68' 'CD11c'\n", " * x (x) int64 1000 1001 1002 1003 1004 ... 1297 1298 1299 1300\n", " * y (y) int64 1000 1001 1002 1003 1004 ... 1297 1298 1299 1300\n", " * cells (cells) int64 1 2 3 4 5 6 7 8 ... 324 325 326 327 328 329 330\n", " * features (features) <U10 'centroid-0' 'centroid-1'\n", "Data variables:\n", " _image (channels, y, x) uint8 86 83 80 80 70 90 75 ... 5 5 3 5 6 2 4\n", " _segmentation (y, x) int64 0 1 1 1 1 1 1 1 ... 324 324 324 324 324 324 0\n", " _obs (cells, features) float64 1.005e+03 1.011e+03 ... 1.003e+03" ], "text/plain": [ "