scallops.visualize.composite.label_montage

scallops.visualize.composite.label_montage(image, labels, labels_include, col_wrap=14, crop_size=(24, 24), **kwargs)

Plot a label montage.

Parameters:
  • image (DataArray) – XArray representing image to plot

  • labels (ndarray) – Labels (e.g., segmentation labels).

  • labels_include (list[int]) – list of label ids to plot

  • col_wrap (int) – Number of columns in grid

  • crop_size (tuple[int, int]) – Size of label crop

  • kwargs (Any) – Keyword arguments passed to single imcomposite function (e.g. vmin)

Returns:

RGBA array

Example:
import numpy as np
import xarray as xr
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
from skimage import data
from skimage.filters import sobel
from skimage.measure import label
from skimage.segmentation import expand_labels, watershed

from scallops.visualize.composite import label_montage

coins = data.coins()

# Make segmentation using edge-detection and watershed.
edges = sobel(coins)

# Identify some background and foreground pixels from the intensity values.
# These pixels are used as seeds for watershed.
markers = np.zeros_like(coins)
foreground, background = 1, 2
markers[coins < 30.0] = background
markers[coins > 150.0] = foreground

ws = watershed(edges, markers)
seg1 = label(ws == foreground)

expanded = expand_labels(seg1, distance=10)
img = label_montage(
    image=xr.DataArray(coins, dims=["y", "x"]),
    labels=expanded,
    labels_include=np.unique(expanded)[1:18],
    crop_size=(80, 80),
    col_wrap=6,
    labels_contour_cmap=ListedColormap([(1, 0, 0, 1)]),
)
plt.imshow(img, cmap=None)
plt.axis("off")
Return type:

ndarray