Terminology#

This notebook serves showing images and segmented images of different kind to explain common terminology.

from skimage.io import imread, imshow
import napari_segment_blobs_and_things_with_membranes as nsbatwm
import stackview
import numpy as np

Intensity images#

We start with intensity images as they are commonly produced by microscopes.

input_image = imread("../../data/BBBC022/IXMtest_A02_s9.tif")[:,:,0]

cropped_image = input_image[0:200, 200:400]

imshow(cropped_image, cmap='Greys_r')
C:\Users\haase\mambaforge\envs\bio39\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Low image data range; displaying image with stretched contrast.
  lo, hi, cmap = _get_display_range(image)
<matplotlib.image.AxesImage at 0x2ba68647e20>
../_images/7642ae17d367f89fcd614de0e62927e0d15176780e0bae08e20780f0a31028cc.png

Binary images#

Basic segmentation algorithms lead to binary images. They are characterized by having only two different intensities such as 0 and 1.

binary_image = nsbatwm.threshold_otsu(cropped_image)
binary_image
nsbatwm made image
shape(200, 200)
dtypeint32
size156.2 kB
min0
max1

Instance segmentation#

If each individual object has its own intensity / color, we call it an instance segmentation label image. The inistances are labeled with integer numbers. The maximum intensity (label) in this image typically corresponds to the number of objects.

instance_segmentation = nsbatwm.voronoi_otsu_labeling(cropped_image, 
                                        spot_sigma=5, 
                                        outline_sigma=1)

instance_segmentation
nsbatwm made image
shape(200, 200)
dtypeint32
size156.2 kB
min0
max12

When you run this notebook locally, you can hover with your mouse over the image and inspect pixel intensities.

import stackview
stackview.picker(instance_segmentation)

Semantic segmentation#

Semantic segmentation label images can have more than two labels and typically label regions where pixels have the same meanings, for example: nuclei, nuclear envelope and background.

semantic_segmentation = binary_image + nsbatwm.maximum_filter(binary_image).astype(np.uint32) + 1
semantic_segmentation
nsbatwm made made image
shape(200, 200)
dtypeint64
size312.5 kB
min1
max3

Sparse annotations#

Annotated label images are typically drawn by humans. When executing this notebook locally, you can draw some annotations. If you annotate a couple of nuclei precisely, you create a sparse nuclei annotation. Hold down the ALT key to erase an annotation.

sparse_label_annotation = np.zeros_like(cropped_image, dtype=np.uint32)
stackview.annotate(cropped_image, sparse_label_annotation)
stackview.insight(sparse_label_annotation)
shape(200, 200)
dtypeuint32
size156.2 kB
min0
max4

You can also create a sparse semantic annotation, e.g. by annotating some pixels within nuclei and some pixels within the background.

sparse_semantic_annotation = np.zeros_like(cropped_image, dtype=np.uint32)
stackview.annotate(cropped_image, sparse_semantic_annotation)
stackview.insight(sparse_semantic_annotation)
shape(200, 200)
dtypeuint32
size156.2 kB
min0
max3