{ "cells": [ { "cell_type": "markdown", "id": "c463dc52-4a63-4a2e-9803-2e25ed1ec6ae", "metadata": {}, "source": [ "# Interactive Removal of Artifacts\n", "\n", "Sometimes, it can happen that only a part of the tissue is usable for analysis, for example due to artifacts or poor tissue quality in a certain region. In such cases, it can make sense to mask out problematic regions. This way, the image can still be used for downstream analysis, but the artifact will not influence results in a negative way. `Spatialproteomics` allows users to upload a binary mask, which indicates which part of the image is suitable for further analysis and which part is not.\n", "\n", "The example below shows how one could for example use [TissueTag](https://github.com/Teichlab/TissueTag/tree/main) to obtain such a mask, load it into the spatialproteomics and use the mask to remove the artifact. Note that TissueTag runs in jupyter notebooks or jupyter lab, but has no implementation for jupyterhub at the moment." ] }, { "cell_type": "code", "execution_count": 33, "id": "e66ec23f-fc5e-4498-a3e6-3ce4a13ab822", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import spatialproteomics as sp\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from PIL import Image" ] }, { "cell_type": "markdown", "id": "5cf6f16b-2dd5-4934-be68-dca33dd8ebbb", "metadata": {}, "source": [ "### Loading the image from a zarr file" ] }, { "cell_type": "code", "execution_count": 34, "id": "0e44ceac-0319-419b-aed9-dd1570585512", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/mbender/mambaforge/envs/interactive_cropping_env/lib/python3.10/site-packages/xarray/backends/plugins.py:159: RuntimeWarning: 'scipy' fails while guessing\n", " warnings.warn(f\"{engine!r} fails while guessing\", RuntimeWarning)\n" ] }, { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (cells: 8395, celltype_levels: 3, channels: 3,\n", " y: 1811, x: 1721, features: 9, labels: 9, props: 2,\n", " rgba: 4)\n", "Coordinates:\n", " * cells (cells) int64 1 2 3 4 5 ... 8391 8392 8393 8394 8395\n", " * celltype_levels (celltype_levels) <U8 'labels' 'labels_1' 'labels_2'\n", " * channels (channels) <U11 'PAX5' 'CD3' 'Podoplanin'\n", " * features (features) <U10 'BCL-2' 'CCR7' ... 'ki-67'\n", " * labels (labels) int64 1 2 3 4 5 6 7 8 9\n", " * props (props) <U6 '_color' '_name'\n", " * x (x) int64 70 71 72 73 74 ... 1786 1787 1788 1789 1790\n", " * y (y) int64 120 121 122 123 124 ... 1927 1928 1929 1930\n", " * rgba (rgba) <U1 'r' 'g' 'b' 'a'\n", "Data variables:\n", " _celltype_predictions (cells, celltype_levels) object 'B' 'B' ... 'B' 'B'\n", " _image (channels, y, x) uint8 1 1 0 1 0 0 0 ... 0 0 0 0 0 0\n", " _obs (cells, features) float64 1.0 0.0 0.0 ... 933.1 0.0\n", " _properties (labels, props) object '#e6194B' 'B' ... 'T'\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0\n", " _plot (y, x, rgba) float64 0.02338 0.02922 ... 0.01153 1.0