Skip to content

Composite Overlays

Overlay generation functions

composite_overlay(segs, colors=None, alpha=0.2, imagery=None, outline=False, merge_outline=True, overlap=True, width=10, side='out', dim=2, palette=DEFAULT_PALETTE, h=DEFAULT_H, l=DEFAULT_L, s=DEFAULT_S)

Make a colored composite overlay for a 3d mask from an iterable of masks.

Parameters:

Name Type Description Default
segs

Iterable of masked images of the same size. If a dict, colors must be a dict as well.

required
colors list-like, dict, or None

Iterable of RGB colors of the same size as masks. If a dict, masks must also be a dict and colors must have all keys in masks. If None, uses discrete_colors to generate colors.

None
alpha float

Alpha value for the overlay

0.2
imagery Image or None

If an Image, applies the overlay to the image, by default None

None
outline bool

If True, produces an outline instead of a flat overay, by default False

False
merge_outline bool

If True, the merge outline applies to the segmentation as a whole and thus internal contacts are not outlined.

True
overlap bool

If False, segmentations later in the list will not overlap segmentations earlier on the list.

True
width int

If outline=True, sets the width of the outline, by default 10

10
side out or 'in'

If outline=True, selects if the outline is inside or outside the original segmentation mask, by default 'out'

'out'
dim int

Determines axis over which slices are iterated if the data is 3 dimensional. Default is 2 (z-axis).

2

Returns:

Type Description
list or Image

Image or list of composite overlay images, optionally overlaid over provided imagery. List or single image is determined based on segmentation arrays being 2 or 3 dimensional.

discrete_colors(segs, palette=DEFAULT_PALETTE, h=DEFAULT_H, l=DEFAULT_L, s=DEFAULT_S)

Generate discrete colors for segmentations from a palette generator. Defaults to perceptually uniform differences with high saturation.

Parameters:

Name Type Description Default
segs list or dict

Dict or list of segmentations to provide colors for.

required
palette 'husl', 'hls', or str

Which palette system to use, by default 'husl'. Will accept anything allowed by seaborn color_palette function.

DEFAULT_PALETTE
h float

Hue value if husl or hls palettes are used, by default 0.01

DEFAULT_H
l float

Lightness if husl or hls palettes are used, by default 0.6

DEFAULT_L
s int

Saturation if husl or hls palettes are used, by default 1

DEFAULT_S

Returns:

Type Description
List or dict

List or dict with one color per segmentation.

stack_images(images, direction='horizontal', spacing=10)

Stack an iterable of images either veritcally or horizontally

Parameters:

Name Type Description Default
images list - like

Iterable of Image.Image objects

required
spacing int

Spacing between images in pixels, by default 10

10
direction horizontal or vertical

Direction of the grid of images, by default 'horizontal'

'horizontal'

Returns:

Type Description
Image

Combined grid of images