@rosepetal/node-red-contrib-image-tools 1.4.2 → 1.5.0
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/artifacts/darwin-arm64/package.json +1 -1
- package/artifacts/linux-arm64/package.json +1 -1
- package/artifacts/linux-x64/package.json +1 -1
- package/artifacts/linuxmusl-x64/package.json +1 -1
- package/node-red-contrib-image-tools/lib/inference-transform.js +1 -33
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +243 -16
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +71 -2
- 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 +27 -2
- package/rosepetal-image-engine/src/image-align.cpp +708 -116
- package/scripts/build-opencv-static.ps1 +7 -2
- package/scripts/build-opencv-static.sh +13 -2
|
@@ -292,40 +292,8 @@ function makeRotateTransform(params) {
|
|
|
292
292
|
if (near(0)) {
|
|
293
293
|
return { pointFn: (x, y) => [x, y], opts: {}, maskTransformFn: null };
|
|
294
294
|
}
|
|
295
|
-
if (near(90)) {
|
|
296
|
-
// C++ uses cv::ROTATE_90_COUNTERCLOCKWISE for angle=90
|
|
297
|
-
return {
|
|
298
|
-
pointFn: (x, y) => [y, 1 - x],
|
|
299
|
-
opts: {},
|
|
300
|
-
maskTransformFn: async (mask, cppBridge) => {
|
|
301
|
-
const { image } = await cppBridge.rotate(mask, 90, '#00000000', 'raw', 90, false);
|
|
302
|
-
return image;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
if (near(180)) {
|
|
307
|
-
return {
|
|
308
|
-
pointFn: (x, y) => [1 - x, 1 - y],
|
|
309
|
-
opts: {},
|
|
310
|
-
maskTransformFn: async (mask, cppBridge) => {
|
|
311
|
-
const { image } = await cppBridge.rotate(mask, 180, '#00000000', 'raw', 90, false);
|
|
312
|
-
return image;
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
if (near(270)) {
|
|
317
|
-
// C++ uses cv::ROTATE_90_CLOCKWISE for angle=270
|
|
318
|
-
return {
|
|
319
|
-
pointFn: (x, y) => [1 - y, x],
|
|
320
|
-
opts: {},
|
|
321
|
-
maskTransformFn: async (mask, cppBridge) => {
|
|
322
|
-
const { image } = await cppBridge.rotate(mask, 270, '#00000000', 'raw', 90, false);
|
|
323
|
-
return image;
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
295
|
|
|
328
|
-
//
|
|
296
|
+
// All non-zero angles use the affine matrix path (matches C++ getRotationMatrix2D)
|
|
329
297
|
const rad = angleDeg * DEG;
|
|
330
298
|
const cosA = Math.cos(rad), sinA = Math.sin(rad);
|
|
331
299
|
const absCos = Math.abs(cosA), absSin = Math.abs(sinA);
|
|
@@ -23,6 +23,26 @@
|
|
|
23
23
|
debugWidthType: { value: "num" },
|
|
24
24
|
// Alignment configuration
|
|
25
25
|
preset: { value: "ultra-fast" },
|
|
26
|
+
// Motion model used by the alignment algorithm(s). Default for NEW
|
|
27
|
+
// nodes is "affine" (handles translation + rotation + anisotropic
|
|
28
|
+
// scale + shear); existing saved flows that lack this field fall
|
|
29
|
+
// back to "translation" in image-align.js for full backward
|
|
30
|
+
// compatibility.
|
|
31
|
+
motionModel: { value: "affine" },
|
|
32
|
+
// Pipeline: which alignment algorithm(s) to run.
|
|
33
|
+
// ecc - intensity-only ECC, identity init (legacy)
|
|
34
|
+
// features - ORB+RANSAC only, fast and robust
|
|
35
|
+
// features+ecc - ORB seed -> ECC refinement (best accuracy)
|
|
36
|
+
// New nodes default to features+ecc; existing saved flows fall
|
|
37
|
+
// back to ecc in image-align.js for full backward compatibility.
|
|
38
|
+
pipeline: { value: "features+ecc" },
|
|
39
|
+
// ECC refinement policy when pipeline=features+ecc:
|
|
40
|
+
// always - run ECC every call (legacy default, preserves accuracy)
|
|
41
|
+
// auto - skip ECC when ORB seed has high RANSAC inlier count
|
|
42
|
+
// (>=50). Big speedup on clean feature-rich data.
|
|
43
|
+
// never - never run ECC (equivalent to pipeline=features)
|
|
44
|
+
// Default 'always' for back-compat. Existing saved flows use 'always'.
|
|
45
|
+
eccRefine: { value: "always" },
|
|
26
46
|
returnMatrix: { value: false },
|
|
27
47
|
transformPolygon: { value: false },
|
|
28
48
|
polygonPath: { value: "payload.polygon" },
|
|
@@ -177,6 +197,75 @@
|
|
|
177
197
|
|
|
178
198
|
$('#node-input-preset').on('change', updatePresetDescription);
|
|
179
199
|
updatePresetDescription();
|
|
200
|
+
|
|
201
|
+
// Pipeline description + ECC Refine row visibility
|
|
202
|
+
function updatePipelineDescription() {
|
|
203
|
+
const pipeline = $('#node-input-pipeline').val();
|
|
204
|
+
let description = '';
|
|
205
|
+
switch (pipeline) {
|
|
206
|
+
case 'ecc':
|
|
207
|
+
description = 'Intensity-based ECC only. Fast for small misalignments; diverges if golden and scan are far apart.';
|
|
208
|
+
break;
|
|
209
|
+
case 'features':
|
|
210
|
+
description = 'ORB feature matching + RANSAC. Robust to large misalignments; no sub-pixel refinement.';
|
|
211
|
+
break;
|
|
212
|
+
case 'features+ecc':
|
|
213
|
+
description = 'ORB seeds an ECC refinement pass. Most accurate; recommended default.';
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
$('#pipeline-description').text(description);
|
|
217
|
+
// ECC Refine policy is only meaningful when ECC actually runs
|
|
218
|
+
$('#ecc-refine-row').toggle(pipeline === 'features+ecc');
|
|
219
|
+
$('#ecc-refine-description').toggle(pipeline === 'features+ecc');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
$('#node-input-pipeline').on('change', updatePipelineDescription);
|
|
223
|
+
updatePipelineDescription();
|
|
224
|
+
|
|
225
|
+
// ECC Refine description
|
|
226
|
+
function updateEccRefineDescription() {
|
|
227
|
+
const eccRefine = $('#node-input-eccRefine').val();
|
|
228
|
+
let description = '';
|
|
229
|
+
switch (eccRefine) {
|
|
230
|
+
case 'always':
|
|
231
|
+
description = 'Always run ECC refinement (legacy default, most accurate).';
|
|
232
|
+
break;
|
|
233
|
+
case 'auto':
|
|
234
|
+
description = 'Skip ECC when ORB seed has 50+ RANSAC inliers. Big speedup on clean feature-rich data with ~5% accuracy loss in edge cases.';
|
|
235
|
+
break;
|
|
236
|
+
case 'never':
|
|
237
|
+
description = 'Never run ECC. Equivalent to pipeline=features but keeps the features+ecc mode in saved config.';
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
$('#ecc-refine-description').text(description);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
$('#node-input-eccRefine').on('change', updateEccRefineDescription);
|
|
244
|
+
updateEccRefineDescription();
|
|
245
|
+
|
|
246
|
+
// Motion Model description
|
|
247
|
+
function updateMotionModelDescription() {
|
|
248
|
+
const motionModel = $('#node-input-motionModel').val();
|
|
249
|
+
let description = '';
|
|
250
|
+
switch (motionModel) {
|
|
251
|
+
case 'translation':
|
|
252
|
+
description = 'Pure x/y shift (fastest, 2 DoF). Use when scans only translate.';
|
|
253
|
+
break;
|
|
254
|
+
case 'euclidean':
|
|
255
|
+
description = 'Translation + rotation (3 DoF). Use for rigid in-plane rotation.';
|
|
256
|
+
break;
|
|
257
|
+
case 'affine':
|
|
258
|
+
description = 'Translation + rotation + anisotropic scale + shear (6 DoF). Best general default for printed labels and documents.';
|
|
259
|
+
break;
|
|
260
|
+
case 'homography':
|
|
261
|
+
description = 'Full perspective transform (8 DoF). Use only if you have real perspective distortion; slowest to converge.';
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
$('#motion-model-description').text(description);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
$('#node-input-motionModel').on('change', updateMotionModelDescription);
|
|
268
|
+
updateMotionModelDescription();
|
|
180
269
|
}
|
|
181
270
|
};
|
|
182
271
|
RED.nodes.registerType('rp-image-align', _rpNodeCfg);
|
|
@@ -389,6 +478,46 @@
|
|
|
389
478
|
|
|
390
479
|
<hr>
|
|
391
480
|
|
|
481
|
+
<div class="form-row">
|
|
482
|
+
<label for="node-input-pipeline"><i class="fa fa-cogs"></i> Pipeline</label>
|
|
483
|
+
<select id="node-input-pipeline" style="width: 250px;">
|
|
484
|
+
<option value="ecc">ECC only (intensity)</option>
|
|
485
|
+
<option value="features">Features only (ORB)</option>
|
|
486
|
+
<option value="features+ecc">Features → ECC refine</option>
|
|
487
|
+
</select>
|
|
488
|
+
</div>
|
|
489
|
+
<div class="form-row">
|
|
490
|
+
<label></label>
|
|
491
|
+
<div id="pipeline-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
|
|
492
|
+
</div>
|
|
493
|
+
|
|
494
|
+
<div class="form-row" id="ecc-refine-row">
|
|
495
|
+
<label for="node-input-eccRefine"><i class="fa fa-rocket"></i> ECC Refine</label>
|
|
496
|
+
<select id="node-input-eccRefine" style="width: 250px;">
|
|
497
|
+
<option value="always">Always (legacy, accurate)</option>
|
|
498
|
+
<option value="auto">Auto (skip when seed is strong)</option>
|
|
499
|
+
<option value="never">Never (use seed only)</option>
|
|
500
|
+
</select>
|
|
501
|
+
</div>
|
|
502
|
+
<div class="form-row">
|
|
503
|
+
<label></label>
|
|
504
|
+
<div id="ecc-refine-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
|
|
505
|
+
</div>
|
|
506
|
+
|
|
507
|
+
<div class="form-row">
|
|
508
|
+
<label for="node-input-motionModel"><i class="fa fa-arrows"></i> Motion Model</label>
|
|
509
|
+
<select id="node-input-motionModel" style="width: 200px;">
|
|
510
|
+
<option value="translation">Translation (2 DoF)</option>
|
|
511
|
+
<option value="euclidean">Euclidean (3 DoF, +rotation)</option>
|
|
512
|
+
<option value="affine">Affine (6 DoF, +scale+shear)</option>
|
|
513
|
+
<option value="homography">Homography (8 DoF, +perspective)</option>
|
|
514
|
+
</select>
|
|
515
|
+
</div>
|
|
516
|
+
<div class="form-row">
|
|
517
|
+
<label></label>
|
|
518
|
+
<div id="motion-model-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
|
|
519
|
+
</div>
|
|
520
|
+
|
|
392
521
|
<div class="form-row">
|
|
393
522
|
<label for="node-input-preset"><i class="fa fa-tachometer"></i> Speed Preset</label>
|
|
394
523
|
<select id="node-input-preset" style="width: 200px;">
|
|
@@ -528,6 +657,46 @@
|
|
|
528
657
|
|
|
529
658
|
<hr>
|
|
530
659
|
|
|
660
|
+
<div class="form-row">
|
|
661
|
+
<label for="node-input-pipeline"><i class="fa fa-cogs"></i> Pipeline</label>
|
|
662
|
+
<select id="node-input-pipeline" style="width: 250px;">
|
|
663
|
+
<option value="ecc">ECC only (intensity)</option>
|
|
664
|
+
<option value="features">Features only (ORB)</option>
|
|
665
|
+
<option value="features+ecc">Features → ECC refine</option>
|
|
666
|
+
</select>
|
|
667
|
+
</div>
|
|
668
|
+
<div class="form-row">
|
|
669
|
+
<label></label>
|
|
670
|
+
<div id="pipeline-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
|
|
671
|
+
</div>
|
|
672
|
+
|
|
673
|
+
<div class="form-row" id="ecc-refine-row">
|
|
674
|
+
<label for="node-input-eccRefine"><i class="fa fa-rocket"></i> ECC Refine</label>
|
|
675
|
+
<select id="node-input-eccRefine" style="width: 250px;">
|
|
676
|
+
<option value="always">Always (legacy, accurate)</option>
|
|
677
|
+
<option value="auto">Auto (skip when seed is strong)</option>
|
|
678
|
+
<option value="never">Never (use seed only)</option>
|
|
679
|
+
</select>
|
|
680
|
+
</div>
|
|
681
|
+
<div class="form-row">
|
|
682
|
+
<label></label>
|
|
683
|
+
<div id="ecc-refine-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
|
|
684
|
+
</div>
|
|
685
|
+
|
|
686
|
+
<div class="form-row">
|
|
687
|
+
<label for="node-input-motionModel"><i class="fa fa-arrows"></i> Motion Model</label>
|
|
688
|
+
<select id="node-input-motionModel" style="width: 200px;">
|
|
689
|
+
<option value="translation">Translation (2 DoF)</option>
|
|
690
|
+
<option value="euclidean">Euclidean (3 DoF, +rotation)</option>
|
|
691
|
+
<option value="affine">Affine (6 DoF, +scale+shear)</option>
|
|
692
|
+
<option value="homography">Homography (8 DoF, +perspective)</option>
|
|
693
|
+
</select>
|
|
694
|
+
</div>
|
|
695
|
+
<div class="form-row">
|
|
696
|
+
<label></label>
|
|
697
|
+
<div id="motion-model-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
|
|
698
|
+
</div>
|
|
699
|
+
|
|
531
700
|
<div class="form-row">
|
|
532
701
|
<label for="node-input-preset"><i class="fa fa-tachometer"></i> Speed Preset</label>
|
|
533
702
|
<select id="node-input-preset" style="width: 200px;">
|
|
@@ -590,8 +759,28 @@
|
|
|
590
759
|
<dd>Location where aligned image will be stored. Defaults to <code>msg.payload</code>.</dd>
|
|
591
760
|
<dt>Output Format <span class="property-type">string</span></dt>
|
|
592
761
|
<dd>Output format: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
|
|
762
|
+
<dt>Pipeline <span class="property-type">string</span></dt>
|
|
763
|
+
<dd>Which alignment algorithm(s) to run:
|
|
764
|
+
<ul>
|
|
765
|
+
<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>
|
|
766
|
+
<li><code>features</code> — ORB+RANSAC feature matching only. Robust to large misalignments and rotation/scale; no sub-pixel refinement.</li>
|
|
767
|
+
<li><code>features+ecc</code> — ORB result seeds an ECC refinement pass. Best accuracy. Recommended default for new nodes.</li>
|
|
768
|
+
</ul>
|
|
769
|
+
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).
|
|
770
|
+
</dd>
|
|
771
|
+
<dt>ECC Refine <span class="property-type">string</span></dt>
|
|
772
|
+
<dd>Only used when Pipeline is <code>features+ecc</code>. Controls whether ECC's slow iterative refinement actually runs after the ORB seed:
|
|
773
|
+
<ul>
|
|
774
|
+
<li><code>always</code> — run ECC every call. Most accurate. Legacy default.</li>
|
|
775
|
+
<li><code>auto</code> — skip ECC when the ORB seed has 50+ RANSAC inliers (high confidence). On clean feature-rich data this can save 30-200ms per call with negligible accuracy impact. ECC still runs when features are weak.</li>
|
|
776
|
+
<li><code>never</code> — never run ECC. Equivalent to <code>pipeline=features</code> but keeps the features+ecc mode in the saved config for easy toggling.</li>
|
|
777
|
+
</ul>
|
|
778
|
+
Default <code>always</code> for new nodes and back-compat with existing saved flows.
|
|
779
|
+
</dd>
|
|
780
|
+
<dt>Motion Model <span class="property-type">string</span></dt>
|
|
781
|
+
<dd>Geometric transform shape that the chosen pipeline is allowed to recover. One of <code>translation</code> (2 DoF), <code>euclidean</code> (3 DoF, +rotation), <code>affine</code> (6 DoF, +anisotropic scale + shear), or <code>homography</code> (8 DoF, full perspective). Default for new nodes is <code>affine</code>; existing saved flows that lack this field continue to use <code>translation</code> for full backward compatibility.</dd>
|
|
593
782
|
<dt>Speed Preset <span class="property-type">string</span></dt>
|
|
594
|
-
<dd>Alignment speed/quality balance: <code>ultra-fast</code>, <code>fast</code>, <code>balanced</code>, or <code>quality</code
|
|
783
|
+
<dd>Alignment speed/quality balance: <code>ultra-fast</code>, <code>fast</code>, <code>balanced</code>, or <code>quality</code>. Higher-DoF motion models (affine, homography) may benefit from <code>balanced</code> or <code>quality</code> presets if you observe convergence issues.</dd>
|
|
595
784
|
<dt>Transform Polygon <span class="property-type">boolean</span></dt>
|
|
596
785
|
<dd>When enabled, transforms polygon coordinates from the specified path using the alignment transformation.</dd>
|
|
597
786
|
<dt>Polygon Path <span class="property-type">string</span></dt>
|
|
@@ -614,13 +803,17 @@
|
|
|
614
803
|
<li><code>success</code>: boolean indicating alignment success</li>
|
|
615
804
|
<li><code>timing</code>: processing timing breakdown</li>
|
|
616
805
|
<li><code>preset</code>: speed preset used</li>
|
|
806
|
+
<li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, or <code>features+ecc</code>)</li>
|
|
807
|
+
<li><code>eccRefine</code>: ECC refinement policy used (<code>always</code>, <code>auto</code>, or <code>never</code>)</li>
|
|
808
|
+
<li><code>motionModel</code>: motion model used (<code>translation</code>, <code>euclidean</code>, <code>affine</code>, or <code>homography</code>)</li>
|
|
617
809
|
<li><code>transformMatrix</code>: (optional) transformation matrix when enabled:
|
|
618
810
|
<ul>
|
|
619
811
|
<li><code>dx</code>: horizontal translation in pixels</li>
|
|
620
812
|
<li><code>dy</code>: vertical translation in pixels</li>
|
|
621
|
-
<li><code>matrix2x3</code>: OpenCV 2x3 matrix format [a, b, dx, c, d, dy]</li>
|
|
622
|
-
<li><code>matrix3x3</code>:
|
|
813
|
+
<li><code>matrix2x3</code>: OpenCV 2x3 matrix format [a, b, dx, c, d, dy] (upper rows for homography)</li>
|
|
814
|
+
<li><code>matrix3x3</code>: 3x3 homogeneous matrix - canonical [a,b,dx,c,d,dy,0,0,1] for affine-family, full perspective matrix for homography</li>
|
|
623
815
|
<li><code>transform</code>: alias for matrix3x3 (backward compatibility)</li>
|
|
816
|
+
<li><code>motionModel</code>: copy of the motion model string for introspection</li>
|
|
624
817
|
</ul>
|
|
625
818
|
</li>
|
|
626
819
|
<li><code>originalPolygon</code>: (optional) original polygon coordinates when Transform Polygon is enabled</li>
|
|
@@ -645,12 +838,17 @@
|
|
|
645
838
|
</ul>
|
|
646
839
|
|
|
647
840
|
<h3>Algorithm Details</h3>
|
|
648
|
-
<p>
|
|
841
|
+
<p>Two complementary alignment families are available, selectable via the Pipeline dropdown:</p>
|
|
649
842
|
<ul>
|
|
650
|
-
<li>
|
|
651
|
-
<li>
|
|
652
|
-
|
|
653
|
-
|
|
843
|
+
<li><strong>Feature-based</strong> (ORB + RANSAC): detects keypoints in both images, matches descriptors with brute-force Hamming + Lowe's ratio test, then runs RANSAC to fit the chosen motion model. Robust to large displacements, rotations, and scale changes. Routes to <code>cv::estimateAffinePartial2D</code> (translation/euclidean), <code>cv::estimateAffine2D</code> (affine), or <code>cv::findHomography</code> (homography).</li>
|
|
844
|
+
<li><strong>Intensity-based</strong> (<code>cv::findTransformECC</code>): iterative pixel-wise optimization. Sub-pixel accurate but a local optimizer — needs a good initial guess. Routes to <code>cv::MOTION_TRANSLATION</code> / <code>EUCLIDEAN</code> / <code>AFFINE</code> / <code>HOMOGRAPHY</code> depending on the motion model.</li>
|
|
845
|
+
</ul>
|
|
846
|
+
<p>The two are combined in <code>features+ecc</code>: ORB+RANSAC produces a coarse seed, then ECC refines it from that initial guess. If ECC diverges after the seed, the feature result is returned rather than failing the alignment.</p>
|
|
847
|
+
<ul>
|
|
848
|
+
<li>Images are downscaled for speed (configurable scale factor); both feature detection and ECC refinement run on the same downscaled grid, and the resulting matrix is rescaled to full resolution at the end.</li>
|
|
849
|
+
<li>Affine-family models are warped via <code>cv::warpAffine</code>; homography uses <code>cv::warpPerspective</code>.</li>
|
|
850
|
+
<li>Target image dimensions are adjusted to match reference before alignment.</li>
|
|
851
|
+
<li>Polygon coordinates are remapped through the inverse warp using <code>cv::transform</code> (affine) or <code>cv::perspectiveTransform</code> (homography).</li>
|
|
654
852
|
</ul>
|
|
655
853
|
|
|
656
854
|
<h3>Flexible Input Configuration</h3>
|
|
@@ -707,8 +905,28 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
707
905
|
<dd>Location where aligned image will be stored. Defaults to <code>msg.payload</code>.</dd>
|
|
708
906
|
<dt>Output Format <span class="property-type">string</span></dt>
|
|
709
907
|
<dd>Output format: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
|
|
908
|
+
<dt>Pipeline <span class="property-type">string</span></dt>
|
|
909
|
+
<dd>Which alignment algorithm(s) to run:
|
|
910
|
+
<ul>
|
|
911
|
+
<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>
|
|
912
|
+
<li><code>features</code> — ORB+RANSAC feature matching only. Robust to large misalignments and rotation/scale; no sub-pixel refinement.</li>
|
|
913
|
+
<li><code>features+ecc</code> — ORB result seeds an ECC refinement pass. Best accuracy. Recommended default for new nodes.</li>
|
|
914
|
+
</ul>
|
|
915
|
+
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).
|
|
916
|
+
</dd>
|
|
917
|
+
<dt>ECC Refine <span class="property-type">string</span></dt>
|
|
918
|
+
<dd>Only used when Pipeline is <code>features+ecc</code>. Controls whether ECC's slow iterative refinement actually runs after the ORB seed:
|
|
919
|
+
<ul>
|
|
920
|
+
<li><code>always</code> — run ECC every call. Most accurate. Legacy default.</li>
|
|
921
|
+
<li><code>auto</code> — skip ECC when the ORB seed has 50+ RANSAC inliers (high confidence). On clean feature-rich data this can save 30-200ms per call with negligible accuracy impact. ECC still runs when features are weak.</li>
|
|
922
|
+
<li><code>never</code> — never run ECC. Equivalent to <code>pipeline=features</code> but keeps the features+ecc mode in the saved config for easy toggling.</li>
|
|
923
|
+
</ul>
|
|
924
|
+
Default <code>always</code> for new nodes and back-compat with existing saved flows.
|
|
925
|
+
</dd>
|
|
926
|
+
<dt>Motion Model <span class="property-type">string</span></dt>
|
|
927
|
+
<dd>Geometric transform shape that the chosen pipeline is allowed to recover. One of <code>translation</code> (2 DoF), <code>euclidean</code> (3 DoF, +rotation), <code>affine</code> (6 DoF, +anisotropic scale + shear), or <code>homography</code> (8 DoF, full perspective). Default for new nodes is <code>affine</code>; existing saved flows that lack this field continue to use <code>translation</code> for full backward compatibility.</dd>
|
|
710
928
|
<dt>Speed Preset <span class="property-type">string</span></dt>
|
|
711
|
-
<dd>Alignment speed/quality balance: <code>ultra-fast</code>, <code>fast</code>, <code>balanced</code>, or <code>quality</code
|
|
929
|
+
<dd>Alignment speed/quality balance: <code>ultra-fast</code>, <code>fast</code>, <code>balanced</code>, or <code>quality</code>. Higher-DoF motion models (affine, homography) may benefit from <code>balanced</code> or <code>quality</code> presets if you observe convergence issues.</dd>
|
|
712
930
|
<dt>Transform Polygon <span class="property-type">boolean</span></dt>
|
|
713
931
|
<dd>When enabled, transforms polygon coordinates from the specified path using the alignment transformation.</dd>
|
|
714
932
|
<dt>Polygon Path <span class="property-type">string</span></dt>
|
|
@@ -731,13 +949,17 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
731
949
|
<li><code>success</code>: boolean indicating alignment success</li>
|
|
732
950
|
<li><code>timing</code>: processing timing breakdown</li>
|
|
733
951
|
<li><code>preset</code>: speed preset used</li>
|
|
952
|
+
<li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, or <code>features+ecc</code>)</li>
|
|
953
|
+
<li><code>eccRefine</code>: ECC refinement policy used (<code>always</code>, <code>auto</code>, or <code>never</code>)</li>
|
|
954
|
+
<li><code>motionModel</code>: motion model used (<code>translation</code>, <code>euclidean</code>, <code>affine</code>, or <code>homography</code>)</li>
|
|
734
955
|
<li><code>transformMatrix</code>: (optional) transformation matrix when enabled:
|
|
735
956
|
<ul>
|
|
736
957
|
<li><code>dx</code>: horizontal translation in pixels</li>
|
|
737
958
|
<li><code>dy</code>: vertical translation in pixels</li>
|
|
738
|
-
<li><code>matrix2x3</code>: OpenCV 2x3 matrix format [a, b, dx, c, d, dy]</li>
|
|
739
|
-
<li><code>matrix3x3</code>:
|
|
959
|
+
<li><code>matrix2x3</code>: OpenCV 2x3 matrix format [a, b, dx, c, d, dy] (upper rows for homography)</li>
|
|
960
|
+
<li><code>matrix3x3</code>: 3x3 homogeneous matrix - canonical [a,b,dx,c,d,dy,0,0,1] for affine-family, full perspective matrix for homography</li>
|
|
740
961
|
<li><code>transform</code>: alias for matrix3x3 (backward compatibility)</li>
|
|
962
|
+
<li><code>motionModel</code>: copy of the motion model string for introspection</li>
|
|
741
963
|
</ul>
|
|
742
964
|
</li>
|
|
743
965
|
<li><code>originalPolygon</code>: (optional) original polygon coordinates when Transform Polygon is enabled</li>
|
|
@@ -762,12 +984,17 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
762
984
|
</ul>
|
|
763
985
|
|
|
764
986
|
<h3>Algorithm Details</h3>
|
|
765
|
-
<p>
|
|
987
|
+
<p>Two complementary alignment families are available, selectable via the Pipeline dropdown:</p>
|
|
988
|
+
<ul>
|
|
989
|
+
<li><strong>Feature-based</strong> (ORB + RANSAC): detects keypoints in both images, matches descriptors with brute-force Hamming + Lowe's ratio test, then runs RANSAC to fit the chosen motion model. Robust to large displacements, rotations, and scale changes. Routes to <code>cv::estimateAffinePartial2D</code> (translation/euclidean), <code>cv::estimateAffine2D</code> (affine), or <code>cv::findHomography</code> (homography).</li>
|
|
990
|
+
<li><strong>Intensity-based</strong> (<code>cv::findTransformECC</code>): iterative pixel-wise optimization. Sub-pixel accurate but a local optimizer — needs a good initial guess. Routes to <code>cv::MOTION_TRANSLATION</code> / <code>EUCLIDEAN</code> / <code>AFFINE</code> / <code>HOMOGRAPHY</code> depending on the motion model.</li>
|
|
991
|
+
</ul>
|
|
992
|
+
<p>The two are combined in <code>features+ecc</code>: ORB+RANSAC produces a coarse seed, then ECC refines it from that initial guess. If ECC diverges after the seed, the feature result is returned rather than failing the alignment.</p>
|
|
766
993
|
<ul>
|
|
767
|
-
<li>Images are downscaled for speed (configurable scale factor)
|
|
768
|
-
<li>
|
|
769
|
-
<li>
|
|
770
|
-
<li>
|
|
994
|
+
<li>Images are downscaled for speed (configurable scale factor); both feature detection and ECC refinement run on the same downscaled grid, and the resulting matrix is rescaled to full resolution at the end.</li>
|
|
995
|
+
<li>Affine-family models are warped via <code>cv::warpAffine</code>; homography uses <code>cv::warpPerspective</code>.</li>
|
|
996
|
+
<li>Target image dimensions are adjusted to match reference before alignment.</li>
|
|
997
|
+
<li>Polygon coordinates are remapped through the inverse warp using <code>cv::transform</code> (affine) or <code>cv::perspectiveTransform</code> (homography).</li>
|
|
771
998
|
</ul>
|
|
772
999
|
|
|
773
1000
|
<h3>Flexible Input Configuration</h3>
|
|
@@ -69,6 +69,69 @@ module.exports = function (RED) {
|
|
|
69
69
|
const returnMatrix = config.returnMatrix || false;
|
|
70
70
|
const transformPolygon = config.transformPolygon || false;
|
|
71
71
|
|
|
72
|
+
// Default to 'translation' so existing flows that were saved before
|
|
73
|
+
// motionModel was added behave bit-identically. New nodes set
|
|
74
|
+
// motionModel = 'affine' via the HTML defaults.
|
|
75
|
+
const motionModel = config.motionModel || 'translation';
|
|
76
|
+
const VALID_MOTION_MODELS = ['translation', 'euclidean', 'affine', 'homography'];
|
|
77
|
+
if (!VALID_MOTION_MODELS.includes(motionModel)) {
|
|
78
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
79
|
+
node,
|
|
80
|
+
{
|
|
81
|
+
message: `Invalid motionModel "${motionModel}"`,
|
|
82
|
+
hint: `motionModel must be one of: ${VALID_MOTION_MODELS.join(', ')}`,
|
|
83
|
+
details: { motionModel, referenceImagePath, targetImagePath, outputPath }
|
|
84
|
+
},
|
|
85
|
+
msg, send, done,
|
|
86
|
+
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Pipeline: which alignment algorithm(s) to run.
|
|
91
|
+
// ecc - intensity-based ECC only (legacy default)
|
|
92
|
+
// features - ORB+RANSAC only, no ECC refinement
|
|
93
|
+
// features+ecc - ORB seed -> ECC refinement (best accuracy)
|
|
94
|
+
// Default 'ecc' for back-compat with flows saved before this field existed;
|
|
95
|
+
// new nodes get 'features+ecc' via the HTML defaults block.
|
|
96
|
+
const pipeline = config.pipeline || 'ecc';
|
|
97
|
+
const VALID_PIPELINES = ['ecc', 'features', 'features+ecc'];
|
|
98
|
+
if (!VALID_PIPELINES.includes(pipeline)) {
|
|
99
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
100
|
+
node,
|
|
101
|
+
{
|
|
102
|
+
message: `Invalid pipeline "${pipeline}"`,
|
|
103
|
+
hint: `pipeline must be one of: ${VALID_PIPELINES.join(', ')}`,
|
|
104
|
+
details: { pipeline, referenceImagePath, targetImagePath, outputPath }
|
|
105
|
+
},
|
|
106
|
+
msg, send, done,
|
|
107
|
+
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ECC refinement policy. Only meaningful when pipeline === 'features+ecc'.
|
|
112
|
+
// always - run ECC refinement on every call (legacy default)
|
|
113
|
+
// auto - skip ECC when ORB seed has high RANSAC inlier count (>=50);
|
|
114
|
+
// saves ~10-75% time on clean feature-rich data with ~5%
|
|
115
|
+
// accuracy loss in edge cases
|
|
116
|
+
// never - never run ECC; equivalent to pipeline=features but keeps
|
|
117
|
+
// the features+ecc mode in saved config for easy toggling
|
|
118
|
+
// Default 'always' for back-compat. New nodes also default to 'always'
|
|
119
|
+
// unless the user explicitly opts in via the dropdown.
|
|
120
|
+
const eccRefine = config.eccRefine || 'always';
|
|
121
|
+
const VALID_ECC_REFINE = ['always', 'auto', 'never'];
|
|
122
|
+
if (!VALID_ECC_REFINE.includes(eccRefine)) {
|
|
123
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
124
|
+
node,
|
|
125
|
+
{
|
|
126
|
+
message: `Invalid eccRefine "${eccRefine}"`,
|
|
127
|
+
hint: `eccRefine must be one of: ${VALID_ECC_REFINE.join(', ')}`,
|
|
128
|
+
details: { eccRefine, referenceImagePath, targetImagePath, outputPath }
|
|
129
|
+
},
|
|
130
|
+
msg, send, done,
|
|
131
|
+
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
72
135
|
/* ▸ Read images from message ------------------------------------ */
|
|
73
136
|
// Validate input images
|
|
74
137
|
const ref = NodeUtils.validateImageStructure(referenceImage, node);
|
|
@@ -256,7 +319,10 @@ module.exports = function (RED) {
|
|
|
256
319
|
outputQuality,
|
|
257
320
|
pngOptimize,
|
|
258
321
|
returnMatrix,
|
|
259
|
-
polygon
|
|
322
|
+
polygon,
|
|
323
|
+
motionModel,
|
|
324
|
+
pipeline,
|
|
325
|
+
eccRefine
|
|
260
326
|
);
|
|
261
327
|
|
|
262
328
|
if (useSharpWebp) {
|
|
@@ -313,7 +379,10 @@ module.exports = function (RED) {
|
|
|
313
379
|
msg.alignment = {
|
|
314
380
|
success: result.success,
|
|
315
381
|
timing: result.timing,
|
|
316
|
-
preset: preset
|
|
382
|
+
preset: preset,
|
|
383
|
+
motionModel: motionModel,
|
|
384
|
+
pipeline: pipeline,
|
|
385
|
+
eccRefine: eccRefine
|
|
317
386
|
};
|
|
318
387
|
|
|
319
388
|
// Add transformation matrix if returned
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosepetal/node-red-contrib-image-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Node-RED Image Processing Toolkit",
|
|
5
5
|
"main": "install.sh",
|
|
6
6
|
"directories": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"sharp": "^0.34.2"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.
|
|
39
|
-
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.
|
|
40
|
-
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.
|
|
41
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.
|
|
42
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.
|
|
38
|
+
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.0",
|
|
39
|
+
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.0",
|
|
40
|
+
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.0",
|
|
41
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.0",
|
|
42
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.0"
|
|
43
43
|
},
|
|
44
44
|
"node-red": {
|
|
45
45
|
"version": ">=1.0.0",
|