robokudo.annotators.cluster_color¶
Robokudo Color Analysis Module
This module provides functionality for semantic color analysis of object hypotheses. It analyzes RGB regions of interest (ROIs) and masks to determine dominant colors using HSV color space segmentation.
Warning
The non-numba version of color counting may contain bugs in color counting.
Classes¶
Enumeration of semantic colors used for classification. |
|
Calculate the semantic color for every Object Hypothesis (cluster) that has a RGB ROI and a Mask. |
Module Contents¶
- class robokudo.annotators.cluster_color.Color¶
-
Bases:
enum.EnumEnumeration of semantic colors used for classification.
Primary colors: RED, GREEN, BLUE
Secondary colors: YELLOW, CYAN, MAGENTA
Grayscale: WHITE, BLACK, GREY
- RED = (0,)¶
- YELLOW = (1,)¶
- GREEN = (2,)¶
- CYAN = (3,)¶
- BLUE = (4,)¶
- MAGENTA = (5,)¶
- WHITE = (6,)¶
- BLACK = (7,)¶
- GREY = (8,)¶
- class robokudo.annotators.cluster_color.ClusterColorAnnotator(name='ClusterColorAnnotator', descriptor=Descriptor())¶
-
Bases:
robokudo.annotators.core.BaseAnnotatorCalculate the semantic color for every Object Hypothesis (cluster) that has a RGB ROI and a Mask.
This annotator analyzes object hypotheses by:
Converting RGB image regions to HSV color space
Using HSV thresholds to classify pixels into semantic color categories
Counting pixel distributions for each color
Annotating objects with their dominant colors
The color classification uses configurable thresholds for:
Hue ranges for primary/secondary colors
Saturation threshold for chromatic colors
Value thresholds for black/white/grey
- class Descriptor¶
-
Bases:
robokudo.annotators.core.BaseAnnotator.DescriptorConfiguration descriptor for the ClusterColorAnnotator.
Defines parameters that control the color analysis behavior:
Number of color divisions in hue space
Thresholds for color classification
Minimum ratio for color annotation
- class Parameters¶
-
Parameters for color analysis configuration.
- num_of_colors = 6¶
- color_range = 42.666666666666664¶
- jit_compile_on_init = False¶
- min_value_color = 60¶
- min_saturation_color = 60¶
- max_value_black = 60¶
- min_value_white = 120¶
- ratio_annotation_threshold = 0.2¶
- analysis_scope¶
- parameters¶
- color_name_to_bgr_values¶
- color_hue_positions¶
- cluster_color_info = []¶
- cluster_rois = []¶
- count_colors_numba(hsv_image: numpy.typing.NDArray, mask: numpy.typing.NDArray)¶
-
Wrapper function for the numba version of the count colors method.
The wrapper handles the pythonic/object style data and prepares everything for the requirements of the numba method.
- Parameters:
-
hsv_image (numpy.ndarray) – Image in HSV color space
mask (numpy.ndarray) – Binary mask indicating pixels to analyze
- Returns:
-
A tuple with the number of analyzed pixels (given by the mask) as well as a dict with the counted colors. The key is a Color enum from this module.
- Return type:
-
tuple(int, dict)
- static count_colors_numba_impl(hsv_image: numpy.typing.NDArray, mask: numpy.typing.NDArray, total_amount_of_colors: int, min_saturation_color: int, min_value_color: int, max_value_black: int, min_value_white: int, number_of_colors: int, color_range: float)¶
-
Iterate over the masked pixels on a given hsv image to count how many pixels can be assigned to the defined color ranges. Requires the numba library and passes the required parameters to avoid class access and object-mode from numba.
- Parameters:
-
hsv_image (numpy.ndarray) – Image in HSV color space
mask (numpy.ndarray) – Binary mask indicating pixels to analyze
total_amount_of_colors (int) – Total number of color categories
min_saturation_color (int) – Minimum saturation for chromatic colors
min_value_color (int) – Minimum value for chromatic colors
max_value_black (int) – Maximum value for black classification
min_value_white (int) – Minimum value for white classification
number_of_colors (int) – Number of hue divisions
color_range (float) – Size of each hue division
- Returns:
-
A tuple with the number of analyzed pixels (given by the mask) as well as a numpy array with the counted colors. The id refers the indices of the Color enum from this module.
- Return type:
-
tuple(int, numpy.ndarray)
- count_colors(hsv_image: numpy.typing.NDArray, mask: numpy.typing.NDArray)¶
-
Non-numba version of the count_colors_numba_impl method. Use only if you can’t use numba.
Warning
Seems to contain a bug in color counting.
- Parameters:
-
hsv_image (numpy.ndarray) – Image in HSV color space
mask (numpy.ndarray) – Binary mask indicating pixels to analyze
- Returns:
-
A tuple with the number of analyzed pixels and a dict with color counts
- Return type:
-
tuple(int, dict)
- update()¶
-
Process current scene to analyze colors of object hypotheses.
Steps:
Gets current point cloud and color image
Creates color annotations for each object hypothesis
Updates visualization with color information
Prepares 3D visualization geometries
- Returns:
-
SUCCESS after processing is complete
- Return type:
-
py_trees.Status
- create_color_annotations(color)¶
-
Create color annotations for all object hypotheses.
For each object hypothesis with a valid ROI mask:
Extract color image region and mask
Convert to HSV color space
Count pixel colors using numba-optimized implementation
Sort colors by frequency
Add color annotations for colors above ratio threshold
Store color information for visualization
- Parameters:
-
color (numpy.ndarray) – Input color image
- draw_visualization(visualization_img)¶
-
Draw visualization of detected colors on the image.
For each ROI:
Draw bounding box in dominant color
Add text label with ROI index and dominant color name
Create color histogram showing distribution of detected colors
- Parameters:
-
visualization_img (numpy.ndarray) – Image to draw visualization on
- Returns:
-
Image with visualization overlays
- Return type:
-
numpy.ndarray