@rosepetal/node-red-contrib-image-tools 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/workflows/build-prebuild.yml +326 -0
  3. package/LICENSE +13 -0
  4. package/README.md +161 -0
  5. package/artifacts/darwin-arm64/package.json +25 -0
  6. package/artifacts/linux-arm64/package.json +26 -0
  7. package/artifacts/linux-x64/package.json +26 -0
  8. package/artifacts/linuxmusl-x64/package.json +26 -0
  9. package/assets/flow_time_example.gif +0 -0
  10. package/assets/nodes/io/array-in-demo.gif +0 -0
  11. package/assets/nodes/io/array-out-demo.gif +0 -0
  12. package/assets/nodes/io/array-select-demo.gif +0 -0
  13. package/assets/nodes/io/image-in-demo.gif +0 -0
  14. package/assets/nodes/mix/concat-demo.gif +0 -0
  15. package/assets/nodes/mix/mosaic-demo.gif +0 -0
  16. package/assets/nodes/transform/crop-demo.gif +0 -0
  17. package/assets/nodes/transform/filter-demo.gif +0 -0
  18. package/assets/nodes/transform/padding-demo.gif +0 -0
  19. package/assets/nodes/transform/resize-demo.gif +0 -0
  20. package/assets/nodes/transform/rotate-demo.gif +0 -0
  21. package/docs/nodes/blend/add-mask.md +275 -0
  22. package/docs/nodes/blend/add-masks.md +284 -0
  23. package/docs/nodes/blend/blend.md +248 -0
  24. package/docs/nodes/io/array-in.md +119 -0
  25. package/docs/nodes/io/array-out.md +150 -0
  26. package/docs/nodes/io/array-select.md +157 -0
  27. package/docs/nodes/io/image-in.md +131 -0
  28. package/docs/nodes/io/image-out.md +179 -0
  29. package/docs/nodes/io/queue.md +57 -0
  30. package/docs/nodes/io/save-file.md +30 -0
  31. package/docs/nodes/mix/advanced-mosaic.md +108 -0
  32. package/docs/nodes/mix/concat.md +127 -0
  33. package/docs/nodes/mix/mosaic.md +146 -0
  34. package/docs/nodes/specialized/cropBB.md +271 -0
  35. package/docs/nodes/specialized/image-align.md +426 -0
  36. package/docs/nodes/transform/crop.md +132 -0
  37. package/docs/nodes/transform/draw.md +77 -0
  38. package/docs/nodes/transform/filter.md +84 -0
  39. package/docs/nodes/transform/padding.md +133 -0
  40. package/docs/nodes/transform/resize.md +158 -0
  41. package/docs/nodes/transform/rotate.md +121 -0
  42. package/docs/nodes/util/block-detect.md +46 -0
  43. package/install.sh +144 -0
  44. package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
  45. package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
  46. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
  47. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
  48. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
  49. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
  50. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
  51. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
  52. package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
  53. package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
  54. package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
  55. package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
  56. package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
  57. package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
  58. package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
  59. package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
  60. package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
  61. package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
  62. package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
  63. package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
  64. package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
  65. package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
  66. package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
  67. package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
  68. package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
  69. package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
  70. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
  71. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
  72. package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
  73. package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
  74. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
  75. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
  76. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
  77. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
  78. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
  79. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
  80. package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
  81. package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
  82. package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
  83. package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
  84. package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
  85. package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
  86. package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
  87. package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
  88. package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
  89. package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
  90. package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
  91. package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
  92. package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
  93. package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
  94. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
  95. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
  96. package/node-red-contrib-image-tools/package.json +64 -0
  97. package/npm/darwin-arm64/lib/.gitkeep +1 -0
  98. package/npm/darwin-arm64/package.json +25 -0
  99. package/npm/darwin-x64/lib/.gitkeep +1 -0
  100. package/npm/darwin-x64/package.json +25 -0
  101. package/npm/linux-arm64/lib/.gitkeep +1 -0
  102. package/npm/linux-arm64/package.json +26 -0
  103. package/npm/linux-x64/lib/.gitkeep +1 -0
  104. package/npm/linux-x64/package.json +26 -0
  105. package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
  106. package/npm/linuxmusl-x64/package.json +26 -0
  107. package/npm/win32-x64/lib/.gitkeep +1 -0
  108. package/npm/win32-x64/package.json +25 -0
  109. package/package.json +74 -0
  110. package/rosepetal-image-engine/binding.gyp +153 -0
  111. package/rosepetal-image-engine/package.json +19 -0
  112. package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
  113. package/rosepetal-image-engine/src/add-mask.cpp +240 -0
  114. package/rosepetal-image-engine/src/add-masks.cpp +638 -0
  115. package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
  116. package/rosepetal-image-engine/src/blend.cpp +200 -0
  117. package/rosepetal-image-engine/src/concat.cpp +329 -0
  118. package/rosepetal-image-engine/src/crop.cpp +139 -0
  119. package/rosepetal-image-engine/src/draw.cpp +414 -0
  120. package/rosepetal-image-engine/src/filter.cpp +230 -0
  121. package/rosepetal-image-engine/src/filters/kernels.h +171 -0
  122. package/rosepetal-image-engine/src/image-align.cpp +551 -0
  123. package/rosepetal-image-engine/src/main.cpp +36 -0
  124. package/rosepetal-image-engine/src/mosaic.cpp +373 -0
  125. package/rosepetal-image-engine/src/padding.cpp +124 -0
  126. package/rosepetal-image-engine/src/resize.cpp +210 -0
  127. package/rosepetal-image-engine/src/rotate.cpp +177 -0
  128. package/rosepetal-image-engine/src/utils.h +563 -0
  129. package/rosepetal-image-engine/test-formats.js +119 -0
  130. package/scripts/build-opencv-static.ps1 +166 -0
  131. package/scripts/build-opencv-static.sh +147 -0
@@ -0,0 +1,275 @@
1
+ # Add-Mask Node
2
+
3
+ ## Purpose & Use Cases
4
+
5
+ The `add-mask` node applies polygon-based masks to images using coordinate arrays to define masked regions. It creates weighted blending effects within polygon boundaries, perfect for selective image modifications and region-based processing from AI detection or manual selection.
6
+
7
+ **Real-World Applications:**
8
+ - **AI Object Masking**: Apply masks from AI detection results with polygon coordinates
9
+ - **ROI Processing**: Highlight or modify regions of interest defined by coordinate boundaries
10
+ - **Selective Enhancement**: Apply effects only within specific geometric areas
11
+ - **Quality Control**: Overlay inspection results on products using detected boundaries
12
+ - **Medical Analysis**: Highlight detected anomalies or structures with polygon masks
13
+
14
+ *[PLACEHOLDER - Add GIF showing various masking operations including product cutouts and artistic effects]*
15
+
16
+ ## Input/Output Specification
17
+
18
+ ### Inputs
19
+ - **Base Image**: The image to which the polygon mask will be applied
20
+ - **Polygon Coordinates**: Array of [x, y] coordinate pairs defining mask boundary
21
+ - **Mask Parameters**: Strength and fill color via configuration
22
+
23
+ ### Outputs
24
+ - **Masked Image**: Original image with weighted blending applied within polygon area
25
+ - **Selective Processing**: Areas within polygon receive mask treatment based on strength setting
26
+ - **Format Options**: Raw image object or encoded file formats
27
+
28
+ ## Configuration Options
29
+
30
+ ### Input Paths
31
+ - **Image Path**: Location of base image to mask (default: `msg.payload.image`)
32
+ - **Polygon Path**: Location of coordinate array (default: `msg.payload.default.masks[0].mask[0]`)
33
+ - **Path Sources**: `msg.*`, `flow.*`, `global.*`
34
+
35
+ ### Output Configuration
36
+ - **Output Path**: Where to store masked result (default: `msg.payload`)
37
+ - **Output Format**: Raw, JPEG, PNG, WebP
38
+ - **Quality Settings**: Compression settings for lossy formats
39
+
40
+ ### Polygon Mask Options
41
+
42
+ #### Coordinate System
43
+ - **Normalized Coordinates**: All coordinates must be in range [0, 1]
44
+ - **Format**: Array of [x, y] pairs: `[[x1,y1], [x2,y2], [x3,y3], ...]`
45
+ - **Relative Positioning**: 0.0 = left/top edge, 1.0 = right/bottom edge
46
+
47
+ #### Mask Strength
48
+ - **Range**: 0-100% (0 = no effect, 100 = maximum blending)
49
+ - **Default**: 50% for balanced effect
50
+ - **Purpose**: Controls intensity of mask blending within polygon
51
+
52
+ #### Fill Color
53
+ - **Format**: Hex color code (e.g., `#FF0000` for red)
54
+ - **Default**: White (`#FFFFFF`)
55
+ - **Purpose**: Color used for blending within masked polygon area
56
+
57
+ ### Output Format Options
58
+ - **Raw**: Standard image object with alpha channel
59
+ - **PNG**: Full transparency preservation (recommended)
60
+ - **WebP**: Modern format with transparency support
61
+ - **JPEG**: Not recommended (transparency becomes background color)
62
+
63
+ ## Performance Notes
64
+
65
+ ### C++ Backend Processing
66
+ - **Optimized Alpha Processing**: Fast alpha channel manipulation
67
+ - **Edge Smoothing**: High-quality anti-aliasing for smooth mask edges
68
+ - **Memory Efficient**: Direct alpha channel writing without full image copying
69
+ - **Format Handling**: Proper handling of different input mask formats
70
+
71
+ ### Mask Processing Algorithms
72
+ - **Grayscale Conversion**: Efficient luminance-to-alpha conversion
73
+ - **Edge Detection**: Smart edge smoothing for professional results
74
+ - **Threshold Processing**: Fast binary mask generation when needed
75
+
76
+ ## Real-World Examples
77
+
78
+ ### AI Object Detection Highlighting
79
+ ```javascript
80
+ // AI detection provides polygon coordinates
81
+ msg.detectedObjects[0] = {
82
+ polygon: [[0.1, 0.2], [0.8, 0.2], [0.8, 0.7], [0.1, 0.7]],
83
+ confidence: 0.95
84
+ };
85
+ msg.payload.image = originalImage;
86
+ msg.payload.default.masks[0].mask[0] = msg.detectedObjects[0].polygon;
87
+ ```
88
+ ```
89
+ [Image + AI Polygons] → [Add-Mask: 30% red overlay] → [Highlighted Detections]
90
+ ```
91
+
92
+ ### Quality Control ROI
93
+ ```javascript
94
+ // Define inspection region
95
+ msg.inspectionRegion = [
96
+ [0.25, 0.25], [0.75, 0.25],
97
+ [0.75, 0.75], [0.25, 0.75]
98
+ ];
99
+ ```
100
+ ```
101
+ [Product Image] → [Function: Set ROI] → [Add-Mask: 50% yellow] → [Inspection Overlay]
102
+ ```
103
+
104
+ ### Medical Annotation
105
+ ```javascript
106
+ // Radiologist defined region
107
+ msg.anomalyRegion = [
108
+ [0.4, 0.3], [0.6, 0.3], [0.65, 0.5],
109
+ [0.6, 0.7], [0.4, 0.7], [0.35, 0.5]
110
+ ];
111
+ ```
112
+ ```
113
+ [Medical Scan] → [Function: Set Polygon] → [Add-Mask: 40% red] → [Annotated Scan]
114
+ ```
115
+
116
+ ### Custom Selection Processing
117
+ ```javascript
118
+ // User-defined polygon selection
119
+ msg.userSelection = [
120
+ [0.0, 0.0], [1.0, 0.0], [1.0, 0.5], [0.0, 0.5]
121
+ ]; // Top half of image
122
+ ```
123
+ ```
124
+ [Image] → [Function: Set Selection] → [Add-Mask: 70% blue tint] → [Selective Processing]
125
+ ```
126
+
127
+ ### Batch Region Processing
128
+ ```
129
+ [Image Array] → [AI Detection] → [Extract Polygons] → [Add-Mask: Highlight] → [Processed Results]
130
+ ```
131
+ Process multiple images with AI-detected regions.
132
+
133
+ ## Common Issues & Troubleshooting
134
+
135
+ ### Invalid Polygon Coordinates
136
+ - **Issue**: Error messages about invalid coordinate format or ranges
137
+ - **Solution**: Ensure coordinates are arrays of [x,y] pairs with values in [0,1] range
138
+ - **Format**: `[[0.1,0.2], [0.8,0.2], [0.8,0.7], [0.1,0.7]]`
139
+
140
+ ### Empty or Missing Polygons
141
+ - **Issue**: No masking effect applied to image
142
+ - **Solution**: Verify polygon path contains valid coordinate array
143
+ - **Check**: Ensure polygon array is not empty and coordinates are properly formatted
144
+
145
+ ### Polygon Outside Image Bounds
146
+ - **Issue**: Mask effect not visible or only partially applied
147
+ - **Cause**: Polygon coordinates outside [0,1] normalized range
148
+ - **Solution**: Validate all coordinates are between 0.0 and 1.0
149
+
150
+ ### Incorrect Path Configuration
151
+ - **Issue**: Node cannot find image or polygon data
152
+ - **Solution**: Verify input paths match your message structure
153
+ - **Default Paths**: `msg.payload.image` and `msg.payload.default.masks[0].mask[0]`
154
+
155
+ ### Weak or Invisible Mask Effects
156
+ - **Issue**: Mask blending barely visible on image
157
+ - **Solution**: Increase mask strength percentage or adjust fill color contrast
158
+ - **Optimization**: Use colors that contrast well with image content
159
+
160
+ ## Integration Patterns
161
+
162
+ ### E-commerce Product Processing
163
+ ```
164
+ Product Photo → Background Detection → Generate Mask → Add-Mask → Clean Cutout
165
+ ```
166
+ Automated product cutout generation for online catalogs.
167
+
168
+ ### Portrait Enhancement Workflow
169
+ ```
170
+ Portrait → Create Vignette → Add-Mask → Color Enhancement → Artistic Portrait
171
+ ```
172
+ Professional portrait processing with masking effects.
173
+
174
+ ### Logo Production Pipeline
175
+ ```
176
+ Design → Shape Creation → Mask Generation → Add-Mask → Export Formats
177
+ ```
178
+ Convert solid designs into transparent logo formats.
179
+
180
+ ### Medical Analysis Pipeline
181
+ ```
182
+ Scan → Region Detection → Mask Creation → Add-Mask → Analysis → Report
183
+ ```
184
+ Medical imaging analysis with region masking.
185
+
186
+ ## Advanced Usage
187
+
188
+ ### Dynamic Mask Creation
189
+ ```javascript
190
+ // Generate circular mask based on image dimensions
191
+ const width = msg.image.width;
192
+ const height = msg.image.height;
193
+ const radius = Math.min(width, height) / 3;
194
+
195
+ msg.maskType = 'circular';
196
+ msg.maskRadius = radius;
197
+ msg.maskCenter = { x: width/2, y: height/2 };
198
+ ```
199
+
200
+ ### Conditional Mask Processing
201
+ ```javascript
202
+ // Apply different mask processing based on image type
203
+ if (msg.imageType === 'product') {
204
+ msg.maskInversion = false;
205
+ msg.smoothEdges = true;
206
+ msg.featherAmount = 2;
207
+ } else if (msg.imageType === 'portrait') {
208
+ msg.maskInversion = true; // Vignette mask
209
+ msg.smoothEdges = true;
210
+ msg.featherAmount = 5;
211
+ }
212
+ ```
213
+
214
+ ### Quality-Based Processing
215
+ ```javascript
216
+ // Adjust processing based on output requirements
217
+ if (msg.outputUse === 'web') {
218
+ msg.outputFormat = 'webp';
219
+ msg.featherAmount = 1; // Minimal feathering for web
220
+ } else if (msg.outputUse === 'print') {
221
+ msg.outputFormat = 'png';
222
+ msg.featherAmount = 3; // More feathering for print
223
+ msg.smoothEdges = true;
224
+ }
225
+ ```
226
+
227
+ ### Batch Mask Application
228
+ ```javascript
229
+ // Apply same mask to multiple images
230
+ msg.images.forEach((img, index) => {
231
+ img.maskSettings = {
232
+ invert: false,
233
+ smooth: true,
234
+ feather: 2
235
+ };
236
+ });
237
+ ```
238
+
239
+ ## Best Practices
240
+
241
+ ### Mask Creation
242
+ - Create masks at same resolution as target images for best quality
243
+ - Use soft brushes or gradients for smooth edge transitions
244
+ - Test masks with sample images before batch processing
245
+ - Save masks as high-quality grayscale or alpha channel images
246
+
247
+ ### Edge Quality
248
+ - Enable smooth edges for professional results
249
+ - Use appropriate feathering amounts (1-3 pixels for web, 2-5 for print)
250
+ - Consider anti-aliasing requirements for your final output
251
+ - Test edge quality at actual display size
252
+
253
+ ### Format Selection
254
+ - **PNG**: Best for transparency preservation and quality
255
+ - **WebP**: Good compression with transparency support
256
+ - **Raw**: For continued processing chains
257
+ - **Avoid JPEG**: For images requiring transparency
258
+
259
+ ### Performance Optimization
260
+ - Use appropriately sized masks (don't oversample)
261
+ - Process masks separately from color correction when possible
262
+ - Use raw format for processing chains
263
+ - Consider memory usage with large high-resolution images
264
+
265
+ ### Quality Considerations
266
+ - Match mask resolution to target image resolution
267
+ - Use high-quality source masks without compression artifacts
268
+ - Test transparency results in final display context
269
+ - Consider edge quality requirements for intended use
270
+
271
+ ### Production Workflow
272
+ - Maintain original images before masking
273
+ - Create standardized mask templates for consistent results
274
+ - Implement quality checks for edge smoothness
275
+ - Document mask settings for reproducible results
@@ -0,0 +1,284 @@
1
+ # add-masks
2
+
3
+ Applies multiple polygon-based masks to a base image using weighted blending with configurable mask strength and class-based color mapping.
4
+
5
+ ## Description
6
+
7
+ The `add-masks` node extends the functionality of `add-mask` to handle multiple masks with automatic color assignment based on class names. It processes arrays of mask objects where each mask can have a different color based on its `class_name` property. Undefined classes can automatically receive randomly generated colors for visual distinction.
8
+
9
+ This node is ideal for visualizing object detection results, semantic segmentation, or any scenario where multiple regions need to be highlighted with different colors based on their classification.
10
+
11
+ ## Input Structure
12
+
13
+ The node consumes an array of mask objects. It now accepts the exact segmentation output produced by the Rosepetal **inferencer** node (no manual conversion required):
14
+
15
+ - **Class name**: `tag`, `class_name`, `className`, `label`, or `class`
16
+ - **Geometry** (one of):
17
+ - `polygons`: array of polygons; each polygon is an array of `[x, y]` points in **normalized** coordinates (0‑1)
18
+ - `mask`: either a raw mask image `{data, width, height, channels, colorSpace, dtype}` (inferencer “mask” format) or a 2D matrix/array-of-matrices with numeric values (0/1 or 0‑255)
19
+ - Any extra fields are ignored. If both `polygons` and `mask` exist, polygons take priority.
20
+
21
+ **Example (direct inferencer output)**
22
+ ```javascript
23
+ msg.payload = [
24
+ {
25
+ tag: "bottle",
26
+ polygons: [[[0.1, 0.1], [0.9, 0.1], [0.9, 0.8], [0.1, 0.8]]]
27
+ },
28
+ {
29
+ class_name: "person",
30
+ mask: {
31
+ width: 512,
32
+ height: 512,
33
+ channels: 4,
34
+ colorSpace: "RGBA",
35
+ dtype: "uint8",
36
+ data: <Buffer ...>
37
+ }
38
+ }
39
+ ];
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ ### Paths
45
+ - **Image**: Message property path containing the base image (default: `payload.image`)
46
+ - **Masks Array**: Message property path containing the masks array (default: `payload`)
47
+ - **Output**: Message property path for the result (default: `payload`)
48
+
49
+ ### Processing Options
50
+ - **Global Mask Strength**: 0-100% intensity of mask application (default: 50%)
51
+ - **Output Format**: Raw (fastest), JPEG, PNG, or WebP
52
+ - **Quality**: Compression quality for JPEG/WebP (1-100)
53
+
54
+ ### Dynamic Class Color Mapping
55
+
56
+ The node provides a dynamic interface for managing class-to-color mappings:
57
+
58
+ #### Features:
59
+ - **Add/Remove Mappings**: Dynamic addition and removal of class color pairs
60
+ - **Real-time Validation**:
61
+ - Duplicate class name detection
62
+ - Similar color warnings (RGB distance < 50)
63
+ - **Visual Feedback**: Color swatches and warning indicators
64
+
65
+ #### Usage:
66
+ 1. Click "Add Class Mapping" to create new entries
67
+ 2. Enter class name (e.g., "dog", "cat", "zebra")
68
+ 3. Select desired color using color picker
69
+ 4. Remove unwanted mappings with trash button
70
+
71
+ ## Color Assignment Priority
72
+
73
+ Colors are assigned using this priority order:
74
+
75
+ 1. **User-defined mapping**: Colors explicitly set in the class color mappings
76
+ 2. **Auto-generated**: Seeded random colors (always enabled)
77
+ 3. **Default fallback**: White color (#ffffff)
78
+
79
+ ## Mask Priority System
80
+
81
+ When multiple masks overlap on the same pixel, only **one mask is painted** based on priority order.
82
+
83
+ ### Priority Rules
84
+
85
+ 1. **Class Color Mappings Priority**: Classes listed first in the "Class Color Mappings"
86
+ configuration have higher priority. Drag rows to reorder.
87
+
88
+ 2. **Unmapped Class Tie-breaking**: If neither overlapping mask has a class defined
89
+ in the mappings, the mask that appears first in the input results array wins.
90
+
91
+ 3. **Mixed Priority**: Mapped classes always take priority over unmapped classes.
92
+
93
+ ### Example
94
+
95
+ Configuration:
96
+ ```
97
+ Class Color Mappings (drag to reorder):
98
+ 1. "person" → #FF0000 (red) ← Highest priority
99
+ 2. "car" → #00FF00 (green)
100
+ 3. "dog" → #0000FF (blue) ← Lowest mapped priority
101
+ ```
102
+
103
+ If a pixel is covered by both "person" and "car" masks, only the **red (person)**
104
+ color will be painted.
105
+
106
+ If a pixel is covered by "cat" and "bird" (both unmapped), the one appearing
107
+ first in the input array will be painted.
108
+
109
+ ### Reordering Classes
110
+
111
+ In the Node-RED editor:
112
+ 1. Click and drag the ☰ handle next to any class row
113
+ 2. Drop it in the desired position
114
+ 3. Top = highest priority, bottom = lowest priority
115
+
116
+ ## Processing Flow
117
+
118
+ 1. **Structure Validation**: Validates the nested array structure
119
+ 2. **Color Resolution**: Builds color map from configuration and auto-generation
120
+ 3. **Mask Generation**: Creates binary masks for each polygon using OpenCV
121
+ 4. **Multi-layer Blending**: Applies all masks with proper weight normalization
122
+ 5. **Output Encoding**: Converts to specified format with quality settings
123
+
124
+ ## Examples
125
+
126
+ ### Basic Object Detection Visualization
127
+
128
+ **Input:**
129
+ ```javascript
130
+ msg.payload = [
131
+ {
132
+ masks: [
133
+ {
134
+ mask: [[[0.1,0.1], [0.3,0.1], [0.3,0.3], [0.1,0.3]]],
135
+ class_name: "dog"
136
+ },
137
+ {
138
+ mask: [[[0.5,0.5], [0.7,0.5], [0.7,0.7], [0.5,0.7]]],
139
+ class_name: "cat"
140
+ }
141
+ ]
142
+ }
143
+ ];
144
+ ```
145
+
146
+ **Configuration:**
147
+ - dog → Red (#FF0000)
148
+ - cat → Blue (#0000FF)
149
+ - Global Mask Strength: 70%
150
+
151
+ **Result:** Image with red rectangle for dog and blue rectangle for cat
152
+
153
+ ### Semantic Segmentation with Auto-Colors
154
+
155
+ **Input:** Multiple elements with various class names
156
+
157
+ **Configuration:**
158
+ - Only define colors for important classes
159
+ - System automatically generates colors for others
160
+
161
+ **Result:** Consistent coloring with user-defined colors for key classes and auto-generated colors for others
162
+
163
+ ## Performance Characteristics
164
+
165
+ ### Optimizations
166
+ - **C++ Backend**: OpenCV-powered processing with SIMD optimizations
167
+ - **Batch Processing**: All masks processed in single C++ call
168
+ - **Weight Normalization**: Prevents over-saturation when masks overlap
169
+ - **Memory Efficiency**: Reuses intermediate buffers across masks
170
+
171
+ ### Timing Breakdown
172
+ Status displays show detailed timing:
173
+ - **Convert**: Time for input validation and format conversion
174
+ - **Task**: Time for mask generation and blending in C++
175
+ - **Encode**: Time for output format encoding (if not raw)
176
+
177
+ ## Error Handling
178
+
179
+ ### Input Validation
180
+ - **Structure validation**: Comprehensive checking of nested array format
181
+ - **Coordinate validation**: Ensures normalized range (0-1) for all coordinates
182
+ - **Class name validation**: Checks for non-empty string class names
183
+ - **Missing mask[0]**: Specific error for missing coordinate arrays
184
+
185
+ ### Visual Feedback
186
+ - **Duplicate class warnings**: Real-time detection of duplicate class names
187
+ - **Color conflict warnings**: Alerts for visually similar colors
188
+ - **Processing status**: Shows number of masks processed and timing
189
+
190
+ ## Advanced Features
191
+
192
+ ### HSV-Based Color Generation
193
+ Auto-generated colors use HSV color space for better visual distinction:
194
+ - **Seeded randomization**: Consistent colors based on class name hash
195
+ - **Optimal distribution**: 70-100% saturation and value for vibrant colors
196
+ - **Visual separation**: Automatic spacing for distinguishable colors
197
+
198
+ ### Multi-mask Blending Algorithm
199
+ ```
200
+ For each mask:
201
+ 1. Generate binary mask from polygon coordinates
202
+ 2. Apply mask strength weighting
203
+ 3. Accumulate color contributions and total weights
204
+
205
+ Final blending:
206
+ result = image × (1 - total_weights) + normalized_mask_colors
207
+ ```
208
+
209
+ ### Overlap Handling
210
+ When masks overlap, the **highest priority mask wins** and paints the pixel:
211
+ - Priority determined by order in Class Color Mappings (first = highest)
212
+ - Unmapped classes have lower priority than mapped classes
213
+ - Among unmapped classes, input array order determines priority
214
+ - Alpha blending still applies: `result = original × (1 - strength) + mask_color × strength`
215
+
216
+ ## Integration Patterns
217
+
218
+ ### With Object Detection Models
219
+ ```javascript
220
+ // Convert model output to expected format
221
+ const masks = detectionResults.map(detection => ({
222
+ masks: [{
223
+ mask: [detection.polygon],
224
+ class_name: detection.class
225
+ }]
226
+ }));
227
+
228
+ msg.payload = masks;
229
+ ```
230
+
231
+ ### With Semantic Segmentation
232
+ ```javascript
233
+ // Process segmentation masks
234
+ const masks = segmentationRegions.map(region => ({
235
+ masks: [{
236
+ mask: [region.contour],
237
+ class_name: region.label
238
+ }]
239
+ }));
240
+ ```
241
+
242
+ ### Chaining with Other Nodes
243
+ - **Upstream**: Works with `cropBB`, AI model outputs, or manual annotation tools
244
+ - **Downstream**: Connect to `image-out`, display components, or further processing
245
+ - **Flow integration**: Supports flow and global context for color persistence
246
+
247
+ ## Troubleshooting
248
+
249
+ ### Common Issues
250
+
251
+ **"Invalid element structure"**
252
+ - Check that each array element has `masks` property
253
+ - Ensure `masks` is an array, not an object
254
+
255
+ **"Missing mask[0]"**
256
+ - Verify that coordinates are in `mask[0]`, not directly in `mask`
257
+ - Check that `mask` array is not empty
258
+
259
+ **"Coordinates out of range"**
260
+ - Ensure all coordinates are normalized (0.0-1.0)
261
+ - Convert pixel coordinates to normalized before input
262
+
263
+ **"Duplicate class warnings"**
264
+ - Review class mappings for exact duplicates
265
+ - Consider using more specific class names
266
+
267
+ ### Performance Tips
268
+ - Use raw format for processing chains (fastest)
269
+ - Define colors for frequently used classes to avoid repeated generation
270
+ - Monitor timing display to identify bottlenecks
271
+ - Process smaller images for real-time applications
272
+
273
+ ## Node Interactions
274
+
275
+ ### Compatible Nodes
276
+ - **Input sources**: `image-in`, `cropBB`, AI/ML model outputs
277
+ - **Output destinations**: `image-out`, `concat`, display nodes
278
+ - **Processing chains**: Can be chained with other blending nodes
279
+ - **Context sharing**: Supports Node-RED flow and global context
280
+
281
+ ### Flow Patterns
282
+ - **Batch processing**: Process multiple images with same color mapping
283
+ - **Interactive visualization**: Real-time mask overlay for user interfaces
284
+ - **Analysis pipelines**: Combine with other image processing for complex workflows