darsia.SegmentationComparison#
- class SegmentationComparison(number_of_segmented_images=2, **kwargs)[source]#
Bases:
objectClass for comparing segmented images.
Routines for comparing segmentations and creating visualizations of the comparison.
- Attributes:
- number_of_segmented_images
int Number of segmented images that one compares.
- segmentation_names
list[str] List of names for each of the segmentations. Will affect legends in plots.
- components
list 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_names
list[str] List of names for each of the components. Will be visual in legends.
- gray_colors
np.ndarray Array of base gray colors (in RGB space) that accounts for different overlapping segmentations of different components.
- colors
np.ndarray Color values for the different unique segmentations. Default is created from a colormap (matplotlib) depending on the amount of present segmentations.
- color_dictionary
dict Dictionary relating all of the different colors to different overlapping segmentation situations.
- number_of_segmented_images
Constructor of compare segmentations class.
- Parameters:
- number_of_segmented_images
int 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.
- number_of_segmented_images
Methods
color_fractions(comparison_image[, colors, ...])Returns color fractions.
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_image
np.ndarray Comparison of segmentations.
- colors
np.ndarray Array of color values in the comparison image.
- depth_map
np.ndarray,optional Depth map for the image.
- comparison_image
- Returns:
- (
dict):Dictionaryrelatingeachcolortothefractionof thenumberofpixelsthatthecoloroccupiesandthetotalnumberofoccupiedpixelsintheimage.
- (
- 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:
- *segmentations
numpy.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].
- *segmentations
- get_combinations(*segmentation_numbers, num_segmentations=5)[source]#
Returns a 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:
- image
np.ndarray Image with comparison of segmentations.
- figure_name
str Figure name.
- legend_anchor
tuple Tuple of coordinates (x,y) in Euclidean style that determines legend anchor.
- image
- 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_image
np.ndarray The image containing comparison of segmentations.
- base_image
np.ndarray The base image that is to be overlayed.
- figure_name
str Figure name.
- opacity
float Tha opacity value for the comparison image.
- legend_anchor
tuple Tuple of coordinates (x,y) in euclidean style that determines legend anchor.
- custom_legend
Optional[list[mpatches.Patch]] In case it is desirable to create a custom legend.
- custom_legend_text
Optional[list[str]] In case it is desirable to customize legend.
- comparison_image