@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,8 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Padding Node - Add Margins Around Images"
|
|
3
|
+
description: "Add top, bottom, left and right margins of a solid color around images in Node-RED. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, padding, margin, border, canvas, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Padding Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Add top, bottom, left and right margins of a solid color around images in Node-RED."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Padding Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `padding` node adds
|
|
20
|
+
The `padding` node adds a margin of a solid colour on each side of an image, or of every image of an array. The canvas grows by the margins and the original pixels are kept as they are.
|
|
6
21
|
|
|
7
22
|
**Real-World Applications:**
|
|
8
23
|
- **Social Media Formatting**: Add borders for consistent post dimensions
|
|
@@ -16,65 +31,56 @@ The `padding` node adds margins around images with configurable colors and dimen
|
|
|
16
31
|
## Input/Output Specification
|
|
17
32
|
|
|
18
33
|
### Inputs
|
|
19
|
-
- **Single Image**:
|
|
20
|
-
- **Image Array**:
|
|
21
|
-
- **Dynamic Values**:
|
|
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, padded in parallel with the same margins; the output is an array in the same order
|
|
36
|
+
- **Dynamic Values**: each margin can be read from `msg`, `flow` or `global`
|
|
22
37
|
|
|
23
38
|
### Outputs
|
|
24
|
-
|
|
25
|
-
- **
|
|
26
|
-
-
|
|
39
|
+
One output, written to **Output** (`msg.payload` by default):
|
|
40
|
+
- **Padded Image**: a raw image object of `width + left + right` by `height + top + bottom` pixels, 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 | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
|
|
49
|
+
| Output | `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
|
+
| Top | `0` | Margin above the image, in pixels |
|
|
53
|
+
| Bottom | `0` | Margin below the image, in pixels |
|
|
54
|
+
| Left | `0` | Margin on the left, in pixels |
|
|
55
|
+
| Right | `0` | Margin on the right, in pixels |
|
|
56
|
+
| Colour | `#000000` | Colour of the margins |
|
|
57
|
+
| Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
|
|
33
58
|
|
|
34
59
|
### Padding Dimensions
|
|
60
|
+
- **Values**: whole pixels; decimals are truncated and an empty value means 0. Negative values are not supported (OpenCV rejects them and the node reports the error)
|
|
61
|
+
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
|
|
35
62
|
|
|
36
|
-
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **Effect**: Adds space above the image
|
|
40
|
-
|
|
41
|
-
#### Right Padding
|
|
42
|
-
- **Type**: Pixels (integer)
|
|
43
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
44
|
-
- **Effect**: Adds space to the right of the image
|
|
63
|
+
### Color Configuration
|
|
64
|
+
- **Colour**: picked with the editor's colour picker (`#RRGGBB`); default black
|
|
65
|
+
- **Images with alpha** (RGBA, BGRA): the margins are transparent; their colour channels hold the pad colour
|
|
45
66
|
|
|
46
|
-
|
|
47
|
-
- **
|
|
48
|
-
- **
|
|
49
|
-
- **
|
|
67
|
+
### Output Format Options
|
|
68
|
+
- **Raw**: Standard image object (fastest between image nodes)
|
|
69
|
+
- **JPEG**: Compressed; the alpha channel is dropped, so transparent margins show the pad colour
|
|
70
|
+
- **PNG**: Lossless, keeps the alpha channel
|
|
71
|
+
- **WebP**: Keeps the alpha channel
|
|
50
72
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
54
|
-
- **Effect**: Adds space to the left of the image
|
|
73
|
+
### Inference
|
|
74
|
+
With **Transform inference coordinates** checked, the normalized coordinates of the detections and segmentations read from **Inf. Input** are recomputed for the larger canvas (measured on the first input image) and written to **Inf. Output**. Bitmap masks are padded too.
|
|
55
75
|
|
|
56
|
-
|
|
76
|
+
## Status and Errors
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
- **
|
|
60
|
-
- RGB: `rgb(255,0,0)`, `rgb(255,255,255)`
|
|
61
|
-
- **Default**: Black
|
|
62
|
-
|
|
63
|
-
### Output Format Options
|
|
64
|
-
- **Raw**: Standard image object (fastest for processing chains)
|
|
65
|
-
- **JPEG**: Compressed (note: transparency becomes white)
|
|
66
|
-
- **PNG**: Lossless with full transparency support
|
|
67
|
-
- **WebP**: Modern format with transparency support
|
|
78
|
+
- **Success**: green dot `OK: <n> img in <t> ms (conv <c> | task <k> ms)` (no `ms` after the conversion time); with Debug on it reads `(conv <c> ms | task <k> ms)` followed by the preview format
|
|
79
|
+
- **Failure**: `msg.error` is set, the input is written back to **Output**, a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent
|
|
68
80
|
|
|
69
81
|
## Performance Notes
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
- **Efficient Canvas Expansion**: Optimized memory allocation for padded dimensions
|
|
73
|
-
- **Color Fill**: Fast uniform color filling using OpenCV
|
|
74
|
-
- **Memory Management**: Minimal memory overhead for padding operations
|
|
75
|
-
- **Batch Processing**: Array inputs processed in parallel
|
|
76
|
-
|
|
77
|
-
### Dimension Calculations
|
|
83
|
+
- The margins are added with `cv::copyMakeBorder` in the native addon, on the libuv thread pool; the images of an array are processed concurrently
|
|
78
84
|
- **New Width**: Original width + left padding + right padding
|
|
79
85
|
- **New Height**: Original height + top padding + bottom padding
|
|
80
86
|
|
|
@@ -113,21 +119,15 @@ Add subtle borders to scanned documents.
|
|
|
113
119
|
## Common Issues & Troubleshooting
|
|
114
120
|
|
|
115
121
|
### Transparency Issues
|
|
116
|
-
- **Issue**:
|
|
117
|
-
- **
|
|
118
|
-
- **
|
|
122
|
+
- **Issue**: Margins of an RGBA image are transparent instead of coloured
|
|
123
|
+
- **Cause**: For images with alpha the margins get alpha 0
|
|
124
|
+
- **Solution**: Convert the image to RGB first ([color-convert](./color-convert.md)), or save as JPEG, which drops the alpha channel
|
|
119
125
|
|
|
120
126
|
### Large File Sizes
|
|
121
127
|
- **Issue**: Padding significantly increases file size
|
|
122
128
|
- **Cause**: Expanded canvas dimensions
|
|
123
129
|
- **Solution**: Use appropriate compression settings, consider if padding is necessary
|
|
124
130
|
|
|
125
|
-
### Color Matching Problems
|
|
126
|
-
- **Issue**: Padding color doesn't match expected appearance
|
|
127
|
-
- **Solution**: Use exact color specifications (RGB codes)
|
|
128
|
-
- **Testing**: Use debug mode to verify color appearance
|
|
129
|
-
|
|
130
131
|
### Dynamic Dimension Errors
|
|
131
132
|
- **Issue**: Invalid padding values from message properties
|
|
132
|
-
- **Solution**:
|
|
133
|
-
- **Safety**: Add bounds checking in upstream nodes
|
|
133
|
+
- **Solution**: Make sure the dynamic sources hold zero or positive numbers
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Resize Node - Scale Images"
|
|
3
|
+
description: "Scale images in Node-RED to a fixed size or by a factor, keeping the aspect ratio when one dimension is left empty. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, resize, scale image, thumbnail, aspect ratio, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Resize Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Scale images in Node-RED to a fixed size or by a factor, keeping the aspect ratio when one dimension is left empty."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Resize Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `resize` node
|
|
20
|
+
The `resize` node scales an image, or every image of an array, to a size in pixels or by a factor, and keeps the aspect ratio when one dimension is left empty. The scaling runs in the native OpenCV addon with bilinear interpolation.
|
|
6
21
|
|
|
7
22
|
**Real-World Applications:**
|
|
8
23
|
- **Web Image Optimization**: Scale images for different device sizes and bandwidths
|
|
@@ -16,9 +31,9 @@ The `resize` node provides high-performance image scaling with flexible dimensio
|
|
|
16
31
|
## Input/Output Specification
|
|
17
32
|
|
|
18
33
|
### Inputs
|
|
19
|
-
- **Single Image**:
|
|
20
|
-
- **Image Array**:
|
|
21
|
-
- **Dynamic Dimensions**:
|
|
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, resized in parallel; the output is an array in the same order
|
|
36
|
+
- **Dynamic Dimensions**: Width and Height can be read from `msg`, `flow` or `global`
|
|
22
37
|
|
|
23
38
|
### Input Image Format
|
|
24
39
|
```javascript
|
|
@@ -27,79 +42,90 @@ The `resize` node provides high-performance image scaling with flexible dimensio
|
|
|
27
42
|
width: number, // Original width in pixels
|
|
28
43
|
height: number, // Original height in pixels
|
|
29
44
|
channels: number, // Channel count (1, 3, 4)
|
|
30
|
-
colorSpace: string, // "GRAY", "RGB", "RGBA"
|
|
45
|
+
colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR" or "BGRA"
|
|
31
46
|
dtype: string // "uint8"
|
|
32
47
|
}
|
|
33
48
|
```
|
|
34
49
|
|
|
35
50
|
### Outputs
|
|
36
|
-
Output
|
|
37
|
-
- **Raw**:
|
|
38
|
-
- **JPEG/PNG/WebP**:
|
|
51
|
+
One output. The result is written to **Output to** and its form depends on **Output Format**:
|
|
52
|
+
- **Raw**: an image object with the new `width` and `height` and the same channels and color space
|
|
53
|
+
- **JPEG/PNG/WebP**: an encoded `Buffer`
|
|
54
|
+
|
|
55
|
+
The node also sets `msg.performance.rpimage.<key>` (`{ conversion, task, total }` in milliseconds) and, with **Inference** checked, writes the detections back (see below).
|
|
39
56
|
|
|
40
57
|
## Configuration Options
|
|
41
58
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
59
|
+
| Property | Default | Meaning |
|
|
60
|
+
|----------|---------|---------|
|
|
61
|
+
| Name | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
|
|
62
|
+
| Input from | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
|
|
63
|
+
| Output to | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
|
|
64
|
+
| Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP |
|
|
65
|
+
| Quality | `90` | JPEG and WebP quality, 1-100 |
|
|
66
|
+
| PNG Optimize | off | **Compress PNG (slower, smaller file)**: PNG compression level 6 instead of 0 |
|
|
67
|
+
| Lossless / Smart Subsample / Effort | off / off / empty | WebP options. When any of them is set, the WebP is encoded with `sharp` (Effort 0-6) instead of OpenCV |
|
|
68
|
+
| Debug | off | **Show processed image**: a preview under the node in the editor (the first image of an array) |
|
|
69
|
+
| Debug Width | `200` | Width of the preview in pixels: a number, or read from `msg`, `flow` or `global` |
|
|
70
|
+
| Width | Set to, empty | Mode (**Set to** or **Multiply by**) and value: a number, or read from `msg`, `flow` or `global` |
|
|
71
|
+
| Height | Set to, empty | Same as Width |
|
|
72
|
+
| Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
|
|
46
73
|
|
|
47
74
|
### Dimension Configuration
|
|
48
75
|
|
|
49
76
|
#### Width Settings
|
|
50
77
|
- **Mode**:
|
|
51
|
-
- **Set to**:
|
|
52
|
-
- **Multiply by**:
|
|
53
|
-
- **Value Sources**:
|
|
54
|
-
|
|
55
|
-
- **msg.***: Dynamic from message property
|
|
56
|
-
- **flow.***: From flow context
|
|
57
|
-
- **global.***: From global context
|
|
58
|
-
- **Auto Mode**: Leave empty for automatic aspect ratio preservation
|
|
78
|
+
- **Set to**: the width in pixels (e.g., 800)
|
|
79
|
+
- **Multiply by**: a factor of the input width (e.g., 0.5 for half size)
|
|
80
|
+
- **Value Sources**: 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.`
|
|
81
|
+
- **Auto**: leave it empty (or 0) and the width follows from the height, keeping the aspect ratio
|
|
59
82
|
|
|
60
83
|
#### Height Settings
|
|
61
84
|
- **Mode**: Same options as width (Set to / Multiply by)
|
|
62
|
-
- **Value Sources**: Same
|
|
63
|
-
- **Auto
|
|
85
|
+
- **Value Sources**: Same as width
|
|
86
|
+
- **Auto**: leave it empty (or 0) and the height follows from the width
|
|
87
|
+
|
|
88
|
+
Results are rounded to whole pixels. Leaving both empty fails with `Both dimensions are Auto`. An output larger than 4 GiB is refused; the limit can be changed with the environment variable `ROSEPETAL_MAX_RESIZE_BYTES` (in bytes) of the Node-RED process.
|
|
64
89
|
|
|
65
90
|
### Output Format Options
|
|
66
91
|
|
|
67
92
|
#### Raw Format (Default)
|
|
68
|
-
- **Performance**:
|
|
69
|
-
- **Use Case**: When passing to other
|
|
93
|
+
- **Performance**: no encoding; the fastest option between image nodes
|
|
94
|
+
- **Use Case**: When passing to other image nodes
|
|
70
95
|
|
|
71
96
|
#### JPEG Format
|
|
72
97
|
- **Quality**: 1-100 (default: 90)
|
|
73
|
-
- **Use Case**: Final output,
|
|
74
|
-
- **Compression**: Lossy
|
|
98
|
+
- **Use Case**: Final output, small files
|
|
99
|
+
- **Compression**: Lossy; the alpha channel is dropped
|
|
75
100
|
|
|
76
101
|
#### PNG Format
|
|
77
|
-
- **Optimize**:
|
|
78
|
-
- **Use Case**: When transparency
|
|
102
|
+
- **PNG Optimize**: compression level 6 when checked, 0 (fastest, largest) otherwise
|
|
103
|
+
- **Use Case**: When transparency or lossless output is needed
|
|
79
104
|
- **Compression**: Lossless
|
|
80
105
|
|
|
81
106
|
#### WebP Format
|
|
82
107
|
- **Quality**: 1-100 (default: 90)
|
|
83
|
-
- **
|
|
84
|
-
- **
|
|
108
|
+
- **Lossless**, **Smart Subsample** (lossy only) and **Effort** (0-6): encoded with `sharp` when any of them is set
|
|
109
|
+
- **Use Case**: Small files with alpha, lossy or lossless
|
|
85
110
|
|
|
86
111
|
### Debug Options
|
|
87
|
-
- **Show
|
|
88
|
-
- **Debug Width**:
|
|
89
|
-
- **Interactive**:
|
|
112
|
+
- **Show processed image**: a preview of the result (or of the first image of an array) under the node in the editor, as JPEG for Raw output and in the output format otherwise
|
|
113
|
+
- **Debug Width**: width of the preview in pixels
|
|
114
|
+
- **Interactive**: click the preview to hide it
|
|
90
115
|
|
|
91
|
-
|
|
116
|
+
### Inference
|
|
117
|
+
With **Transform inference coordinates** checked, the node reads the inference results at **Inf. Input** and writes them to **Inf. Output** after the image is resized. Normalized coordinates do not change with a resize, so boxes and polygons are written back unchanged. Bitmap masks of segmentations are resized to the new image size, except when the output is encoded by OpenCV (JPEG, PNG, or WebP without the `sharp` options): the new size is then not read back and the masks are left as they are. Only a non-empty array is processed; a failure logs `Inference transform: ...` and leaves the message as it is.
|
|
92
118
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
- **
|
|
96
|
-
- **
|
|
97
|
-
|
|
119
|
+
## Status and Errors
|
|
120
|
+
|
|
121
|
+
- **Success**: green dot `OK: <n> img in <t> ms (conv <c> ms | task <k> ms)`, followed by the preview format with Debug on (`| jpg default (first)` for an array)
|
|
122
|
+
- **Failure**: the node sets `msg.error` (`message`, `operation`, `hint`, `details`, `timestamp`, `nodeId`, `nodeName`, `nodeType`), writes the input back to **Output to**, logs a warning, shows a red ring `Error: <first 30 characters>` and still sends the message. Invalid input images give `Invalid image structure` or `Invalid image list structure` with `msg.error.validationError` set to `true`
|
|
123
|
+
|
|
124
|
+
## Performance Notes
|
|
98
125
|
|
|
99
|
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
- **Status Display**: Real-time processing time and result information
|
|
126
|
+
- Resizing and encoding run in the native addon on the libuv thread pool, not on the Node-RED event loop
|
|
127
|
+
- The images of an array are resized concurrently
|
|
128
|
+
- Interpolation: bilinear (`cv::INTER_LINEAR`)
|
|
103
129
|
|
|
104
130
|
## Real-World Examples
|
|
105
131
|
|
|
@@ -111,17 +137,17 @@ Create web-optimized versions of high-resolution images.
|
|
|
111
137
|
|
|
112
138
|
### Responsive Image Set
|
|
113
139
|
```
|
|
114
|
-
[Image-In] → [Resize:
|
|
115
|
-
→ [Resize:
|
|
116
|
-
→ [Resize:
|
|
140
|
+
[Image-In] → [Resize: 1200 x Auto, JPEG Quality 80] → [Large]
|
|
141
|
+
→ [Resize: 800 x Auto, JPEG Quality 85] → [Medium]
|
|
142
|
+
→ [Resize: 400 x Auto, JPEG Quality 90] → [Small]
|
|
117
143
|
```
|
|
118
144
|
Generate multiple sizes for responsive web design.
|
|
119
145
|
|
|
120
146
|
### Thumbnail Generation
|
|
121
147
|
```
|
|
122
|
-
[Image Array] → [Resize: 150x150
|
|
148
|
+
[Image Array] → [Resize: 150x150, PNG] → [Thumbnail Gallery]
|
|
123
149
|
```
|
|
124
|
-
Create square thumbnails from image collections.
|
|
150
|
+
Create square thumbnails from image collections (images that are not square are stretched).
|
|
125
151
|
|
|
126
152
|
### Batch Photo Processing
|
|
127
153
|
```
|
|
@@ -142,17 +168,16 @@ Resize based on runtime requirements.
|
|
|
142
168
|
- **Cause**: Both width and height set without considering aspect ratio
|
|
143
169
|
- **Solution**: Leave one dimension empty for auto-calculation
|
|
144
170
|
|
|
145
|
-
###
|
|
146
|
-
- **Issue**:
|
|
147
|
-
- **
|
|
148
|
-
- **
|
|
171
|
+
### Too Much Memory
|
|
172
|
+
- **Issue**: `Resize to WxH would allocate too much memory`
|
|
173
|
+
- **Cause**: The computed size is over 4 GiB, usually a pixel size typed in **Multiply by** mode or a wrong dynamic value
|
|
174
|
+
- **Solution**: Check the mode and the values; raise `ROSEPETAL_MAX_RESIZE_BYTES` only if such a size is intended
|
|
149
175
|
|
|
150
176
|
### Quality vs. File Size Balance
|
|
151
177
|
- **Issue**: Output files too large or quality too low
|
|
152
|
-
- **Solution**: Adjust quality
|
|
153
|
-
- **Format Choice**: Use WebP for best compression, PNG for transparency
|
|
178
|
+
- **Solution**: Adjust the quality (80-95 is a common range), or check PNG Optimize for smaller PNG files
|
|
154
179
|
|
|
155
180
|
### Dynamic Value Errors
|
|
156
|
-
- **Issue**:
|
|
157
|
-
- **Solution**:
|
|
181
|
+
- **Issue**: `Value "..." from property "..." is not a valid number.` in `msg.error`
|
|
182
|
+
- **Solution**: Make sure the `msg`, `flow` or `global` property exists and holds a number
|
|
158
183
|
- **Debugging**: Use debug nodes to verify property values
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Rotate Node - Rotate Images by Any Angle"
|
|
3
|
+
description: "Rotate images in Node-RED by an angle in degrees and fill the uncovered area with a pad color. Part of @rosepetal/node-red-contrib-image-tools."
|
|
4
|
+
head:
|
|
5
|
+
- - meta
|
|
6
|
+
- name: "keywords"
|
|
7
|
+
content: "node-red, rotate, image rotation, angle, pad color, opencv, rosepetal"
|
|
8
|
+
- - meta
|
|
9
|
+
- property: "og:title"
|
|
10
|
+
content: "Rotate Node - @rosepetal/node-red-contrib-image-tools"
|
|
11
|
+
- - meta
|
|
12
|
+
- property: "og:description"
|
|
13
|
+
content: "Rotate images in Node-RED by an angle in degrees and fill the uncovered area with a pad color."
|
|
14
|
+
---
|
|
15
|
+
|
|
1
16
|
# Rotate Node
|
|
2
17
|
|
|
3
18
|
## Purpose & Use Cases
|
|
4
19
|
|
|
5
|
-
The `rotate` node
|
|
20
|
+
The `rotate` node rotates an image, or every image of an array, by any angle in degrees. The canvas grows so that the whole rotated image fits, and the uncovered corners are filled with a pad colour.
|
|
6
21
|
|
|
7
22
|
**Real-World Applications:**
|
|
8
23
|
- **Photo Orientation**: Correct camera orientation issues
|
|
@@ -16,54 +31,62 @@ The `rotate` node provides precise image rotation with customizable padding and
|
|
|
16
31
|
## Input/Output Specification
|
|
17
32
|
|
|
18
33
|
### Inputs
|
|
19
|
-
- **Single Image**:
|
|
20
|
-
- **Image Array**:
|
|
21
|
-
- **Dynamic Angles**:
|
|
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, rotated in parallel by the same angle; the output is an array in the same order
|
|
36
|
+
- **Dynamic Angles**: the angle can be read from `msg`, `flow` or `global`
|
|
22
37
|
|
|
23
38
|
### Outputs
|
|
24
|
-
|
|
25
|
-
- **
|
|
39
|
+
One output, written to **Output** (`msg.payload` by default):
|
|
40
|
+
- **Rotated Image**: a raw image object with the size of the rotated image's bounding box, 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 | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
|
|
49
|
+
| Output | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
|
|
50
|
+
| Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP |
|
|
51
|
+
| Quality | `90` | JPEG and WebP quality, 1-100 |
|
|
52
|
+
| PNG Optimize | off | PNG compression level 6 instead of 0 |
|
|
53
|
+
| Lossless / Smart Subsample / Effort | off / off / empty | WebP options; when any is set the WebP is encoded with `sharp` |
|
|
54
|
+
| Debug | off | **Show processed image** under the node in the editor (the first image of an array) |
|
|
55
|
+
| Debug Width | `200` | Width of the preview in pixels |
|
|
56
|
+
| Angle (°) | `90` | Rotation angle in degrees: a number, or read from `msg`, `flow` or `global`. Empty means 0 |
|
|
57
|
+
| Pad colour | `#000000` | Colour of the corners uncovered by the rotation |
|
|
58
|
+
| Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
|
|
32
59
|
|
|
33
60
|
### Rotation Settings
|
|
34
61
|
|
|
35
62
|
#### Angle
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
63
|
+
- **Values**: any number of degrees, with decimals (e.g., 15.5); values beyond 360 or below 0 wrap around
|
|
64
|
+
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
|
|
65
|
+
- **Direction**: Positive = counter-clockwise, Negative = clockwise
|
|
66
|
+
- **Right angles**: 0, 90, 180 and 270 degrees are exact rotations without interpolation; other angles use bilinear interpolation
|
|
40
67
|
|
|
41
68
|
#### Padding Settings
|
|
42
|
-
- **
|
|
43
|
-
- **
|
|
44
|
-
- Hex: `#FF0000` (red)
|
|
45
|
-
- RGB: `rgb(255,0,0)`
|
|
46
|
-
- Named: `red`, `white`, `black`, `transparent`
|
|
47
|
-
- **Default**: Black background
|
|
69
|
+
- **Pad colour**: picked with the editor's colour picker (`#RRGGBB`)
|
|
70
|
+
- **Images with alpha** (RGBA, BGRA): the padding is transparent, whatever the colour
|
|
48
71
|
|
|
49
72
|
### Output Format Options
|
|
50
|
-
- **Raw**: Standard image object (fastest
|
|
51
|
-
- **JPEG**: Compressed with quality control (1-100)
|
|
52
|
-
- **PNG**: Lossless
|
|
53
|
-
- **WebP**:
|
|
73
|
+
- **Raw**: Standard image object (fastest between image nodes)
|
|
74
|
+
- **JPEG**: Compressed with quality control (1-100); the alpha channel is dropped
|
|
75
|
+
- **PNG**: Lossless, keeps the alpha channel
|
|
76
|
+
- **WebP**: Quality control (1-100), keeps the alpha channel
|
|
54
77
|
|
|
55
|
-
|
|
78
|
+
### Inference
|
|
79
|
+
With **Transform inference coordinates** checked, the detections and segmentations read from **Inf. Input** get the same rotation, measured on the first input image, and are written to **Inf. Output**, so that their normalized coordinates match the rotated image. Bitmap masks are rotated too. Only a non-empty array is processed; a failure logs `Inference transform: ...`.
|
|
80
|
+
|
|
81
|
+
## Status and Errors
|
|
56
82
|
|
|
57
|
-
|
|
58
|
-
- **
|
|
59
|
-
- **Canvas Expansion**: Automatic canvas sizing to prevent clipping
|
|
60
|
-
- **Memory Management**: Efficient handling of rotated image dimensions
|
|
61
|
-
- **Interpolation**: High-quality pixel interpolation for smooth results
|
|
83
|
+
- **Success**: green dot `OK: <n> img in <t> ms (conv <c> ms | task <k> ms)`, plus the preview format with Debug on
|
|
84
|
+
- **Failure**: `msg.error` is set, the input is written back to **Output**, a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent. Invalid input images give `Invalid image structure` or `Invalid image list structure`
|
|
62
85
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
-
|
|
66
|
-
- **
|
|
86
|
+
## Performance Notes
|
|
87
|
+
|
|
88
|
+
- Rotation and encoding run in the native OpenCV addon on the libuv thread pool
|
|
89
|
+
- **Canvas Growth**: for angles that are not multiples of 90 the output is larger than the input; at 45 degrees a square image grows by a factor of about 1.41 on each side
|
|
67
90
|
|
|
68
91
|
## Real-World Examples
|
|
69
92
|
|
|
@@ -83,13 +106,13 @@ Correct slight rotation in scanned documents.
|
|
|
83
106
|
```
|
|
84
107
|
[Photo Array] → [Rotate: msg.orientation] → [Corrected Photos]
|
|
85
108
|
```
|
|
86
|
-
Apply
|
|
109
|
+
Apply one angle, read from the message, to every photo of the array.
|
|
87
110
|
|
|
88
111
|
### Artistic Composition
|
|
89
112
|
```
|
|
90
|
-
[Logo Image] → [Rotate: 45°,
|
|
113
|
+
[Logo Image (RGBA)] → [Rotate: 45°, PNG] → [Diamond Logo]
|
|
91
114
|
```
|
|
92
|
-
|
|
115
|
+
An RGBA logo rotated by 45 degrees gets transparent corners.
|
|
93
116
|
|
|
94
117
|
### Dynamic Rotation
|
|
95
118
|
```
|
|
@@ -103,19 +126,13 @@ Rotate based on image analysis results.
|
|
|
103
126
|
- **Issue**: Output image larger than input
|
|
104
127
|
- **Cause**: Canvas expansion to accommodate rotated content
|
|
105
128
|
- **Expected**: Normal behavior to prevent clipping
|
|
106
|
-
- **Solution**:
|
|
129
|
+
- **Solution**: Follow with a [crop](./crop.md) or [resize](./resize.md) node if a fixed size is needed
|
|
107
130
|
|
|
108
131
|
### Background Color Issues
|
|
109
|
-
- **Issue**:
|
|
110
|
-
- **Solution**:
|
|
111
|
-
- **Transparency**: Use PNG
|
|
112
|
-
|
|
113
|
-
###
|
|
114
|
-
- **Issue**:
|
|
115
|
-
- **
|
|
116
|
-
- **Memory**: Monitor memory usage with very large images
|
|
117
|
-
|
|
118
|
-
### Precision vs. Speed
|
|
119
|
-
- **Issue**: High-precision angles may be slower
|
|
120
|
-
- **Balance**: Use appropriate precision for your requirements
|
|
121
|
-
- **Optimization**: Round to nearest degree if precision not critical
|
|
132
|
+
- **Issue**: The corners are black, or transparent instead of the pad colour
|
|
133
|
+
- **Solution**: Set **Pad colour**; for images with alpha the corners are always transparent, so convert to RGB first if a coloured background is needed
|
|
134
|
+
- **Transparency**: Use PNG or WebP output to keep it; JPEG drops the alpha channel
|
|
135
|
+
|
|
136
|
+
### Wrong Direction
|
|
137
|
+
- **Issue**: The image turns the opposite way
|
|
138
|
+
- **Solution**: Positive angles turn counter-clockwise; use a negative angle to turn clockwise
|
|
@@ -217,14 +217,17 @@
|
|
|
217
217
|
case 'features+ecc':
|
|
218
218
|
description = 'ORB seeds an ECC refinement pass. Most accurate; recommended default.';
|
|
219
219
|
break;
|
|
220
|
+
case 'shift':
|
|
221
|
+
description = 'Exhaustive translation search. For low-texture or line-scan images where features fail; always a pure shift.';
|
|
222
|
+
break;
|
|
220
223
|
}
|
|
221
224
|
$('#pipeline-description').text(description);
|
|
222
225
|
// ECC Refine policy is only meaningful when ECC actually runs
|
|
223
226
|
$('#ecc-refine-row').toggle(pipeline === 'features+ecc');
|
|
224
227
|
$('#ecc-refine-description').toggle(pipeline === 'features+ecc');
|
|
225
228
|
// Detector is only used by the feature-seed stage
|
|
226
|
-
$('#detector-row').toggle(pipeline
|
|
227
|
-
$('#detector-description').toggle(pipeline
|
|
229
|
+
$('#detector-row').toggle(pipeline === 'features' || pipeline === 'features+ecc');
|
|
230
|
+
$('#detector-description').toggle(pipeline === 'features' || pipeline === 'features+ecc');
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
$('#node-input-pipeline').on('change', updatePipelineDescription);
|
|
@@ -511,6 +514,7 @@
|
|
|
511
514
|
<option value="ecc">ECC only (intensity)</option>
|
|
512
515
|
<option value="features">Features only (ORB)</option>
|
|
513
516
|
<option value="features+ecc">Features → ECC refine</option>
|
|
517
|
+
<option value="shift">Shift search (translation)</option>
|
|
514
518
|
</select>
|
|
515
519
|
</div>
|
|
516
520
|
<div class="form-row">
|
|
@@ -702,6 +706,7 @@
|
|
|
702
706
|
<option value="ecc">ECC only (intensity)</option>
|
|
703
707
|
<option value="features">Features only (ORB)</option>
|
|
704
708
|
<option value="features+ecc">Features → ECC refine</option>
|
|
709
|
+
<option value="shift">Shift search (translation)</option>
|
|
705
710
|
</select>
|
|
706
711
|
</div>
|
|
707
712
|
<div class="form-row">
|
|
@@ -816,6 +821,7 @@
|
|
|
816
821
|
<li><code>ecc</code> — intensity-based ECC only, identity init. Legacy behavior. Fast for small misalignments but diverges when golden and scan are far apart.</li>
|
|
817
822
|
<li><code>features</code> — ORB+RANSAC feature matching only. Robust to large misalignments and rotation/scale; no sub-pixel refinement.</li>
|
|
818
823
|
<li><code>features+ecc</code> — ORB result seeds an ECC refinement pass. Best accuracy. Recommended default for new nodes.</li>
|
|
824
|
+
<li><code>shift</code> — exhaustive translation search: the centre of the target slides over the reference within ±10 % of the height and ±4 % of the width (at least 150 / 60 px), after removing each column and line mean (line-scan column gains, lamp flicker). Always a pure translation, whatever <em>Motion Model</em> says; sub-pixel peak. Fails (no matrix) on a weak match or when the best shift sits on the window edge. For low-texture images or wood grain where feature points are scarce or ambiguous.</li>
|
|
819
825
|
</ul>
|
|
820
826
|
New nodes default to <code>features+ecc</code>; existing saved flows that lack this field fall back to <code>ecc</code> for full backward compatibility. If ECC diverges after a successful feature seed, the seed itself is returned (rather than failing the alignment).
|
|
821
827
|
</dd>
|
|
@@ -862,7 +868,7 @@
|
|
|
862
868
|
<li><code>success</code>: boolean indicating alignment success</li>
|
|
863
869
|
<li><code>timing</code>: processing timing breakdown</li>
|
|
864
870
|
<li><code>preset</code>: speed preset used</li>
|
|
865
|
-
<li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>,
|
|
871
|
+
<li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, <code>features+ecc</code>, or <code>shift</code>)</li>
|
|
866
872
|
<li><code>eccRefine</code>: ECC refinement policy used (<code>always</code>, <code>auto</code>, or <code>never</code>)</li>
|
|
867
873
|
<li><code>detector</code>: feature detector used (<code>orb</code> or <code>sift</code>)</li>
|
|
868
874
|
<li><code>motionModel</code>: motion model used (<code>translation</code>, <code>euclidean</code>, <code>affine</code>, or <code>homography</code>)</li>
|
|
@@ -971,6 +977,7 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
971
977
|
<li><code>ecc</code> — intensity-based ECC only, identity init. Legacy behavior. Fast for small misalignments but diverges when golden and scan are far apart.</li>
|
|
972
978
|
<li><code>features</code> — ORB+RANSAC feature matching only. Robust to large misalignments and rotation/scale; no sub-pixel refinement.</li>
|
|
973
979
|
<li><code>features+ecc</code> — ORB result seeds an ECC refinement pass. Best accuracy. Recommended default for new nodes.</li>
|
|
980
|
+
<li><code>shift</code> — exhaustive translation search: the centre of the target slides over the reference within ±10 % of the height and ±4 % of the width (at least 150 / 60 px), after removing each column and line mean (line-scan column gains, lamp flicker). Always a pure translation, whatever <em>Motion Model</em> says; sub-pixel peak. Fails (no matrix) on a weak match or when the best shift sits on the window edge. For low-texture images or wood grain where feature points are scarce or ambiguous.</li>
|
|
974
981
|
</ul>
|
|
975
982
|
New nodes default to <code>features+ecc</code>; existing saved flows that lack this field fall back to <code>ecc</code> for full backward compatibility. If ECC diverges after a successful feature seed, the seed itself is returned (rather than failing the alignment).
|
|
976
983
|
</dd>
|
|
@@ -1017,7 +1024,7 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
1017
1024
|
<li><code>success</code>: boolean indicating alignment success</li>
|
|
1018
1025
|
<li><code>timing</code>: processing timing breakdown</li>
|
|
1019
1026
|
<li><code>preset</code>: speed preset used</li>
|
|
1020
|
-
<li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>,
|
|
1027
|
+
<li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, <code>features+ecc</code>, or <code>shift</code>)</li>
|
|
1021
1028
|
<li><code>eccRefine</code>: ECC refinement policy used (<code>always</code>, <code>auto</code>, or <code>never</code>)</li>
|
|
1022
1029
|
<li><code>detector</code>: feature detector used (<code>orb</code> or <code>sift</code>)</li>
|
|
1023
1030
|
<li><code>motionModel</code>: motion model used (<code>translation</code>, <code>euclidean</code>, <code>affine</code>, or <code>homography</code>)</li>
|
|
@@ -92,10 +92,11 @@ module.exports = function (RED) {
|
|
|
92
92
|
// ecc - intensity-based ECC only (legacy default)
|
|
93
93
|
// features - ORB+RANSAC only, no ECC refinement
|
|
94
94
|
// features+ecc - ORB seed -> ECC refinement (best accuracy)
|
|
95
|
+
// shift - exhaustive translation search (low-texture / line-scan images)
|
|
95
96
|
// Default 'ecc' for back-compat with flows saved before this field existed;
|
|
96
97
|
// new nodes get 'features+ecc' via the HTML defaults block.
|
|
97
98
|
const pipeline = config.pipeline || 'ecc';
|
|
98
|
-
const VALID_PIPELINES = ['ecc', 'features', 'features+ecc'];
|
|
99
|
+
const VALID_PIPELINES = ['ecc', 'features', 'features+ecc', 'shift'];
|
|
99
100
|
if (!VALID_PIPELINES.includes(pipeline)) {
|
|
100
101
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
101
102
|
node,
|