Overview
TheMaskDrawer class implements the MaskDrawerInterface to visualize segmentation masks on images using color-coded overlays with alpha blending. Each trash class is assigned a specific color for easy visual identification.
Class Definition
MaskDrawer
Implements mask visualization with configurable color mapping for different trash classes.Attributes
Color mapping for trash classes:
0:(255, 0, 0)- Red (e.g., plastic)1:(255, 255, 0)- Yellow (e.g., paper)2:(200, 200, 200)- Light gray (e.g., metal)
(255, 255, 255).Methods
draw
Draws segmentation masks on an image with alpha blending.Parameters
Input image in BGR format (OpenCV format). The image will be modified with overlays and contours.
List of segmentation masks. Each mask is a numpy array of polygon coordinates representing the mask boundary.
List of class IDs corresponding to each mask. Used to determine the color from
color_map.Returns
The annotated image with:
- Filled polygon overlays blended at 50% opacity (alpha = 0.5)
- Contour lines drawn with 2px thickness
- Colors based on class IDs from
color_map
Alpha Blending
The drawer uses OpenCV’saddWeighted function to blend the mask overlay with the original image:
alpha = 0.5: 50% of the filled mask overlay1 - alpha = 0.5: 50% of the original image with contours
Usage Example
Interface
MaskDrawerInterface
Abstract base class defining the contract for mask drawing implementations.Color Mapping Reference
| Class ID | Color (BGR) | RGB | Description |
|---|---|---|---|
| 0 | (255, 0, 0) | Blue | First trash class |
| 1 | (255, 255, 0) | Cyan | Second trash class |
| 2 | (200, 200, 200) | Light Gray | Third trash class |
| Other | (255, 255, 255) | White | Default fallback |