@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.
- package/.gitattributes +6 -0
- package/.github/workflows/build-prebuild.yml +326 -0
- package/LICENSE +13 -0
- package/README.md +161 -0
- package/artifacts/darwin-arm64/package.json +25 -0
- package/artifacts/linux-arm64/package.json +26 -0
- package/artifacts/linux-x64/package.json +26 -0
- package/artifacts/linuxmusl-x64/package.json +26 -0
- package/assets/flow_time_example.gif +0 -0
- package/assets/nodes/io/array-in-demo.gif +0 -0
- package/assets/nodes/io/array-out-demo.gif +0 -0
- package/assets/nodes/io/array-select-demo.gif +0 -0
- package/assets/nodes/io/image-in-demo.gif +0 -0
- package/assets/nodes/mix/concat-demo.gif +0 -0
- package/assets/nodes/mix/mosaic-demo.gif +0 -0
- package/assets/nodes/transform/crop-demo.gif +0 -0
- package/assets/nodes/transform/filter-demo.gif +0 -0
- package/assets/nodes/transform/padding-demo.gif +0 -0
- package/assets/nodes/transform/resize-demo.gif +0 -0
- package/assets/nodes/transform/rotate-demo.gif +0 -0
- package/docs/nodes/blend/add-mask.md +275 -0
- package/docs/nodes/blend/add-masks.md +284 -0
- package/docs/nodes/blend/blend.md +248 -0
- package/docs/nodes/io/array-in.md +119 -0
- package/docs/nodes/io/array-out.md +150 -0
- package/docs/nodes/io/array-select.md +157 -0
- package/docs/nodes/io/image-in.md +131 -0
- package/docs/nodes/io/image-out.md +179 -0
- package/docs/nodes/io/queue.md +57 -0
- package/docs/nodes/io/save-file.md +30 -0
- package/docs/nodes/mix/advanced-mosaic.md +108 -0
- package/docs/nodes/mix/concat.md +127 -0
- package/docs/nodes/mix/mosaic.md +146 -0
- package/docs/nodes/specialized/cropBB.md +271 -0
- package/docs/nodes/specialized/image-align.md +426 -0
- package/docs/nodes/transform/crop.md +132 -0
- package/docs/nodes/transform/draw.md +77 -0
- package/docs/nodes/transform/filter.md +84 -0
- package/docs/nodes/transform/padding.md +133 -0
- package/docs/nodes/transform/resize.md +158 -0
- package/docs/nodes/transform/rotate.md +121 -0
- package/docs/nodes/util/block-detect.md +46 -0
- package/install.sh +144 -0
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
- package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
- package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
- package/node-red-contrib-image-tools/package.json +64 -0
- package/npm/darwin-arm64/lib/.gitkeep +1 -0
- package/npm/darwin-arm64/package.json +25 -0
- package/npm/darwin-x64/lib/.gitkeep +1 -0
- package/npm/darwin-x64/package.json +25 -0
- package/npm/linux-arm64/lib/.gitkeep +1 -0
- package/npm/linux-arm64/package.json +26 -0
- package/npm/linux-x64/lib/.gitkeep +1 -0
- package/npm/linux-x64/package.json +26 -0
- package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
- package/npm/linuxmusl-x64/package.json +26 -0
- package/npm/win32-x64/lib/.gitkeep +1 -0
- package/npm/win32-x64/package.json +25 -0
- package/package.json +74 -0
- package/rosepetal-image-engine/binding.gyp +153 -0
- package/rosepetal-image-engine/package.json +19 -0
- package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
- package/rosepetal-image-engine/src/add-mask.cpp +240 -0
- package/rosepetal-image-engine/src/add-masks.cpp +638 -0
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
- package/rosepetal-image-engine/src/blend.cpp +200 -0
- package/rosepetal-image-engine/src/concat.cpp +329 -0
- package/rosepetal-image-engine/src/crop.cpp +139 -0
- package/rosepetal-image-engine/src/draw.cpp +414 -0
- package/rosepetal-image-engine/src/filter.cpp +230 -0
- package/rosepetal-image-engine/src/filters/kernels.h +171 -0
- package/rosepetal-image-engine/src/image-align.cpp +551 -0
- package/rosepetal-image-engine/src/main.cpp +36 -0
- package/rosepetal-image-engine/src/mosaic.cpp +373 -0
- package/rosepetal-image-engine/src/padding.cpp +124 -0
- package/rosepetal-image-engine/src/resize.cpp +210 -0
- package/rosepetal-image-engine/src/rotate.cpp +177 -0
- package/rosepetal-image-engine/src/utils.h +563 -0
- package/rosepetal-image-engine/test-formats.js +119 -0
- package/scripts/build-opencv-static.ps1 +166 -0
- package/scripts/build-opencv-static.sh +147 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
# Image-Align Node (Ultra-Fast Image Alignment)
|
|
2
|
+
|
|
3
|
+
## Purpose & Use Cases
|
|
4
|
+
|
|
5
|
+
The `image-align` node provides ultra-fast image alignment using OpenCV's Enhanced Correlation Coefficient (ECC) algorithm. It aligns a target image to match the position and orientation of a reference image, correcting for translation shifts and minor rotations. This is essential for computer vision workflows requiring precise image registration.
|
|
6
|
+
|
|
7
|
+
**Real-World Applications:**
|
|
8
|
+
- **Medical Imaging**: Align sequential scans or multi-modal medical images for comparison
|
|
9
|
+
- **Quality Control**: Register product images for defect detection and comparison analysis
|
|
10
|
+
- **Surveillance Systems**: Align camera feeds for motion detection and background subtraction
|
|
11
|
+
- **Scientific Imaging**: Register microscopy images, satellite imagery, or astronomical photos
|
|
12
|
+
- **Document Processing**: Align scanned documents for OCR and content analysis
|
|
13
|
+
- **Augmented Reality**: Register camera feeds with reference markers for AR overlay
|
|
14
|
+
- **Time-Lapse Photography**: Stabilize sequences by aligning frames to eliminate camera shake
|
|
15
|
+
|
|
16
|
+
*[PLACEHOLDER - Add GIF showing before/after alignment of two shifted images]*
|
|
17
|
+
|
|
18
|
+
## Input/Output Specification
|
|
19
|
+
|
|
20
|
+
### Inputs
|
|
21
|
+
The node expects a message containing two images at configurable paths:
|
|
22
|
+
- **Reference Image**: The target image to align to (template)
|
|
23
|
+
- **Target Image**: The image to be aligned (moved to match reference)
|
|
24
|
+
|
|
25
|
+
### Input Format
|
|
26
|
+
Both images should follow the standard image object format:
|
|
27
|
+
```javascript
|
|
28
|
+
{
|
|
29
|
+
data: Buffer, // Raw pixel data
|
|
30
|
+
width: number, // Image width in pixels
|
|
31
|
+
height: number, // Image height in pixels
|
|
32
|
+
channels: number, // Channel count (1, 3, 4)
|
|
33
|
+
colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
|
|
34
|
+
dtype: string // "uint8" (standard)
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Outputs
|
|
39
|
+
```javascript
|
|
40
|
+
{
|
|
41
|
+
payload: ImageObject, // Aligned image (target aligned to reference)
|
|
42
|
+
alignment: {
|
|
43
|
+
success: boolean, // Whether alignment succeeded
|
|
44
|
+
timing: {
|
|
45
|
+
convertMs: number, // Image conversion time
|
|
46
|
+
taskMs: number, // Alignment processing time
|
|
47
|
+
encodeMs: number // Output encoding time (if not raw)
|
|
48
|
+
},
|
|
49
|
+
preset: string, // Alignment preset used
|
|
50
|
+
transformMatrix: { // Optional: only when returnMatrix enabled
|
|
51
|
+
dx: number, // Horizontal translation in pixels
|
|
52
|
+
dy: number, // Vertical translation in pixels
|
|
53
|
+
matrix2x3: [ // OpenCV 2x3 affine matrix format
|
|
54
|
+
a, b, dx, // [a b dx]
|
|
55
|
+
c, d, dy // [c d dy] where typically a=d=1, b=c=0 for translation
|
|
56
|
+
],
|
|
57
|
+
matrix3x3: [ // Standard 3x3 homogeneous transformation matrix
|
|
58
|
+
a, b, dx, // [a b dx]
|
|
59
|
+
c, d, dy, // [c d dy]
|
|
60
|
+
0, 0, 1 // [0 0 1 ] (homogeneous coordinates)
|
|
61
|
+
],
|
|
62
|
+
transform: [] // Alias for matrix3x3 (backward compatibility)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration Options
|
|
69
|
+
|
|
70
|
+
### Input Configuration
|
|
71
|
+
- **Reference Image Path**: Location of reference image (default: `payload.reference`)
|
|
72
|
+
- **Target Image Path**: Location of target image (default: `payload.target`)
|
|
73
|
+
- **Path Sources**: Support for `msg.*`, `flow.*`, `global.*` contexts
|
|
74
|
+
|
|
75
|
+
### Output Configuration
|
|
76
|
+
- **Output Path**: Where to store aligned image (default: `payload`)
|
|
77
|
+
- **Output Format**: Raw, JPEG, PNG, or WebP
|
|
78
|
+
- **Output Quality**: Compression quality for JPEG/WebP (1-100, default: 90)
|
|
79
|
+
- **PNG Optimization**: Enable PNG compression optimization
|
|
80
|
+
|
|
81
|
+
### Alignment Settings
|
|
82
|
+
|
|
83
|
+
#### Speed Presets
|
|
84
|
+
The node offers four carefully tuned presets balancing speed and accuracy:
|
|
85
|
+
|
|
86
|
+
**Ultra-Fast (Default)**
|
|
87
|
+
- **Scale**: 0.2 (20% resolution for alignment calculation)
|
|
88
|
+
- **Max Iterations**: 10
|
|
89
|
+
- **Termination Epsilon**: 1e-1
|
|
90
|
+
- **Use Case**: Real-time processing, minor alignment corrections
|
|
91
|
+
- **Processing Time**: ~5-15ms per image pair
|
|
92
|
+
|
|
93
|
+
**Fast**
|
|
94
|
+
- **Scale**: 0.3 (30% resolution)
|
|
95
|
+
- **Max Iterations**: 20
|
|
96
|
+
- **Termination Epsilon**: 1e-2
|
|
97
|
+
- **Use Case**: Batch processing with moderate accuracy needs
|
|
98
|
+
- **Processing Time**: ~10-25ms per image pair
|
|
99
|
+
|
|
100
|
+
**Balanced**
|
|
101
|
+
- **Scale**: 0.5 (50% resolution)
|
|
102
|
+
- **Max Iterations**: 30
|
|
103
|
+
- **Termination Epsilon**: 1e-3
|
|
104
|
+
- **Use Case**: General purpose alignment with good accuracy
|
|
105
|
+
- **Processing Time**: ~20-50ms per image pair
|
|
106
|
+
|
|
107
|
+
**Quality**
|
|
108
|
+
- **Scale**: 0.7 (70% resolution)
|
|
109
|
+
- **Max Iterations**: 50
|
|
110
|
+
- **Termination Epsilon**: 1e-4
|
|
111
|
+
- **Use Case**: High precision alignment for critical applications
|
|
112
|
+
- **Processing Time**: ~40-100ms per image pair
|
|
113
|
+
|
|
114
|
+
**Custom**
|
|
115
|
+
- **Scale**: User-defined (0.1-1.0) - Image downscale factor for alignment calculation
|
|
116
|
+
- **Max Iterations**: User-defined (1-200) - Maximum number of ECC iterations
|
|
117
|
+
- **Termination Epsilon**: User-defined (0.000001-0.1) - Convergence threshold
|
|
118
|
+
- **Use Case**: Fine-tuned performance for specific image types or requirements
|
|
119
|
+
- **Processing Time**: Depends on parameters chosen
|
|
120
|
+
|
|
121
|
+
### Advanced Options
|
|
122
|
+
- **Return Matrix**: Enable transformation matrix output for analysis
|
|
123
|
+
- **Debug Mode**: Enable image preview display for development
|
|
124
|
+
- **Debug Width**: Preview image width (default: 200 pixels)
|
|
125
|
+
|
|
126
|
+
## Algorithm Details
|
|
127
|
+
|
|
128
|
+
### Enhanced Correlation Coefficient (ECC)
|
|
129
|
+
The node uses OpenCV's `findTransformECC()` with translation-only motion model for optimal speed:
|
|
130
|
+
|
|
131
|
+
1. **Preprocessing**: Convert both images to grayscale for alignment calculation
|
|
132
|
+
2. **Downsampling**: Scale images by preset factor for faster processing
|
|
133
|
+
3. **ECC Registration**: Find optimal translation transformation using iterative ECC algorithm
|
|
134
|
+
4. **Upscaling**: Scale transformation matrix back to full resolution
|
|
135
|
+
5. **Application**: Apply transformation to original color target image
|
|
136
|
+
6. **Output**: Return aligned target image matching reference position
|
|
137
|
+
|
|
138
|
+
### Motion Model
|
|
139
|
+
- **Translation Only**: Corrects for X/Y shifts (most common alignment need)
|
|
140
|
+
- **Benefits**: Faster processing, more stable than full affine transformation
|
|
141
|
+
- **Limitations**: Cannot correct rotation, scaling, or perspective distortion
|
|
142
|
+
|
|
143
|
+
### Performance Optimizations
|
|
144
|
+
- **Multi-threaded**: Leverages OpenCV's parallel processing capabilities
|
|
145
|
+
- **Memory Efficient**: Processes images in-place where possible
|
|
146
|
+
- **Adaptive Scaling**: Automatic resolution reduction for speed without quality loss
|
|
147
|
+
- **Early Termination**: Stops iteration when convergence criteria met
|
|
148
|
+
|
|
149
|
+
## Performance Notes
|
|
150
|
+
|
|
151
|
+
### C++ Backend Processing
|
|
152
|
+
- **OpenCV ECC**: Professional-grade image registration algorithm
|
|
153
|
+
- **Async Processing**: Non-blocking execution with timing metrics
|
|
154
|
+
- **Memory Management**: Efficient buffer handling between JS/C++ layers
|
|
155
|
+
- **Error Recovery**: Graceful fallback if alignment fails
|
|
156
|
+
|
|
157
|
+
### Speed Characteristics
|
|
158
|
+
- **Ultra-Fast Preset**: 5-15ms processing time, suitable for real-time workflows
|
|
159
|
+
- **Quality Preset**: 40-100ms processing time for precision alignment
|
|
160
|
+
- **Batch Processing**: Parallel execution support for multiple image pairs
|
|
161
|
+
- **Scalability**: Linear performance scaling with image resolution
|
|
162
|
+
|
|
163
|
+
### Memory Usage
|
|
164
|
+
- **Temporary Buffers**: ~2-3x source image memory during processing
|
|
165
|
+
- **Optimization**: Automatic cleanup after processing completion
|
|
166
|
+
- **Large Images**: Consider downsampling very large images for speed
|
|
167
|
+
|
|
168
|
+
## Real-World Examples
|
|
169
|
+
|
|
170
|
+
### Medical Image Registration
|
|
171
|
+
```
|
|
172
|
+
[MRI Scan T1] + [MRI Scan T2] → [Image-Align: quality] → [Registered T2] → [Comparison Analysis]
|
|
173
|
+
```
|
|
174
|
+
Align multi-modal medical images for accurate comparison and analysis.
|
|
175
|
+
|
|
176
|
+
### Quality Control System
|
|
177
|
+
```
|
|
178
|
+
[Reference Product] + [Test Product] → [Image-Align: balanced] → [Aligned Test] → [Defect Detection]
|
|
179
|
+
```
|
|
180
|
+
Register product images for precise defect detection and quality analysis.
|
|
181
|
+
|
|
182
|
+
### Surveillance Motion Detection
|
|
183
|
+
```
|
|
184
|
+
[Background Reference] + [Current Frame] → [Image-Align: ultra-fast] → [Stabilized Frame] → [Motion Analysis]
|
|
185
|
+
```
|
|
186
|
+
Stabilize camera feeds for accurate motion detection and tracking.
|
|
187
|
+
|
|
188
|
+
### Document Processing
|
|
189
|
+
```
|
|
190
|
+
[Template Document] + [Scanned Document] → [Image-Align: fast] → [Registered Scan] → [OCR Processing]
|
|
191
|
+
```
|
|
192
|
+
Align scanned documents with templates for improved OCR accuracy.
|
|
193
|
+
|
|
194
|
+
### Scientific Imaging
|
|
195
|
+
```
|
|
196
|
+
[Reference Microscopy] + [Sample Image] → [Image-Align: quality] → [Registered Sample] → [Analysis Pipeline]
|
|
197
|
+
```
|
|
198
|
+
Register scientific images for precise measurement and comparison.
|
|
199
|
+
|
|
200
|
+
## Common Issues & Troubleshooting
|
|
201
|
+
|
|
202
|
+
### Alignment Failures
|
|
203
|
+
- **Issue**: `alignment.success = false` in output
|
|
204
|
+
- **Causes**: Images too different, poor lighting, insufficient features
|
|
205
|
+
- **Solutions**: Try different preset, improve image quality, use more similar reference
|
|
206
|
+
|
|
207
|
+
### Poor Alignment Quality
|
|
208
|
+
- **Issue**: Images appear misaligned despite success=true
|
|
209
|
+
- **Causes**: Complex transformations beyond translation, low image contrast
|
|
210
|
+
- **Solutions**: Use Quality preset, improve image preprocessing, verify motion model suitability
|
|
211
|
+
|
|
212
|
+
### Performance Issues
|
|
213
|
+
- **Issue**: Slow processing times
|
|
214
|
+
- **Causes**: Large images, complex patterns, high-quality presets
|
|
215
|
+
- **Solutions**: Use Ultra-Fast preset, downsample large images, optimize image quality
|
|
216
|
+
|
|
217
|
+
### Memory Problems
|
|
218
|
+
- **Issue**: Out of memory errors with large images
|
|
219
|
+
- **Causes**: Very high resolution images, insufficient system memory
|
|
220
|
+
- **Solutions**: Downsample images, process in batches, increase system memory
|
|
221
|
+
|
|
222
|
+
### Format Compatibility
|
|
223
|
+
- **Issue**: Alignment fails with certain image formats
|
|
224
|
+
- **Causes**: Unsupported color spaces, unusual bit depths
|
|
225
|
+
- **Solutions**: Convert to standard formats, verify image structure
|
|
226
|
+
|
|
227
|
+
## Integration Patterns
|
|
228
|
+
|
|
229
|
+
### Computer Vision Pipeline
|
|
230
|
+
```
|
|
231
|
+
Image Capture → Preprocessing → Image-Align → Feature Extraction → Analysis
|
|
232
|
+
```
|
|
233
|
+
Standard computer vision workflow with image stabilization.
|
|
234
|
+
|
|
235
|
+
### Quality Inspection System
|
|
236
|
+
```
|
|
237
|
+
Reference Capture → Product Capture → Image-Align → Difference Analysis → Pass/Fail
|
|
238
|
+
```
|
|
239
|
+
Automated quality control with precise image registration.
|
|
240
|
+
|
|
241
|
+
### Medical Imaging Workflow
|
|
242
|
+
```
|
|
243
|
+
Reference Scan → Patient Scan → Image-Align → Comparative Analysis → Diagnosis Support
|
|
244
|
+
```
|
|
245
|
+
Medical image registration for diagnostic comparison.
|
|
246
|
+
|
|
247
|
+
### Document Processing Pipeline
|
|
248
|
+
```
|
|
249
|
+
Template Scan → Document Scan → Image-Align → OCR Processing → Content Extraction
|
|
250
|
+
```
|
|
251
|
+
Document alignment for improved text recognition.
|
|
252
|
+
|
|
253
|
+
## Advanced Usage
|
|
254
|
+
|
|
255
|
+
### Dynamic Preset Selection
|
|
256
|
+
```javascript
|
|
257
|
+
// In function node before image-align:
|
|
258
|
+
// Choose preset based on image characteristics
|
|
259
|
+
const imageSize = msg.payload.reference.width * msg.payload.reference.height;
|
|
260
|
+
if (imageSize > 2000000) { // Large images
|
|
261
|
+
msg.alignmentPreset = 'ultra-fast';
|
|
262
|
+
} else if (msg.criticalAccuracy) {
|
|
263
|
+
msg.alignmentPreset = 'quality';
|
|
264
|
+
} else {
|
|
265
|
+
msg.alignmentPreset = 'balanced';
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Custom Parameters for Fine-Tuning
|
|
270
|
+
```javascript
|
|
271
|
+
// Configure image-align node with custom preset for specific use case
|
|
272
|
+
const nodeConfig = {
|
|
273
|
+
preset: 'custom',
|
|
274
|
+
customScale: 0.4, // Medium resolution for balance
|
|
275
|
+
customMaxIterations: 25, // Moderate iterations
|
|
276
|
+
customTerminationEps: 5e-3 // Balanced convergence threshold
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// Example: High-precision alignment for microscopy images
|
|
280
|
+
const microscopeConfig = {
|
|
281
|
+
preset: 'custom',
|
|
282
|
+
customScale: 0.8, // High resolution to capture fine details
|
|
283
|
+
customMaxIterations: 75, // More iterations for precision
|
|
284
|
+
customTerminationEps: 1e-5 // Very strict convergence
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// Example: Ultra-fast alignment for video frames
|
|
288
|
+
const videoConfig = {
|
|
289
|
+
preset: 'custom',
|
|
290
|
+
customScale: 0.15, // Very low resolution for speed
|
|
291
|
+
customMaxIterations: 5, // Minimal iterations
|
|
292
|
+
customTerminationEps: 0.05 // Loose convergence for speed
|
|
293
|
+
};
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Batch Processing Pattern
|
|
297
|
+
```javascript
|
|
298
|
+
// Process multiple image pairs with consistent reference
|
|
299
|
+
msg.imageQueue.forEach((target, index) => {
|
|
300
|
+
msg.payload = {
|
|
301
|
+
reference: msg.referenceImage, // Consistent reference
|
|
302
|
+
target: target // Different target for each
|
|
303
|
+
};
|
|
304
|
+
// Send to image-align node
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Quality Validation
|
|
309
|
+
```javascript
|
|
310
|
+
// After image-align node:
|
|
311
|
+
if (msg.alignment.success && msg.alignment.timing.taskMs < 100) {
|
|
312
|
+
// Alignment succeeded and was fast - good quality match
|
|
313
|
+
msg.qualityScore = 'excellent';
|
|
314
|
+
} else if (msg.alignment.success) {
|
|
315
|
+
// Alignment succeeded but slow - challenging alignment
|
|
316
|
+
msg.qualityScore = 'good';
|
|
317
|
+
} else {
|
|
318
|
+
// Alignment failed - images too different
|
|
319
|
+
msg.qualityScore = 'poor';
|
|
320
|
+
// Consider fallback processing
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Performance Monitoring
|
|
325
|
+
```javascript
|
|
326
|
+
// Track alignment performance over time
|
|
327
|
+
if (!flow.get('alignmentStats')) {
|
|
328
|
+
flow.set('alignmentStats', { total: 0, successful: 0, avgTime: 0 });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const stats = flow.get('alignmentStats');
|
|
332
|
+
stats.total++;
|
|
333
|
+
if (msg.alignment.success) {
|
|
334
|
+
stats.successful++;
|
|
335
|
+
}
|
|
336
|
+
stats.avgTime = (stats.avgTime * (stats.total - 1) + msg.alignment.timing.taskMs) / stats.total;
|
|
337
|
+
flow.set('alignmentStats', stats);
|
|
338
|
+
|
|
339
|
+
msg.performanceStats = {
|
|
340
|
+
successRate: stats.successful / stats.total,
|
|
341
|
+
averageTime: stats.avgTime
|
|
342
|
+
};
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Transformation Matrix Analysis
|
|
346
|
+
```javascript
|
|
347
|
+
// After image-align node with returnMatrix enabled:
|
|
348
|
+
if (msg.alignment.success && msg.alignment.transformMatrix) {
|
|
349
|
+
const matrix = msg.alignment.transformMatrix;
|
|
350
|
+
|
|
351
|
+
// Simple translation values
|
|
352
|
+
node.log(`Image shifted by dx: ${matrix.dx}, dy: ${matrix.dy} pixels`);
|
|
353
|
+
|
|
354
|
+
// Access different matrix formats
|
|
355
|
+
const opencv2x3 = matrix.matrix2x3; // [a, b, dx, c, d, dy]
|
|
356
|
+
const homogeneous3x3 = matrix.matrix3x3; // [a, b, dx, c, d, dy, 0, 0, 1]
|
|
357
|
+
const transform = matrix.transform; // Same as matrix3x3
|
|
358
|
+
|
|
359
|
+
// Analyze alignment quality
|
|
360
|
+
const totalShift = Math.sqrt(matrix.dx * matrix.dx + matrix.dy * matrix.dy);
|
|
361
|
+
if (totalShift < 5) {
|
|
362
|
+
msg.alignmentQuality = 'excellent';
|
|
363
|
+
} else if (totalShift < 20) {
|
|
364
|
+
msg.alignmentQuality = 'good';
|
|
365
|
+
} else {
|
|
366
|
+
msg.alignmentQuality = 'poor';
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Store for applying to other images
|
|
370
|
+
flow.set('lastAlignment', matrix);
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Applying Transformation to Other Images
|
|
375
|
+
```javascript
|
|
376
|
+
// Use stored transformation matrix to align additional images
|
|
377
|
+
const storedMatrix = flow.get('lastAlignment');
|
|
378
|
+
if (storedMatrix && msg.additionalImages) {
|
|
379
|
+
msg.additionalImages.forEach((image, index) => {
|
|
380
|
+
// Note: You would need a custom transformation function or another alignment node
|
|
381
|
+
// The matrix provides the exact translation values needed
|
|
382
|
+
msg.transformationNeeded = {
|
|
383
|
+
dx: storedMatrix.dx,
|
|
384
|
+
dy: storedMatrix.dy
|
|
385
|
+
};
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Best Practices
|
|
391
|
+
|
|
392
|
+
### Image Preparation
|
|
393
|
+
- Use images with sufficient contrast and distinctive features
|
|
394
|
+
- Ensure reasonable similarity between reference and target images
|
|
395
|
+
- Consider preprocessing (histogram equalization, noise reduction) for challenging images
|
|
396
|
+
- Maintain consistent lighting conditions when possible
|
|
397
|
+
|
|
398
|
+
### Performance Optimization
|
|
399
|
+
- Start with Ultra-Fast preset and upgrade only if accuracy insufficient
|
|
400
|
+
- Downsample very large images (>4MP) before alignment if possible
|
|
401
|
+
- Use Raw output format for processing chains to avoid encoding overhead
|
|
402
|
+
- Monitor timing metrics to optimize preset selection
|
|
403
|
+
|
|
404
|
+
### Quality Control
|
|
405
|
+
- Always check `alignment.success` flag before using results
|
|
406
|
+
- Implement fallback behavior for alignment failures
|
|
407
|
+
- Monitor processing times to detect performance degradation
|
|
408
|
+
- Validate alignment quality using automated metrics when possible
|
|
409
|
+
|
|
410
|
+
### Error Handling
|
|
411
|
+
- Implement graceful handling of alignment failures
|
|
412
|
+
- Provide meaningful feedback for different failure modes
|
|
413
|
+
- Log alignment statistics for system monitoring
|
|
414
|
+
- Consider retry logic with different presets for critical applications
|
|
415
|
+
|
|
416
|
+
### Integration Strategy
|
|
417
|
+
- Design workflows to handle both successful and failed alignments
|
|
418
|
+
- Implement quality scoring based on timing and success metrics
|
|
419
|
+
- Consider batch processing patterns for efficiency with multiple images
|
|
420
|
+
- Plan for scalability based on expected image volumes and quality requirements
|
|
421
|
+
|
|
422
|
+
### Debug and Development
|
|
423
|
+
- Enable debug mode during development for visual verification
|
|
424
|
+
- Use timing metrics to optimize preset selection for your use case
|
|
425
|
+
- Test with representative image pairs from your target domain
|
|
426
|
+
- Validate alignment quality using domain-specific metrics
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Crop Node
|
|
2
|
+
|
|
3
|
+
## Purpose & Use Cases
|
|
4
|
+
|
|
5
|
+
The `crop` node extracts rectangular regions from images with support for both normalized coordinates (0-1) and pixel coordinates. It enables precise region selection for focus areas, object extraction, and image composition.
|
|
6
|
+
|
|
7
|
+
**Real-World Applications:**
|
|
8
|
+
- **Object Extraction**: Extract specific objects or regions of interest
|
|
9
|
+
- **Face Cropping**: Extract detected faces from photographs
|
|
10
|
+
- **Document Processing**: Extract text regions or signatures from scanned documents
|
|
11
|
+
- **Product Photography**: Extract product images from larger scenes
|
|
12
|
+
- **Art Composition**: Extract interesting portions of artwork or photography
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## Input/Output Specification
|
|
17
|
+
|
|
18
|
+
### Inputs
|
|
19
|
+
- **Single Image**: Standard image object format
|
|
20
|
+
- **Image Array**: Array of image objects for batch cropping
|
|
21
|
+
- **Dynamic Coordinates**: Crop parameters can be provided via message properties
|
|
22
|
+
|
|
23
|
+
### Outputs
|
|
24
|
+
- **Cropped Image**: Extracted rectangular region as image object
|
|
25
|
+
- **Format Options**: Raw image object or encoded file formats (JPEG/PNG/WebP)
|
|
26
|
+
|
|
27
|
+
## Configuration Options
|
|
28
|
+
|
|
29
|
+
### Input/Output Paths
|
|
30
|
+
- **Input From**: `msg.payload` (default), `flow.*`, `global.*`
|
|
31
|
+
- **Output To**: `msg.payload` (default), `flow.*`, `global.*`
|
|
32
|
+
|
|
33
|
+
### Coordinate System
|
|
34
|
+
- **Normalized Coordinates**: Toggle between 0-1 range and pixel coordinates
|
|
35
|
+
- **Normalized Mode**: Values from 0.0 to 1.0 (relative to image dimensions)
|
|
36
|
+
- **Pixel Mode**: Absolute pixel coordinates
|
|
37
|
+
|
|
38
|
+
### Crop Parameters
|
|
39
|
+
|
|
40
|
+
#### X Position (cropX)
|
|
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.*`
|
|
49
|
+
|
|
50
|
+
#### Width
|
|
51
|
+
- **Normalized**: 0.0 to 1.0 (proportion of image width)
|
|
52
|
+
- **Pixel**: Absolute width in pixels
|
|
53
|
+
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
54
|
+
|
|
55
|
+
#### Height
|
|
56
|
+
- **Normalized**: 0.0 to 1.0 (proportion of image height)
|
|
57
|
+
- **Pixel**: Absolute height in pixels
|
|
58
|
+
- **Sources**: Number, `msg.*`, `flow.*`, `global.*`
|
|
59
|
+
|
|
60
|
+
### Output Format Options
|
|
61
|
+
- **Raw**: Standard image object (fastest)
|
|
62
|
+
- **JPEG**: Compressed with quality control (1-100)
|
|
63
|
+
- **PNG**: Lossless compression with optional optimization
|
|
64
|
+
- **WebP**: Modern format with quality control
|
|
65
|
+
|
|
66
|
+
## Performance Notes
|
|
67
|
+
|
|
68
|
+
### C++ Backend Processing
|
|
69
|
+
- **High-Speed Extraction**: Optimized OpenCV-based region extraction
|
|
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
|
|
78
|
+
|
|
79
|
+
## Real-World Examples
|
|
80
|
+
|
|
81
|
+
### Face Extraction (Normalized)
|
|
82
|
+
```
|
|
83
|
+
[Face Detection] → [Set msg.faceBox] → [Crop: X=msg.x, Y=msg.y, W=msg.w, H=msg.h] → [Face Image]
|
|
84
|
+
```
|
|
85
|
+
Extract detected faces using normalized coordinates from AI detection.
|
|
86
|
+
|
|
87
|
+
### Center Crop
|
|
88
|
+
```
|
|
89
|
+
[Image-In] → [Crop: X=0.25, Y=0.25, W=0.5, H=0.5] → [Center Square]
|
|
90
|
+
```
|
|
91
|
+
Extract the center 50% of any image.
|
|
92
|
+
|
|
93
|
+
### Document Region Extraction (Pixel)
|
|
94
|
+
```
|
|
95
|
+
[Scanned Document] → [Crop: X=100, Y=150, W=800, H=600] → [Text Region]
|
|
96
|
+
```
|
|
97
|
+
Extract specific document regions using pixel coordinates.
|
|
98
|
+
|
|
99
|
+
### Batch Product Extraction
|
|
100
|
+
```
|
|
101
|
+
[Product Photos] → [Array-Out] → [Crop: Normalized] → [Product Cutouts]
|
|
102
|
+
```
|
|
103
|
+
Extract product regions from multiple photos.
|
|
104
|
+
|
|
105
|
+
### Dynamic ROI Extraction
|
|
106
|
+
```
|
|
107
|
+
[Analysis] → [Set ROI Coords] → [Crop: Dynamic] → [Region of Interest]
|
|
108
|
+
```
|
|
109
|
+
Extract regions based on image analysis results.
|
|
110
|
+
|
|
111
|
+
## Common Issues & Troubleshooting
|
|
112
|
+
|
|
113
|
+
### Coordinate System Confusion
|
|
114
|
+
- **Issue**: Unexpected crop results
|
|
115
|
+
- **Solution**: Verify normalized vs pixel mode matches your coordinate system
|
|
116
|
+
- **Normalized**: Use 0-1 values for relative positioning
|
|
117
|
+
- **Pixel**: Use absolute coordinates
|
|
118
|
+
|
|
119
|
+
### Out of Bounds Cropping
|
|
120
|
+
- **Issue**: Crop region extends beyond image boundaries
|
|
121
|
+
- **Result**: Automatic clipping to image bounds with warning
|
|
122
|
+
- **Prevention**: Validate coordinates before processing
|
|
123
|
+
|
|
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
|
+
### Dynamic Coordinate Errors
|
|
130
|
+
- **Issue**: Message properties don't contain valid coordinates
|
|
131
|
+
- **Solution**: Use debug nodes to verify coordinate values
|
|
132
|
+
- **Validation**: Check that dynamic sources provide numbers
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Draw Node
|
|
2
|
+
|
|
3
|
+
## Purpose & Use Cases
|
|
4
|
+
|
|
5
|
+
The `draw` node overlays configurable points and lines on top of an input image using normalized coordinates. Rendering happens in the Rosepetal C++ engine, keeping overlays crisp even on high-resolution imagery.
|
|
6
|
+
|
|
7
|
+
**Typical scenarios**
|
|
8
|
+
- Visualizing detections (keypoints, landmarks, segmentation anchors)
|
|
9
|
+
- Highlighting measurement locations or points-of-interest
|
|
10
|
+
- Connecting bounding boxes with relational lines
|
|
11
|
+
- Creating quick debugging overlays inside automation flows
|
|
12
|
+
|
|
13
|
+
## Input / Output
|
|
14
|
+
|
|
15
|
+
### Input
|
|
16
|
+
- **Image**: Single image object or encoded buffer following the standard toolkit format (`data`, `width`, `height`, `channels`, `colorSpace`, `dtype`).
|
|
17
|
+
- Source path defaults to `msg.payload` and can be remapped to any `msg`, `flow`, or `global` property.
|
|
18
|
+
|
|
19
|
+
### Output
|
|
20
|
+
- Augmented image delivered in raw format (default) or encoded as `jpg`, `png`, or `webp`, matching the rest of the toolkit conventions.
|
|
21
|
+
- Output path defaults to `msg.payload`.
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
### I/O
|
|
26
|
+
- **Input From / Output To**: Typed inputs (`msg`, `flow`, `global`) for flexible integration.
|
|
27
|
+
- **Output Format**: `raw`, `jpg`, `png`, or `webp`. Quality and PNG optimization options appear when relevant.
|
|
28
|
+
|
|
29
|
+
### Points
|
|
30
|
+
Each list entry configures one point:
|
|
31
|
+
- **X / Y**: Normalized coordinates (`0.0 – 1.0`) with dynamic sources (`num`, `msg`, `flow`, `global`).
|
|
32
|
+
- **Radius**: Normalized size relative to the shortest image dimension (minimum 1 pixel).
|
|
33
|
+
- **Color**: Hex string (e.g. `#FF0066`). Can be resolved from context if needed.
|
|
34
|
+
- **Opacity**: Overlay strength (`0.0 – 1.0`). Combined with any alpha channel supplied in the color.
|
|
35
|
+
- **List mode**: Flip the row to *List* to provide `[[x,y], ...]` in one go (from JSON, msg, flow, or global). The row’s radius/color/opacity apply to every list entry.
|
|
36
|
+
|
|
37
|
+
Click **+** to add points and **🗑** to remove. Fields keep their typed-input settings, allowing mixed static and dynamic values.
|
|
38
|
+
|
|
39
|
+
### Lines
|
|
40
|
+
Each list entry defines a polyline segment:
|
|
41
|
+
- **Start / End (X1, Y1, X2, Y2)**: Normalized coordinates.
|
|
42
|
+
- **Thickness**: Normalized width relative to the shortest dimension (minimum 1 pixel).
|
|
43
|
+
- **Color**: Hex string or dynamic string.
|
|
44
|
+
- **Opacity**: Blend factor (`0.0 – 1.0`).
|
|
45
|
+
- **List mode**: Use *List* to feed multiple lines at once as `[[x0,y0,x1,y1], ...]`. Thickness/color/opacity are reused for each segment.
|
|
46
|
+
|
|
47
|
+
### Debugging
|
|
48
|
+
- **Debug switch**: Streams a preview via the standard Rosepetal debug channel.
|
|
49
|
+
- **Debug width**: Typed value controlling the preview size.
|
|
50
|
+
|
|
51
|
+
## Runtime Behaviour
|
|
52
|
+
|
|
53
|
+
1. The node validates the input image using shared `node-utils` helpers.
|
|
54
|
+
2. Points and lines are resolved via typed inputs—dynamic properties are evaluated per message.
|
|
55
|
+
3. The C++ engine converts normalized coordinates to pixels and composites overlays with anti-aliasing and alpha-aware blending.
|
|
56
|
+
4. Timing information (convert / task / encode) feeds the standard status display.
|
|
57
|
+
5. Optional debug previews reuse the existing toolkit infrastructure (`debug-image` WebSocket).
|
|
58
|
+
|
|
59
|
+
## Tips & Edge Cases
|
|
60
|
+
|
|
61
|
+
- Coordinates outside `[0, 1]` are rejected with warns and skipped.
|
|
62
|
+
- Empty point and line lists pass the image through unchanged.
|
|
63
|
+
- 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.
|
|
65
|
+
- For chained overlays, prefer `raw` output to avoid repeated re-encoding.
|
|
66
|
+
|
|
67
|
+
## Example Flow
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
[image-in]
|
|
71
|
+
└─▶ [draw]
|
|
72
|
+
• point: x=msg.face.x, y=msg.face.y, radius=0.02, color=#00FFEE
|
|
73
|
+
• line: x1=0.1, y1=0.9 → x2=0.9, y2=0.9, thickness=0.004, color=#FFAA00
|
|
74
|
+
└─▶ [image-out]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This creates a face marker plus a baseline overlay, fully driven by message content.
|