@rosepetal/node-red-contrib-image-tools 1.6.4 → 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/.claude/rules/node-implementation-template.md +1 -1
- package/.github/workflows/build-prebuild.yml +1 -1
- package/README.md +41 -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/lib/bmp-decode.js +18 -68
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +202 -104
- package/node-red-contrib-image-tools/lib/node-utils.js +78 -78
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +98 -46
- package/node-red-contrib-image-tools/nodes/io/image-in.js +3 -4
- package/node-red-contrib-image-tools/nodes/io/image-out.js +93 -146
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +3 -3
- package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +3 -3
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +11 -4
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +5 -4
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/crop.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/filter.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/padding.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/resize.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +3 -3
- 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/binding.gyp +2 -1
- package/rosepetal-image-engine/src/add-bbs.cpp +123 -123
- package/rosepetal-image-engine/src/add-mask.cpp +30 -15
- package/rosepetal-image-engine/src/add-masks.cpp +145 -102
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +200 -129
- package/rosepetal-image-engine/src/blend.cpp +34 -20
- package/rosepetal-image-engine/src/codec.cpp +157 -0
- package/rosepetal-image-engine/src/color-convert.cpp +22 -19
- package/rosepetal-image-engine/src/concat.cpp +38 -43
- package/rosepetal-image-engine/src/crop.cpp +23 -26
- package/rosepetal-image-engine/src/draw.cpp +33 -10
- package/rosepetal-image-engine/src/filter.cpp +22 -26
- package/rosepetal-image-engine/src/heat-diff.cpp +35 -8
- package/rosepetal-image-engine/src/image-align.cpp +107 -35
- package/rosepetal-image-engine/src/main.cpp +4 -0
- package/rosepetal-image-engine/src/mosaic.cpp +31 -40
- package/rosepetal-image-engine/src/padding.cpp +30 -29
- package/rosepetal-image-engine/src/resize.cpp +20 -25
- package/rosepetal-image-engine/src/rotate.cpp +22 -23
- package/rosepetal-image-engine/src/utils.h +243 -144
- package/scripts/build-opencv-static.sh +6 -0
- package/scripts/dual-register.js +32 -25
- package/scripts/sync-version.js +58 -41
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Crop Node - Extract Image Regions"
|
|
3
|
+
description: "Extract a rectangular region from images in Node-RED, with normalized (0-1) or pixel coordinates. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, crop, region of interest, normalized coordinates, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Crop Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Extract a rectangular region from images in Node-RED, with normalized (0-1) or pixel coordinates."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Crop Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `crop` node extracts rectangular
|
|
20
|
+
The `crop` node extracts one rectangular region from an image, or the same region from every image of an array, given in normalized coordinates (0-1) or in pixels.
|
|
6
21
|
|
|
7
22
|
**Real-World Applications:**
|
|
8
23
|
- **Object Extraction**: Extract specific objects or regions of interest
|
|
@@ -16,73 +31,62 @@ The `crop` node extracts rectangular regions from images with support for both n
|
|
|
16
31
|
## Input/Output Specification
|
|
17
32
|
|
|
18
33
|
### Inputs
|
|
19
|
-
- **Single Image**:
|
|
20
|
-
- **Image Array**:
|
|
21
|
-
- **Dynamic Coordinates**:
|
|
34
|
+
- **Single Image**: a raw image object, or an encoded JPEG/PNG/WebP/BMP `Buffer` (decoded by the addon)
|
|
35
|
+
- **Image Array**: an array of images, cropped in parallel with the same region; the output is an array in the same order
|
|
36
|
+
- **Dynamic Coordinates**: each coordinate can be read from `msg`, `flow` or `global`
|
|
22
37
|
|
|
23
38
|
### Outputs
|
|
24
|
-
|
|
25
|
-
- **
|
|
39
|
+
One output, written to **Output to** (`msg.payload` by default):
|
|
40
|
+
- **Cropped Image**: the region as a raw image object, or an encoded `Buffer` (JPEG/PNG/WebP)
|
|
41
|
+
- `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds
|
|
26
42
|
|
|
27
43
|
## Configuration Options
|
|
28
44
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
| Property | Default | Meaning |
|
|
46
|
+
|----------|---------|---------|
|
|
47
|
+
| Name | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
|
|
48
|
+
| Input from | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
|
|
49
|
+
| Output to | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
|
|
50
|
+
| Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP, with Quality (`90`), PNG Optimize and the WebP options as in [resize](./resize.md#output-format-options) |
|
|
51
|
+
| Debug / Debug Width | off / `200` | **Show processed image** under the node in the editor (the first image of an array) |
|
|
52
|
+
| Normalised | checked | Coordinates as fractions of the image size (0-1); unchecked, in pixels |
|
|
53
|
+
| X Position | `0` | Left edge of the region |
|
|
54
|
+
| Y Position | `0` | Top edge of the region |
|
|
55
|
+
| Width | `1` | Width of the region |
|
|
56
|
+
| Height | `1` | Height of the region |
|
|
57
|
+
| Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
|
|
58
|
+
|
|
59
|
+
The defaults (0, 0, 1, 1, normalised) select the whole image.
|
|
32
60
|
|
|
33
61
|
### Coordinate System
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **Pixel Mode**: Absolute pixel coordinates
|
|
62
|
+
- **Normalised (checked)**: values from 0.0 to 1.0, multiplied by the width or height of each image and rounded to whole pixels
|
|
63
|
+
- **Pixels (unchecked)**: absolute pixel values, rounded to whole pixels
|
|
37
64
|
|
|
38
65
|
### Crop Parameters
|
|
66
|
+
X Position, Y Position, Width and Height each take a number or a `msg`, `flow` or `global` property. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
|
|
39
67
|
|
|
40
|
-
|
|
41
|
-
- **Normalized**: 0.0 (left edge) to 1.0 (right edge)
|
|
42
|
-
- **Pixel**: 0 to image width
|
|
43
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
44
|
-
|
|
45
|
-
#### Y Position (cropY)
|
|
46
|
-
- **Normalized**: 0.0 (top edge) to 1.0 (bottom edge)
|
|
47
|
-
- **Pixel**: 0 to image height
|
|
48
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
68
|
+
**Bounds**: the region is clamped to the image. X and Y are limited to the image, and Width and Height to at least 1 pixel and at most what remains to the right and below. A region that reaches past the right or bottom edge is cut at that edge; a negative X or Y is raised to 0 without shortening the width or height, and a region that starts beyond the image becomes a 1-pixel strip at its edge; an empty or zero width or height gives a region 1 pixel wide or high. No warning is logged.
|
|
49
69
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- **Pixel**: Absolute width in pixels
|
|
53
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
70
|
+
### Inference
|
|
71
|
+
With **Transform inference coordinates** checked, the detections and segmentations read from **Inf. Input** are mapped into the cropped region (measured on the first input image) and written to **Inf. Output**. Coordinates are clipped to the crop; a detection whose box overlaps the crop by less than 10 % of its area is dropped. Segmentations are not filtered by overlap: their polygon points are clipped to the crop edge, and only a polygon with fewer than 3 points is removed. Bitmap masks are cropped too.
|
|
54
72
|
|
|
55
|
-
|
|
56
|
-
- **Normalized**: 0.0 to 1.0 (proportion of image height)
|
|
57
|
-
- **Pixel**: Absolute height in pixels
|
|
58
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
73
|
+
## Status and Errors
|
|
59
74
|
|
|
60
|
-
|
|
61
|
-
- **
|
|
62
|
-
- **JPEG**: Compressed with quality control (1-100)
|
|
63
|
-
- **PNG**: Lossless compression with optional optimization
|
|
64
|
-
- **WebP**: Modern format with quality control
|
|
75
|
+
- **Success**: green dot `OK: <n> img in <t> ms (conv <c> ms | task <k> ms)`, plus the preview format with Debug on
|
|
76
|
+
- **Failure**: `msg.error` is set, the input is written back to **Output to**, a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent
|
|
65
77
|
|
|
66
78
|
## Performance Notes
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
- **Memory Efficient**: Direct memory copy without full image processing
|
|
71
|
-
- **Bounds Checking**: Automatic coordinate validation and clipping
|
|
72
|
-
- **Parallel Processing**: Array inputs processed concurrently
|
|
73
|
-
|
|
74
|
-
### Coordinate Validation
|
|
75
|
-
- **Bounds Clipping**: Coordinates automatically clipped to image boundaries
|
|
76
|
-
- **Error Handling**: Invalid regions logged with graceful fallback
|
|
77
|
-
- **Status Display**: Processing time and result dimensions shown
|
|
80
|
+
- The crop and the encoding run in the native OpenCV addon on the libuv thread pool
|
|
81
|
+
- The region is copied once from the input image; the images of an array are cropped concurrently
|
|
78
82
|
|
|
79
83
|
## Real-World Examples
|
|
80
84
|
|
|
81
85
|
### Face Extraction (Normalized)
|
|
82
86
|
```
|
|
83
|
-
[Face Detection] → [
|
|
87
|
+
[Face Detection] → [Change: msg.x, msg.y, msg.w, msg.h] → [Crop: X=msg.x, Y=msg.y, Width=msg.w, Height=msg.h] → [Face Image]
|
|
84
88
|
```
|
|
85
|
-
Extract detected
|
|
89
|
+
Extract a detected face using normalized coordinates from a detector. To extract every box of a detection result at once, use [cropBB](../specialized/cropBB.md).
|
|
86
90
|
|
|
87
91
|
### Center Crop
|
|
88
92
|
```
|
|
@@ -100,7 +104,7 @@ Extract specific document regions using pixel coordinates.
|
|
|
100
104
|
```
|
|
101
105
|
[Product Photos] → [Array-Out] → [Crop: Normalized] → [Product Cutouts]
|
|
102
106
|
```
|
|
103
|
-
Extract
|
|
107
|
+
Extract the same region from every photo of an array. Array-Out is part of [`@rosepetal/node-red-contrib-utils`](https://docs.rosepetal.ai/flows/node-red-contrib-utils/nodes/io/array-out).
|
|
104
108
|
|
|
105
109
|
### Dynamic ROI Extraction
|
|
106
110
|
```
|
|
@@ -111,22 +115,16 @@ Extract regions based on image analysis results.
|
|
|
111
115
|
## Common Issues & Troubleshooting
|
|
112
116
|
|
|
113
117
|
### Coordinate System Confusion
|
|
114
|
-
- **Issue**:
|
|
115
|
-
- **Solution**:
|
|
118
|
+
- **Issue**: The output is a single pixel, or the whole image
|
|
119
|
+
- **Solution**: Check **Normalised**: with it checked, values above 1 reach past the image and are clamped; with it unchecked, values such as 0.5 round to 0 or 1 pixel
|
|
116
120
|
- **Normalized**: Use 0-1 values for relative positioning
|
|
117
121
|
- **Pixel**: Use absolute coordinates
|
|
118
122
|
|
|
119
123
|
### Out of Bounds Cropping
|
|
120
124
|
- **Issue**: Crop region extends beyond image boundaries
|
|
121
|
-
- **Result**:
|
|
125
|
+
- **Result**: The region is clamped to the image without a warning, so the output is smaller than requested, or shifted when X or Y is negative
|
|
122
126
|
- **Prevention**: Validate coordinates before processing
|
|
123
127
|
|
|
124
|
-
### Empty Crop Results
|
|
125
|
-
- **Issue**: Crop width or height is zero or negative
|
|
126
|
-
- **Result**: Warning logged, original image passed through
|
|
127
|
-
- **Solution**: Ensure width and height are positive values
|
|
128
|
-
|
|
129
128
|
### Dynamic Coordinate Errors
|
|
130
|
-
- **Issue**:
|
|
131
|
-
- **Solution**: Use debug nodes to verify
|
|
132
|
-
- **Validation**: Check that dynamic sources provide numbers
|
|
129
|
+
- **Issue**: `Value "..." from property "..." is not a valid number.` in `msg.error`
|
|
130
|
+
- **Solution**: Use debug nodes to verify that the `msg`, `flow` or `global` property exists and holds a number
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Draw Node - Overlay Points and Lines"
|
|
3
|
+
description: "Overlay points and line segments on an image in Node-RED, with normalized coordinates, color and opacity. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, draw, overlay, points, lines, keypoints, annotation, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Draw Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Overlay points and line segments on an image in Node-RED, with normalized coordinates, color and opacity."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Draw Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `draw` node overlays
|
|
20
|
+
The `draw` node overlays filled circles (points) and straight line segments on one image, with normalized coordinates, a color and an opacity for each. Drawing happens in the native OpenCV addon, with anti-aliased edges.
|
|
6
21
|
|
|
7
22
|
**Typical scenarios**
|
|
8
23
|
- Visualizing detections (keypoints, landmarks, segmentation anchors)
|
|
@@ -13,55 +28,60 @@ The `draw` node overlays configurable points and lines on top of an input image
|
|
|
13
28
|
## Input / Output
|
|
14
29
|
|
|
15
30
|
### Input
|
|
16
|
-
- **Image**:
|
|
31
|
+
- **Image**: one raw image object (`data`, `width`, `height`, `channels`, `colorSpace`, `dtype`) or an encoded JPEG/PNG/WebP/BMP `Buffer`. Arrays of images are not accepted.
|
|
17
32
|
- Source path defaults to `msg.payload` and can be remapped to any `msg`, `flow`, or `global` property.
|
|
33
|
+
- Point and line values set to `msg`, `flow` or `global` are read for each message.
|
|
18
34
|
|
|
19
35
|
### Output
|
|
20
|
-
-
|
|
21
|
-
-
|
|
36
|
+
- One output. The image with the overlays, in raw format (default) or encoded as `jpg`, `png`, or `webp`, written to **Output to** (`msg.payload` by default).
|
|
37
|
+
- `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds.
|
|
22
38
|
|
|
23
39
|
## Configuration
|
|
24
40
|
|
|
25
41
|
### I/O
|
|
26
|
-
- **Input
|
|
27
|
-
- **Output
|
|
42
|
+
- **Input from / Output to**: Typed inputs (`msg`, `flow`, `global`), both `msg.payload` by default.
|
|
43
|
+
- **Output format**: Raw (fastest), JPEG, PNG or WebP, with Quality (`90`), PNG optimize and the WebP options as in [resize](./resize.md#output-format-options).
|
|
28
44
|
|
|
29
45
|
### Points
|
|
30
|
-
Each
|
|
31
|
-
- **X / Y**: Normalized coordinates (`0.0 – 1.0`)
|
|
32
|
-
- **Radius**: Normalized size relative to the shortest image dimension (minimum 1 pixel).
|
|
33
|
-
- **Color**:
|
|
34
|
-
- **Opacity**: Overlay strength (`0.0 – 1.0`)
|
|
35
|
-
- **
|
|
46
|
+
Each row of the **Points** table (columns Mode, X, Y, List, Radius, Color, Opacity) configures one filled circle:
|
|
47
|
+
- **X / Y**: Normalized coordinates (`0.0 – 1.0`), required, from `num`, `msg`, `flow` or `global`.
|
|
48
|
+
- **Radius**: Normalized size relative to the shortest image dimension (minimum 1 pixel; `0` draws nothing). New rows start at `0.02`; an empty value falls back to `0.01`.
|
|
49
|
+
- **Color**: `#RRGGBB` or `#RRGGBBAA`, typed or read from `msg`, `flow` or `global`. Default `#ff0000`.
|
|
50
|
+
- **Opacity**: Overlay strength (`0.0 – 1.0`), default `1`. Combined with any alpha channel supplied in the color.
|
|
51
|
+
- **Mode**: **Single values**, or **List** to provide `[[x,y], ...]` in one go (JSON, or from `msg`, `flow` or `global`; a JSON string is parsed). The row’s radius/color/opacity apply to every list entry.
|
|
36
52
|
|
|
37
|
-
|
|
53
|
+
Use **Add point** and **Remove** to manage the rows. Fields keep their typed-input settings, allowing mixed static and dynamic values.
|
|
38
54
|
|
|
39
55
|
### Lines
|
|
40
|
-
Each
|
|
41
|
-
- **Start / End (X1, Y1, X2, Y2)**: Normalized coordinates.
|
|
42
|
-
- **Thickness**: Normalized width relative to the shortest dimension (minimum 1 pixel).
|
|
43
|
-
- **Color**:
|
|
44
|
-
- **Opacity**: Blend factor (`0.0 – 1.0`)
|
|
45
|
-
- **
|
|
56
|
+
Each row of the **Lines** table (columns Mode, X1, Y1, X2, Y2, List, Thickness, Color, Opacity) defines one straight segment:
|
|
57
|
+
- **Start / End (X1, Y1, X2, Y2)**: Normalized coordinates, required.
|
|
58
|
+
- **Thickness**: Normalized width relative to the shortest dimension (minimum 1 pixel). New rows start at `0.01`; an empty value falls back to `0.005`.
|
|
59
|
+
- **Color**: `#RRGGBB` or `#RRGGBBAA`, typed or dynamic. Default `#00ff00`.
|
|
60
|
+
- **Opacity**: Blend factor (`0.0 – 1.0`), default `1`.
|
|
61
|
+
- **Mode**: **List** feeds multiple lines at once as `[[x0,y0,x1,y1], ...]`. Thickness/color/opacity are reused for each segment.
|
|
62
|
+
|
|
63
|
+
Use **Add line** and **Remove** to manage the rows.
|
|
46
64
|
|
|
47
65
|
### Debugging
|
|
48
|
-
- **Debug
|
|
49
|
-
- **Debug width**:
|
|
66
|
+
- **Debug preview**: **Show processed image** under the node in the editor.
|
|
67
|
+
- **Debug width**: Width of the preview in pixels (default 200): a number, or read from `msg`, `flow` or `global`.
|
|
50
68
|
|
|
51
69
|
## Runtime Behaviour
|
|
52
70
|
|
|
53
71
|
1. The node validates the input image using shared `node-utils` helpers.
|
|
54
72
|
2. Points and lines are resolved via typed inputs—dynamic properties are evaluated per message.
|
|
55
73
|
3. The C++ engine converts normalized coordinates to pixels and composites overlays with anti-aliasing and alpha-aware blending.
|
|
56
|
-
4.
|
|
74
|
+
4. The status shows a green dot `OK: 1 img in <t> ms (conv <c> ms | task <k> ms)`, and the timings go to `msg.performance.rpimage.<key>`.
|
|
57
75
|
5. Optional debug previews reuse the existing toolkit infrastructure (`debug-image` WebSocket).
|
|
58
76
|
|
|
77
|
+
If the image is invalid or the addon fails, the node sets `msg.error`, writes the input back to **Output to**, logs a warning, shows a red ring `Error: <first 30 characters>` and still sends the message.
|
|
78
|
+
|
|
59
79
|
## Tips & Edge Cases
|
|
60
80
|
|
|
61
|
-
-
|
|
62
|
-
-
|
|
81
|
+
- A point or line with a coordinate outside `[0, 1]`, a missing value or an invalid color is skipped with a warning such as `points[0].x must be a number between 0 and 1`; the others are still drawn.
|
|
82
|
+
- With no valid point or line the node warns `No valid points or lines configured. Outputting original image.` and sends the image unchanged in raw format. With JPEG, PNG or WebP output the result is an empty `Buffer`, because the addon returns before encoding (only WebP with the `sharp` options is still encoded).
|
|
63
83
|
- Opacity multiplies the color alpha, so `#FF000080` at opacity `0.5` results in 25% final strength.
|
|
64
|
-
- Grayscale inputs are supported; color overlays are converted using luminance weighting.
|
|
84
|
+
- Grayscale inputs are supported; color overlays are converted using luminance weighting and added to the pixel values rather than blended, so a black overlay leaves a grayscale image unchanged.
|
|
65
85
|
- For chained overlays, prefer `raw` output to avoid repeated re-encoding.
|
|
66
86
|
|
|
67
87
|
## Example Flow
|
|
@@ -74,4 +94,4 @@ Each list entry defines a polyline segment:
|
|
|
74
94
|
└─▶ [image-out]
|
|
75
95
|
```
|
|
76
96
|
|
|
77
|
-
This creates a face marker
|
|
97
|
+
This creates a face marker, placed from the message, plus a fixed baseline overlay.
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Filter Node - Blur, Sharpen and Edge Detection"
|
|
3
|
+
description: "Apply blur, sharpening, edge detection, emboss, Gaussian blur, Otsu threshold, histogram equalization or CLAHE to images in Node-RED. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, image filter, blur, sharpen, edge detection, emboss, gaussian blur, otsu, histogram equalization, clahe, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Filter Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Apply blur, sharpening, edge detection, emboss, Gaussian blur, Otsu threshold, histogram equalization or CLAHE to images in Node-RED."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Filter Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `filter` node applies
|
|
20
|
+
The `filter` node applies one filter to an image, or to every image of an array: box blur, sharpening, Sobel edge detection, emboss, Gaussian blur, Otsu threshold, histogram equalization or CLAHE. The filters run in the native OpenCV addon.
|
|
6
21
|
|
|
7
22
|
**Real-World Applications:**
|
|
8
23
|
- **Photo Enhancement**: Sharpen portraits and improve image quality
|
|
@@ -16,69 +31,118 @@ The `filter` node applies various image processing filters for enhancement, arti
|
|
|
16
31
|
## Input/Output Specification
|
|
17
32
|
|
|
18
33
|
### Inputs
|
|
19
|
-
- **Single Image**:
|
|
20
|
-
- **Image Array**:
|
|
21
|
-
- **Dynamic Parameters**:
|
|
34
|
+
- **Single Image**: a raw image object, or an encoded JPEG/PNG/WebP/BMP `Buffer` (decoded by the addon)
|
|
35
|
+
- **Image Array**: an array of images, filtered in parallel with the same settings; the output is an array in the same order
|
|
36
|
+
- **Dynamic Parameters**: Kernel Size, Intensity, Pre-blur and Strength can be read from `msg`, `flow` or `global`
|
|
22
37
|
|
|
23
38
|
### Outputs
|
|
24
|
-
|
|
25
|
-
- **
|
|
26
|
-
-
|
|
39
|
+
One output, written to **Output to** (`msg.payload` by default):
|
|
40
|
+
- **Filtered Image**: same size, channels and color space as the input, as a raw image object or an encoded `Buffer` (JPEG/PNG/WebP)
|
|
41
|
+
- `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds
|
|
27
42
|
|
|
28
43
|
## Configuration Options
|
|
29
44
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
| Property | Default | Meaning |
|
|
46
|
+
|----------|---------|---------|
|
|
47
|
+
| Name | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
|
|
48
|
+
| Input from | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
|
|
49
|
+
| Output to | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
|
|
50
|
+
| Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP, with Quality (`90`), PNG Optimize and the WebP options as in [resize](./resize.md#output-format-options) |
|
|
51
|
+
| Debug / Debug Width | off / `200` | **Show processed image** under the node in the editor (the first image of an array) |
|
|
52
|
+
| Filter Type | Blur | One of the filters below |
|
|
53
|
+
| Kernel Size | `3` | Size of the filter window: odd, 3 to 15 (an even value is raised by one, other values are clamped). Shown for Blur, Sharpening, Edge Detection, Gaussian Blur and CLAHE |
|
|
54
|
+
| Intensity | `1.0` | Strength, 0.0 to 2.0 (clamped). The editor names it after the filter: Intensity, Sharpness, Edge Strength, Emboss Depth, Blur Radius or Clip Limit |
|
|
55
|
+
| Invert | off | *Otsu Threshold.* **Invert binary output (white background, black foreground)** |
|
|
56
|
+
| Pre-blur | `0` | *Otsu Threshold.* Gaussian blur before thresholding, odd 3 to 15 (see the note under Otsu Threshold) |
|
|
57
|
+
| Strength | `100` | *Histogram Equalization.* 0-100: mix of the equalized and the original image |
|
|
33
58
|
|
|
34
59
|
### Filter Types
|
|
35
60
|
|
|
36
|
-
#### Blur
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **Use Cases**: Noise reduction, background softening, privacy protection
|
|
61
|
+
#### Blur
|
|
62
|
+
- **Operation**: box blur (mean of the Kernel Size × Kernel Size window)
|
|
63
|
+
- **Intensity**: below 1.0 the result is mixed with the original (0 gives the original); 1.0 and above give the full blur
|
|
40
64
|
|
|
41
|
-
####
|
|
42
|
-
- **
|
|
43
|
-
- **Strength**: Configurable sharpening intensity
|
|
44
|
-
- **Use Cases**: Photo enhancement, print preparation, detail emphasis
|
|
65
|
+
#### Sharpening
|
|
66
|
+
- **Operation**: convolution with a sharpening kernel of Kernel Size; **Sharpness** scales the effect (0 leaves the image unchanged). Kernel Size 3 weights the 4 nearest neighbours; any larger Kernel Size weights only the 8 nearest neighbours, so 5 to 15 give the same result
|
|
45
67
|
|
|
46
68
|
#### Edge Detection
|
|
47
|
-
- **
|
|
48
|
-
- **Output**:
|
|
49
|
-
- **Use Cases**: Object detection, shape analysis, contour extraction
|
|
69
|
+
- **Operation**: Sobel gradients in x and y on the grayscale image, averaged; **Edge Strength** multiplies the result
|
|
70
|
+
- **Output**: a grayscale edge map, returned with the channel count of the input (the alpha channel of a 4-channel image becomes opaque)
|
|
50
71
|
|
|
51
|
-
#### Emboss
|
|
52
|
-
- **
|
|
53
|
-
- **Direction**: Configurable embossing direction
|
|
54
|
-
- **Use Cases**: Artistic effects, texture analysis, decorative processing
|
|
72
|
+
#### Emboss
|
|
73
|
+
- **Operation**: 3×3 relief kernel from top-left to bottom-right, then 128 is added to every channel (clipped at 255). The kernel weights add up to 1, so a flat area keeps its value plus 128 rather than becoming mid-gray (only black areas end up mid-gray); **Emboss Depth** scales every weight except the centre. Kernel Size is not used
|
|
55
74
|
|
|
56
75
|
#### Gaussian Blur
|
|
57
|
-
- **
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
- **Operation**: Gaussian blur with a Kernel Size window and sigma = Kernel Size / 6 × **Blur Radius**. A Blur Radius of 0 lets OpenCV derive sigma from the window size
|
|
77
|
+
|
|
78
|
+
#### Otsu Threshold
|
|
79
|
+
- **Operation**: converts to grayscale, picks the threshold with Otsu's method and returns a black and white image with the channel count of the input
|
|
80
|
+
- **Invert**: white background and black foreground
|
|
81
|
+
- **Pre-blur**: a value from 1 to 15 is made odd and at least 3. Note: the native addon raises every kernel size to at least 3, so a 3×3 Gaussian pre-blur is applied even when Pre-blur is 0
|
|
82
|
+
|
|
83
|
+
#### Histogram Equalization
|
|
84
|
+
- **Operation**: equalizes the histogram of a grayscale image, or of the luminance (Y of YCrCb) of a color image, which keeps the colors
|
|
85
|
+
- **Strength**: 100 gives the equalized image, 0 the original, values between mix the two
|
|
86
|
+
|
|
87
|
+
#### CLAHE (Adaptive Hist. Eq.)
|
|
88
|
+
- **Operation**: contrast-limited adaptive histogram equalization on the grayscale image or on the luminance of a color image
|
|
89
|
+
- **Kernel Size**: the tile grid (Kernel Size × Kernel Size tiles)
|
|
90
|
+
- **Clip Limit**: Intensity × 4, at least 1 (so 0.25 to 2.0 maps to a clip limit of 1 to 8)
|
|
60
91
|
|
|
61
92
|
### Filter Strength/Parameters
|
|
62
|
-
- **
|
|
63
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
64
|
-
- **Dynamic**: Runtime adjustment via message properties
|
|
93
|
+
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
|
|
65
94
|
|
|
66
95
|
### Output Format Options
|
|
67
|
-
- **Raw**: Standard image object (fastest
|
|
68
|
-
- **JPEG**: Compressed with quality control
|
|
69
|
-
- **PNG**: Lossless
|
|
70
|
-
- **WebP**:
|
|
96
|
+
- **Raw**: Standard image object (fastest between image nodes)
|
|
97
|
+
- **JPEG**: Compressed with quality control; the alpha channel is dropped
|
|
98
|
+
- **PNG**: Lossless
|
|
99
|
+
- **WebP**: Lossy or lossless
|
|
100
|
+
|
|
101
|
+
## Status and Errors
|
|
102
|
+
|
|
103
|
+
- **Success**: green dot `OK: <n> img in <t> ms (conv. <c> ms | task <k> ms)`; with Debug on it reads `(conv <c> ms | task <k> ms)` followed by the preview format
|
|
104
|
+
- **Failure**: `msg.error` is set, the input is written back to **Output to**, a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent
|
|
71
105
|
|
|
72
106
|
## Performance Notes
|
|
73
107
|
|
|
74
|
-
|
|
75
|
-
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
- Filtering and encoding run in the native OpenCV addon on the libuv thread pool, not on the Node-RED event loop
|
|
109
|
+
- The images of an array are filtered concurrently
|
|
110
|
+
|
|
111
|
+
## Real-World Examples
|
|
112
|
+
|
|
113
|
+
### Binarize for Inspection
|
|
114
|
+
```
|
|
115
|
+
[Camera] → [Filter: Otsu Threshold, Pre-blur 5] → [Blob analysis]
|
|
116
|
+
```
|
|
117
|
+
Separate dark parts from a light background before measuring them.
|
|
118
|
+
|
|
119
|
+
### Contrast for Dark Images
|
|
120
|
+
```
|
|
121
|
+
[Image-In] → [Filter: CLAHE, Kernel Size 7, Clip Limit 0.5] → [Inference]
|
|
122
|
+
```
|
|
123
|
+
Raise local contrast of under-exposed images before a model.
|
|
124
|
+
|
|
125
|
+
### Edge Map
|
|
126
|
+
```
|
|
127
|
+
[Image-In] → [Filter: Edge Detection, Kernel Size 3, Edge Strength 1.5] → [Image-Out]
|
|
128
|
+
```
|
|
129
|
+
Save an edge map of a part to check its outline.
|
|
130
|
+
|
|
131
|
+
## Common Issues & Troubleshooting
|
|
132
|
+
|
|
133
|
+
### The Image Does Not Change
|
|
134
|
+
- **Issue**: Blur or Sharpening seems to do nothing
|
|
135
|
+
- **Cause**: Intensity (Sharpness) is 0, or Kernel Size is 3 on a large image
|
|
136
|
+
- **Solution**: Raise the intensity (up to 2.0), or for Blur the kernel size (up to 15)
|
|
137
|
+
|
|
138
|
+
### Otsu Output Is Inverted
|
|
139
|
+
- **Issue**: Objects come out black on white instead of white on black
|
|
140
|
+
- **Solution**: Toggle **Invert**
|
|
141
|
+
|
|
142
|
+
### Dynamic Parameter Errors
|
|
143
|
+
- **Issue**: `Value "..." from property "..." is not a valid number.` in `msg.error`
|
|
144
|
+
- **Solution**: Make sure the `msg`, `flow` or `global` property exists and holds a number
|
|
145
|
+
|
|
146
|
+
## See Also
|
|
147
|
+
- [draw](./draw.md): overlay points and lines
|
|
148
|
+
- [color-convert](./color-convert.md): convert between color spaces before or after filtering
|