darsia.SegmentationComparison#

class SegmentationComparison(number_of_segmented_images=2, **kwargs)[source]#

Bases: object

Class for comparing segmented images.

Routines for comparing segmentations and creating visualizations of the comparison.

Attributes:
number_of_segmented_imagesint

Number of segmented images that one compares.

segmentation_nameslist[str]

List of names for each of the segmentations. Will affect legends in plots.

componentslist

List of values the different (active) components in the segmentations. As of now, up to two are allowed for and the default values are 1 and 2.

component_nameslist[str]

List of names for each of the components. Will be visual in legends.

gray_colorsnp.ndarray

Array of base gray colors (in RGB space) that accounts for different overlapping segmentations of different components.

colorsnp.ndarray

Color values for the different unique segmentations. Default is created from a colormap (matplotlib) depending on the amount of present segmentations.

color_dictionarydict

Dictionary relating all of the different colors to different overlapping segmentation situations.

Constructor of compare segmentations class.

Parameters:
number_of_segmented_imagesint

Number of segmentations to be compared. Optional keyword arguments (kwargs): segmentation_names (list): list of names for the different segmented images. So far only used in legends and color dictionary. components (list): list of the different components that are considered in the segmented images. So far only two are allowed to be provided. component_names (list): list of names for the different components. So far only used in legends, and color dictionary. gray_colors (np.ndarray): array of three different scales of gray (in RGB format), one for each of the different combinations of components in the segmentations. colors (np.ndarray): Array of different colors that should indicate unique components in each segmentation. light_scaling (float): Indicate how much lighter the second component should be scaled in its unique color.

Methods

color_fractions(comparison_image[, colors, ...])

Returns color fractions.

compare_segmentations_binary_array(...)

Compare segmentations pixel-wise.

get_combinations(*segmentation_numbers[, ...])

Returns a list of all possible combinations of segmentations.

plot(image[, figure_name, legend_anchor])

Plots the provided image (should be a comparison of segmentations) with matplotlib.pyplot's imshow and prints a legend with colors from the image and dictionary

plot_overlay_segmentation(comparison_image, ...)

Plots a comparison image overlayed a base image using matplotlib.

color_fractions(comparison_image, colors=None, depth_map=None)[source]#

Returns color fractions.

Parameters:
comparison_imagenp.ndarray

Comparison of segmentations.

colorsnp.ndarray

Array of color values in the comparison image.

depth_mapnp.ndarray, optional

Depth map for the image.

Returns:
(dict): Dictionary relating each color to the fraction of
the number of pixels that the color occupies and the
total number of occupied pixels in the image.
compare_segmentations_binary_array(*segmentations, **kwargs)[source]#

Compare segmentations pixel-wise.

Returns an array whose per-pixel value encodes which segmentations are present at that pixel (as a pattern of 1s and 0s). Different kinds of component are not currently distinguished.

Parameters:
*segmentationsnumpy.ndarray

The segmentations to compare.

**kwargs

"roi" (tuple of slices | ndarray of corner points) – region to compare, in pixel/matrix coordinates; defaults to the largest ROI fitting all segmentations. "components" (tuple of int) – components to recognise; default [1, 2].

get_combinations(*segmentation_numbers, num_segmentations=5)[source]#

Returns a list of all possible combinations of segmentations.

Parameters:
*segmentation_numberstuple[int, …]

The segmentation numbers that should be included in the combinations. Defaults to ().

num_segmentationsint, optional

Number of segmentations. Defaults to 5.

Returns:
list[list[int]]

List of all possible combinations of segmentations.

plot(image, figure_name='Comparison', legend_anchor=(0.7, 1))[source]#

Plots the provided image (should be a comparison of segmentations) with matplotlib.pyplot’s imshow and prints a legend with colors from the image and dictionary

Parameters:
imagenp.ndarray

Image with comparison of segmentations.

figure_namestr

Figure name.

legend_anchortuple

Tuple of coordinates (x,y) in Euclidean style that determines legend anchor.

plot_overlay_segmentation(comparison_image, base_image, figure_name='Comparison', opacity=0.6, legend_anchor=(1.0, 1.0), custom_legend=None, custom_legend_text=None)[source]#

Plots a comparison image overlayed a base image using matplotlib.

Parameters:
comparison_imagenp.ndarray

The image containing comparison of segmentations.

base_imagenp.ndarray

The base image that is to be overlayed.

figure_namestr

Figure name.

opacityfloat

Tha opacity value for the comparison image.

legend_anchortuple

Tuple of coordinates (x,y) in euclidean style that determines legend anchor.

custom_legendOptional[list[mpatches.Patch]]

In case it is desirable to create a custom legend.

custom_legend_textOptional[list[str]]

In case it is desirable to customize legend.