@rosepetal/node-red-contrib-image-tools 1.7.0 → 1.8.1
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.
- package/.github/workflows/build-prebuild.yml +1 -1
- package/README.md +39 -21
- package/docs/index.md +156 -0
- package/docs/nodes/blend/add-bbs.md +116 -0
- package/docs/nodes/blend/add-mask.md +67 -224
- package/docs/nodes/blend/add-masks.md +74 -196
- package/docs/nodes/blend/blend.md +84 -200
- package/docs/nodes/io/folder-in.md +92 -0
- package/docs/nodes/io/image-in.md +61 -52
- package/docs/nodes/io/image-out.md +114 -93
- package/docs/nodes/mix/advanced-mosaic.md +124 -78
- package/docs/nodes/mix/concat.md +71 -56
- package/docs/nodes/mix/mosaic.md +81 -91
- package/docs/nodes/specialized/cropBB.md +76 -214
- package/docs/nodes/specialized/heat-diff.md +111 -0
- package/docs/nodes/specialized/image-align.md +125 -387
- package/docs/nodes/transform/color-convert.md +101 -0
- package/docs/nodes/transform/crop.md +56 -58
- package/docs/nodes/transform/draw.md +46 -26
- package/docs/nodes/transform/filter.md +110 -46
- package/docs/nodes/transform/padding.md +55 -55
- package/docs/nodes/transform/resize.md +81 -56
- package/docs/nodes/transform/rotate.md +67 -50
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +11 -4
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +2 -1
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64/package.json +1 -1
- package/npm/linux-x64/package.json +1 -1
- package/npm/linuxmusl-x64/package.json +1 -1
- package/npm/win32-x64/package.json +1 -1
- package/package.json +6 -6
- package/rosepetal-image-engine/src/heat-diff.cpp +4 -0
- package/rosepetal-image-engine/src/image-align.cpp +71 -3
- package/scripts/build-opencv-static.sh +6 -0
|
@@ -1,275 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Add-Mask Node - Polygon Mask Overlay"
|
|
3
|
+
description: "Blend a polygon mask over an image in Node-RED from normalized polygon coordinates, with a fill color and a mask strength. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, add-mask, polygon mask, overlay, segmentation, region of interest, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Add-Mask Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Blend a polygon mask over an image in Node-RED from normalized polygon coordinates, with a fill color and a mask strength."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Add-Mask Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `add-mask` node
|
|
20
|
+
The `add-mask` node tints the inside of one polygon on an image: within the polygon, the image is mixed with a fill colour by a mask strength. The polygon is given in normalized coordinates, as segmentation models return it. For several polygons coloured by class, use [add-masks](./add-masks.md).
|
|
6
21
|
|
|
7
22
|
**Real-World Applications:**
|
|
8
|
-
- **
|
|
9
|
-
- **ROI
|
|
10
|
-
- **
|
|
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]*
|
|
23
|
+
- **Segmentation Display**: Show the region a model found on the original image
|
|
24
|
+
- **ROI Highlighting**: Mark the region of interest of an inspection
|
|
25
|
+
- **Quality Control**: Overlay a detected defect area on the product image
|
|
15
26
|
|
|
16
27
|
## Input/Output Specification
|
|
17
28
|
|
|
18
29
|
### Inputs
|
|
19
|
-
- **
|
|
20
|
-
- **Polygon
|
|
21
|
-
-
|
|
30
|
+
- **Image**: the base image, read from `msg.payload.image` by default: a raw image object or an encoded JPEG/PNG/WebP/BMP `Buffer`
|
|
31
|
+
- **Polygon Path**: one polygon, read from `msg.payload.default.masks[0].mask[0]` by default: an array of `[x, y]` pairs with values from 0 to 1
|
|
32
|
+
- Only `msg` properties are read: the editor also offers `flow` and `global`, but the node reads the typed text as a `msg` path
|
|
22
33
|
|
|
23
34
|
### Outputs
|
|
24
|
-
|
|
25
|
-
- **
|
|
26
|
-
-
|
|
35
|
+
One output:
|
|
36
|
+
- **Masked Image**: written to the `msg` property **Output** (`msg.payload` by default), with the size and color space of the input, as a raw image object or an encoded `Buffer` (JPEG/PNG/WebP)
|
|
37
|
+
- `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds
|
|
27
38
|
|
|
28
39
|
## Configuration Options
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
| Property | Default | Meaning |
|
|
42
|
+
|----------|---------|---------|
|
|
43
|
+
| Image | `msg.payload.image` | Base image |
|
|
44
|
+
| Polygon Path | `msg.payload.default.masks[0].mask[0]` | The polygon |
|
|
45
|
+
| Output | `msg.payload` | Where the result is written |
|
|
46
|
+
| Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP, with Quality (`90`), PNG Optimize and the WebP options as in [resize](../transform/resize.md#output-format-options) |
|
|
47
|
+
| Debug / Debug Width | off / `200` | **Show processed image** under the node in the editor |
|
|
48
|
+
| Mask Strength | `50` | 0-100 %: weight of the fill colour inside the polygon |
|
|
49
|
+
| Fill Color | `#ffffff` | Colour mixed into the polygon |
|
|
34
50
|
|
|
35
|
-
|
|
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
|
|
51
|
+
The editor has no Name field for this node, so its timings are recorded under `msg.performance.rpimage.rp_add_mask`.
|
|
39
52
|
|
|
40
53
|
### Polygon Mask Options
|
|
41
54
|
|
|
42
55
|
#### Coordinate System
|
|
43
|
-
- **Normalized Coordinates**:
|
|
44
|
-
- **Format**:
|
|
56
|
+
- **Normalized Coordinates**: every `x` and `y` must be a number from 0 to 1
|
|
57
|
+
- **Format**: `[[x1,y1], [x2,y2], [x3,y3], ...]`
|
|
45
58
|
- **Relative Positioning**: 0.0 = left/top edge, 1.0 = right/bottom edge
|
|
46
59
|
|
|
47
60
|
#### Mask Strength
|
|
48
|
-
- **
|
|
49
|
-
- **
|
|
50
|
-
- **Purpose**: Controls intensity of mask blending within polygon
|
|
61
|
+
- **Effect**: inside the polygon each pixel becomes image × (100 − strength) / 100 + fill colour × strength / 100; outside it the image is unchanged
|
|
62
|
+
- **Range**: 1-100. A value of 0 is read as the default 50
|
|
51
63
|
|
|
52
64
|
#### Fill Color
|
|
53
|
-
- **Format**:
|
|
54
|
-
- **
|
|
55
|
-
|
|
65
|
+
- **Format**: picked with the editor's colour picker (`#RRGGBB`)
|
|
66
|
+
- **Grayscale images**: the mean of the red, green and blue values is used
|
|
67
|
+
|
|
68
|
+
The polygon is filled with hard edges (no anti-aliasing).
|
|
56
69
|
|
|
57
70
|
### Output Format Options
|
|
58
|
-
- **Raw**: Standard image object
|
|
59
|
-
- **
|
|
60
|
-
- **WebP**:
|
|
61
|
-
- **JPEG**: Not recommended (transparency becomes background color)
|
|
71
|
+
- **Raw**: Standard image object (fastest between image nodes)
|
|
72
|
+
- **JPEG**: Compressed; the alpha channel of an RGBA input is dropped
|
|
73
|
+
- **PNG**, **WebP**: keep the alpha channel of an RGBA input
|
|
62
74
|
|
|
63
|
-
##
|
|
75
|
+
## Status and Errors
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
- **
|
|
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
|
|
77
|
+
- **Success**: green dot `OK: 1 img in <t> ms (conv <c> ms | task <k> ms)`, plus the preview format with Debug on
|
|
78
|
+
- **Failure**: `msg.error` is set (with `validationError: true` for invalid input), **Output** is left as it was (an array there is cut to its first item), a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent. Messages: `Base image is invalid or missing`, `Polygon coordinates must be an array`, `Polygon coordinates array is empty`, `Invalid polygon coordinate at index <i>: expected [x, y] pair`, `...: coordinates must be numbers`, `...: coordinates must be in range [0, 1]`
|
|
70
79
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
- **Threshold Processing**: Fast binary mask generation when needed
|
|
80
|
+
## Performance Notes
|
|
81
|
+
|
|
82
|
+
- The mask is drawn and blended in the native OpenCV addon, on the libuv thread pool
|
|
75
83
|
|
|
76
84
|
## Real-World Examples
|
|
77
85
|
|
|
78
|
-
###
|
|
86
|
+
### Segmentation Highlighting
|
|
79
87
|
```javascript
|
|
80
|
-
//
|
|
81
|
-
msg.
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
// Function node before add-mask
|
|
89
|
+
msg.payload = {
|
|
90
|
+
image: msg.image,
|
|
91
|
+
default: { masks: [ { mask: [ [[0.1, 0.2], [0.8, 0.2], [0.8, 0.7], [0.1, 0.7]] ] } ] }
|
|
84
92
|
};
|
|
85
|
-
msg
|
|
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
|
-
];
|
|
93
|
+
return msg;
|
|
111
94
|
```
|
|
112
95
|
```
|
|
113
|
-
[
|
|
96
|
+
[Image + segmentation] → [Function] → [Add-Mask: Mask Strength 30, Fill Color #ff0000] → [Highlighted region]
|
|
114
97
|
```
|
|
115
98
|
|
|
116
|
-
###
|
|
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
|
|
99
|
+
### Inspection Region
|
|
122
100
|
```
|
|
101
|
+
[Product Image] → [Change: msg.roi = [[0.25,0.25],[0.75,0.25],[0.75,0.75],[0.25,0.75]]] → [Add-Mask: Polygon Path msg.roi, Image msg.payload] → [Inspection Overlay]
|
|
123
102
|
```
|
|
124
|
-
|
|
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.
|
|
103
|
+
Mark the centre of the image in yellow (Fill Color `#ffff00`, Mask Strength 50).
|
|
132
104
|
|
|
133
105
|
## Common Issues & Troubleshooting
|
|
134
106
|
|
|
135
107
|
### Invalid Polygon Coordinates
|
|
136
|
-
- **Issue**:
|
|
137
|
-
- **Solution**:
|
|
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
|
|
108
|
+
- **Issue**: `Invalid polygon coordinate at index ...` in `msg.error`
|
|
109
|
+
- **Solution**: Make the polygon an array of `[x, y]` pairs of numbers between 0 and 1; pixel coordinates must be divided by the image width and height first
|
|
149
110
|
|
|
150
111
|
### Incorrect Path Configuration
|
|
151
|
-
- **Issue**:
|
|
152
|
-
- **Solution**:
|
|
112
|
+
- **Issue**: `Base image is invalid or missing` or `Polygon coordinates must be an array`, or `Invalid imagePath "..."` / `Invalid polygonPath "..."` when an object on the path is missing (for example `msg.payload.default` with the default Polygon Path)
|
|
113
|
+
- **Solution**: Point **Image** and **Polygon Path** at the `msg` properties that hold them
|
|
153
114
|
- **Default Paths**: `msg.payload.image` and `msg.payload.default.masks[0].mask[0]`
|
|
154
115
|
|
|
155
116
|
### Weak or Invisible Mask Effects
|
|
156
117
|
- **Issue**: Mask blending barely visible on image
|
|
157
|
-
- **Solution**: Increase
|
|
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
|
|
118
|
+
- **Solution**: Increase Mask Strength or choose a Fill Color that contrasts with the image
|