@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.
Files changed (131) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/workflows/build-prebuild.yml +326 -0
  3. package/LICENSE +13 -0
  4. package/README.md +161 -0
  5. package/artifacts/darwin-arm64/package.json +25 -0
  6. package/artifacts/linux-arm64/package.json +26 -0
  7. package/artifacts/linux-x64/package.json +26 -0
  8. package/artifacts/linuxmusl-x64/package.json +26 -0
  9. package/assets/flow_time_example.gif +0 -0
  10. package/assets/nodes/io/array-in-demo.gif +0 -0
  11. package/assets/nodes/io/array-out-demo.gif +0 -0
  12. package/assets/nodes/io/array-select-demo.gif +0 -0
  13. package/assets/nodes/io/image-in-demo.gif +0 -0
  14. package/assets/nodes/mix/concat-demo.gif +0 -0
  15. package/assets/nodes/mix/mosaic-demo.gif +0 -0
  16. package/assets/nodes/transform/crop-demo.gif +0 -0
  17. package/assets/nodes/transform/filter-demo.gif +0 -0
  18. package/assets/nodes/transform/padding-demo.gif +0 -0
  19. package/assets/nodes/transform/resize-demo.gif +0 -0
  20. package/assets/nodes/transform/rotate-demo.gif +0 -0
  21. package/docs/nodes/blend/add-mask.md +275 -0
  22. package/docs/nodes/blend/add-masks.md +284 -0
  23. package/docs/nodes/blend/blend.md +248 -0
  24. package/docs/nodes/io/array-in.md +119 -0
  25. package/docs/nodes/io/array-out.md +150 -0
  26. package/docs/nodes/io/array-select.md +157 -0
  27. package/docs/nodes/io/image-in.md +131 -0
  28. package/docs/nodes/io/image-out.md +179 -0
  29. package/docs/nodes/io/queue.md +57 -0
  30. package/docs/nodes/io/save-file.md +30 -0
  31. package/docs/nodes/mix/advanced-mosaic.md +108 -0
  32. package/docs/nodes/mix/concat.md +127 -0
  33. package/docs/nodes/mix/mosaic.md +146 -0
  34. package/docs/nodes/specialized/cropBB.md +271 -0
  35. package/docs/nodes/specialized/image-align.md +426 -0
  36. package/docs/nodes/transform/crop.md +132 -0
  37. package/docs/nodes/transform/draw.md +77 -0
  38. package/docs/nodes/transform/filter.md +84 -0
  39. package/docs/nodes/transform/padding.md +133 -0
  40. package/docs/nodes/transform/resize.md +158 -0
  41. package/docs/nodes/transform/rotate.md +121 -0
  42. package/docs/nodes/util/block-detect.md +46 -0
  43. package/install.sh +144 -0
  44. package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
  45. package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
  46. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
  47. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
  48. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
  49. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
  50. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
  51. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
  52. package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
  53. package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
  54. package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
  55. package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
  56. package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
  57. package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
  58. package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
  59. package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
  60. package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
  61. package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
  62. package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
  63. package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
  64. package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
  65. package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
  66. package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
  67. package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
  68. package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
  69. package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
  70. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
  71. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
  72. package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
  73. package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
  74. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
  75. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
  76. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
  77. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
  78. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
  79. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
  80. package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
  81. package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
  82. package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
  83. package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
  84. package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
  85. package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
  86. package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
  87. package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
  88. package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
  89. package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
  90. package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
  91. package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
  92. package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
  93. package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
  94. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
  95. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
  96. package/node-red-contrib-image-tools/package.json +64 -0
  97. package/npm/darwin-arm64/lib/.gitkeep +1 -0
  98. package/npm/darwin-arm64/package.json +25 -0
  99. package/npm/darwin-x64/lib/.gitkeep +1 -0
  100. package/npm/darwin-x64/package.json +25 -0
  101. package/npm/linux-arm64/lib/.gitkeep +1 -0
  102. package/npm/linux-arm64/package.json +26 -0
  103. package/npm/linux-x64/lib/.gitkeep +1 -0
  104. package/npm/linux-x64/package.json +26 -0
  105. package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
  106. package/npm/linuxmusl-x64/package.json +26 -0
  107. package/npm/win32-x64/lib/.gitkeep +1 -0
  108. package/npm/win32-x64/package.json +25 -0
  109. package/package.json +74 -0
  110. package/rosepetal-image-engine/binding.gyp +153 -0
  111. package/rosepetal-image-engine/package.json +19 -0
  112. package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
  113. package/rosepetal-image-engine/src/add-mask.cpp +240 -0
  114. package/rosepetal-image-engine/src/add-masks.cpp +638 -0
  115. package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
  116. package/rosepetal-image-engine/src/blend.cpp +200 -0
  117. package/rosepetal-image-engine/src/concat.cpp +329 -0
  118. package/rosepetal-image-engine/src/crop.cpp +139 -0
  119. package/rosepetal-image-engine/src/draw.cpp +414 -0
  120. package/rosepetal-image-engine/src/filter.cpp +230 -0
  121. package/rosepetal-image-engine/src/filters/kernels.h +171 -0
  122. package/rosepetal-image-engine/src/image-align.cpp +551 -0
  123. package/rosepetal-image-engine/src/main.cpp +36 -0
  124. package/rosepetal-image-engine/src/mosaic.cpp +373 -0
  125. package/rosepetal-image-engine/src/padding.cpp +124 -0
  126. package/rosepetal-image-engine/src/resize.cpp +210 -0
  127. package/rosepetal-image-engine/src/rotate.cpp +177 -0
  128. package/rosepetal-image-engine/src/utils.h +563 -0
  129. package/rosepetal-image-engine/test-formats.js +119 -0
  130. package/scripts/build-opencv-static.ps1 +166 -0
  131. package/scripts/build-opencv-static.sh +147 -0
@@ -0,0 +1,528 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('image-align', {
3
+ category: 'RP Image',
4
+ color: '#DDA0DD',
5
+ defaults: {
6
+ name: { value: "" },
7
+ // Image path configurations (like blend node)
8
+ referenceImagePath: { value: "payload.reference" },
9
+ referenceImagePathType: { value: "msg" },
10
+ targetImagePath: { value: "payload.target" },
11
+ targetImagePathType: { value: "msg" },
12
+ outputPath: { value: "payload" },
13
+ outputPathType: { value: "msg" },
14
+ outputFormat: { value: "raw" },
15
+ outputQuality: { value: 90 },
16
+ pngOptimize: { value: false },
17
+ // Debug configuration
18
+ debugEnabled: { value: false },
19
+ debugWidth: { value: 200 },
20
+ debugWidthType: { value: "num" },
21
+ // Alignment configuration
22
+ preset: { value: "ultra-fast" },
23
+ returnMatrix: { value: false },
24
+ transformPolygon: { value: false },
25
+ polygonPath: { value: "payload.polygon" },
26
+ polygonPathType: { value: "msg" },
27
+ // Custom parameters
28
+ customScale: { value: 0.2 },
29
+ customScaleType: { value: "num" },
30
+ customMaxIterations: { value: 10 },
31
+ customMaxIterationsType: { value: "num" },
32
+ customTerminationEps: { value: 0.1 },
33
+ customTerminationEpsType: { value: "num" }
34
+ },
35
+ inputs: 1,
36
+ outputs: 1,
37
+ icon: "font-awesome/fa-crosshairs",
38
+ label: function() {
39
+ if (this.name) { return this.name; }
40
+ return `align (${this.preset})`;
41
+ },
42
+ oneditprepare: function() {
43
+ /* path typedInputs */
44
+ $("#node-input-referenceImagePath").typedInput({
45
+ default: 'msg',
46
+ types: ['msg', 'flow', 'global'],
47
+ typeField: "#node-input-referenceImagePathType"
48
+ });
49
+ $("#node-input-targetImagePath").typedInput({
50
+ default: 'msg',
51
+ types: ['msg', 'flow', 'global'],
52
+ typeField: "#node-input-targetImagePathType"
53
+ });
54
+ $("#node-input-outputPath").typedInput({
55
+ default: 'msg',
56
+ types: ['msg', 'flow', 'global'],
57
+ typeField: "#node-input-outputPathType"
58
+ });
59
+ $("#node-input-polygonPath").typedInput({
60
+ default: 'msg',
61
+ types: ['msg', 'flow', 'global'],
62
+ typeField: "#node-input-polygonPathType"
63
+ });
64
+
65
+ // Initialize debug width TypedInput
66
+ $("#node-input-debugWidth").typedInput({
67
+ default: 'num',
68
+ types: ['num', 'msg', 'flow', 'global'],
69
+ typeField: "#node-input-debugWidthType"
70
+ });
71
+
72
+ // Initialize custom parameter TypedInputs
73
+ $("#node-input-customScale").typedInput({
74
+ default: 'num',
75
+ types: ['num', 'msg', 'flow', 'global'],
76
+ typeField: "#node-input-customScaleType"
77
+ });
78
+ $("#node-input-customMaxIterations").typedInput({
79
+ default: 'num',
80
+ types: ['num', 'msg', 'flow', 'global'],
81
+ typeField: "#node-input-customMaxIterationsType"
82
+ });
83
+ $("#node-input-customTerminationEps").typedInput({
84
+ default: 'num',
85
+ types: ['num', 'msg', 'flow', 'global'],
86
+ typeField: "#node-input-customTerminationEpsType"
87
+ });
88
+
89
+ // Output Format Logic
90
+ function updateQualityVisibility() {
91
+ const format = $('#node-input-outputFormat').val();
92
+ if (format === 'jpg' || format === 'webp') {
93
+ $('#quality-row').show();
94
+ } else {
95
+ $('#quality-row').hide();
96
+ }
97
+
98
+ if (format === 'png') {
99
+ $('#png-optimize-row').show();
100
+ } else {
101
+ $('#png-optimize-row').hide();
102
+ }
103
+ }
104
+
105
+ $('#node-input-outputFormat').on('change', updateQualityVisibility);
106
+ updateQualityVisibility();
107
+
108
+ // Debug Display Logic
109
+ const debugCheckbox = $('#node-input-debugEnabled');
110
+ const debugWidthRow = $('#debug-width-row');
111
+
112
+ function updateDebugWidthVisibility() {
113
+ if (debugCheckbox.is(':checked')) {
114
+ debugWidthRow.show();
115
+ } else {
116
+ debugWidthRow.hide();
117
+ }
118
+ }
119
+
120
+ updateDebugWidthVisibility();
121
+ debugCheckbox.on('change', updateDebugWidthVisibility);
122
+
123
+ // Transform Polygon Logic
124
+ const transformPolygonCheckbox = $('#node-input-transformPolygon');
125
+ const polygonPathRow = $('#polygon-path-row');
126
+
127
+ function updatePolygonPathVisibility() {
128
+ if (transformPolygonCheckbox.is(':checked')) {
129
+ polygonPathRow.show();
130
+ } else {
131
+ polygonPathRow.hide();
132
+ }
133
+ }
134
+
135
+ updatePolygonPathVisibility();
136
+ transformPolygonCheckbox.on('change', updatePolygonPathVisibility);
137
+
138
+ // Preset description and custom parameters visibility
139
+ function updatePresetDescription() {
140
+ const preset = $('#node-input-preset').val();
141
+ let description = '';
142
+ const customParams = $('#custom-parameters');
143
+
144
+ switch(preset) {
145
+ case 'ultra-fast':
146
+ description = 'Maximum speed, basic accuracy (scale: 0.2, iter: 10)';
147
+ customParams.hide();
148
+ break;
149
+ case 'fast':
150
+ description = 'Good speed, decent accuracy (scale: 0.3, iter: 20)';
151
+ customParams.hide();
152
+ break;
153
+ case 'balanced':
154
+ description = 'Balanced speed and accuracy (scale: 0.5, iter: 30)';
155
+ customParams.hide();
156
+ break;
157
+ case 'quality':
158
+ description = 'Best accuracy, slower processing (scale: 0.7, iter: 50)';
159
+ customParams.hide();
160
+ break;
161
+ case 'custom':
162
+ description = 'Custom parameters - configure scale, iterations, and convergence';
163
+ customParams.show();
164
+ break;
165
+ }
166
+
167
+ $('#preset-description').text(description);
168
+ }
169
+
170
+ $('#node-input-preset').on('change', updatePresetDescription);
171
+ updatePresetDescription();
172
+ }
173
+ });
174
+
175
+ // Debug image display renderer (shared)
176
+ if (!window.debugImageRendererInitialized) {
177
+ window.debugImageRendererInitialized = true;
178
+
179
+ (function() {
180
+ var isSubscribed = false;
181
+
182
+ function subscribeToDebugImages() {
183
+ if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
184
+ isSubscribed = true;
185
+
186
+ RED.comms.subscribe('debug-image', function(event, data) {
187
+ if (!data || !data.id) return;
188
+
189
+ try {
190
+ renderDebugImage(data);
191
+ } catch (err) {
192
+ console.warn('Debug image render error:', err);
193
+ }
194
+ });
195
+ }
196
+
197
+ function renderDebugImage(data) {
198
+ const nodeId = data.id;
199
+ const base64Data = data.data;
200
+ const format = data.format || 'unknown';
201
+ const mimeType = data.mimeType || 'jpeg';
202
+
203
+ if (!base64Data) {
204
+ removeDebugImage(nodeId);
205
+ return;
206
+ }
207
+
208
+ const nodeElement = document.getElementById(nodeId);
209
+ if (!nodeElement) return;
210
+
211
+ const debugWidth = data.debugWidth || 200;
212
+ const debugHeight = data.debugHeight || 200;
213
+ const maxDisplayWidth = Math.min(debugWidth, 500);
214
+ const displayHeight = debugHeight * (maxDisplayWidth / debugWidth);
215
+
216
+ let debugContainer = document.getElementById('debug-img-container-' + nodeId);
217
+
218
+ if (!debugContainer) {
219
+ debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
220
+ debugContainer.id = 'debug-img-container-' + nodeId;
221
+ debugContainer.setAttribute('x', '0');
222
+ debugContainer.setAttribute('y', '45');
223
+ debugContainer.setAttribute('width', maxDisplayWidth.toString());
224
+ debugContainer.setAttribute('height', displayHeight.toString());
225
+ debugContainer.style.overflow = 'visible';
226
+
227
+ const img = document.createElement('img');
228
+ img.id = 'debug-img-' + nodeId;
229
+ img.style.width = '100%';
230
+ img.style.height = 'auto';
231
+ img.style.display = 'block';
232
+ img.style.cursor = 'pointer';
233
+ img.style.maxHeight = 'none';
234
+ img.style.maxWidth = 'none';
235
+
236
+ img.onclick = function() {
237
+ removeDebugImage(nodeId);
238
+ };
239
+
240
+ debugContainer.appendChild(img);
241
+ nodeElement.appendChild(debugContainer);
242
+ } else {
243
+ debugContainer.setAttribute('width', maxDisplayWidth.toString());
244
+ debugContainer.setAttribute('height', displayHeight.toString());
245
+ }
246
+
247
+ const img = document.getElementById('debug-img-' + nodeId);
248
+ if (img) {
249
+ img.src = `data:image/${mimeType};base64,${base64Data}`;
250
+ img.title = 'Debug aligned image (click to hide)';
251
+ }
252
+ }
253
+
254
+ function removeDebugImage(nodeId) {
255
+ const debugContainer = document.getElementById('debug-img-container-' + nodeId);
256
+ if (debugContainer) {
257
+ debugContainer.remove();
258
+ }
259
+ }
260
+
261
+ function initializeWhenReady() {
262
+ if (typeof RED !== 'undefined' && RED.comms) {
263
+ subscribeToDebugImages();
264
+
265
+ setInterval(function() {
266
+ const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
267
+ debugContainers.forEach(container => {
268
+ const nodeId = container.id.replace('debug-img-container-', '');
269
+ const nodeElement = document.getElementById(nodeId);
270
+ if (!nodeElement) {
271
+ container.remove();
272
+ }
273
+ });
274
+ }, 5000);
275
+ } else {
276
+ setTimeout(initializeWhenReady, 100);
277
+ }
278
+ }
279
+
280
+ if (document.readyState === 'loading') {
281
+ document.addEventListener('DOMContentLoaded', initializeWhenReady);
282
+ } else {
283
+ initializeWhenReady();
284
+ }
285
+ })();
286
+ }
287
+ </script>
288
+
289
+ <script type="text/x-red" data-template-name="image-align">
290
+ <div class="form-row">
291
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
292
+ <input type="text" id="node-input-name" placeholder="Name">
293
+ </div>
294
+
295
+ <hr>
296
+
297
+ <div class="form-row">
298
+ <label for="node-input-referenceImagePath"><i class="fa fa-photo"></i> Reference Image</label>
299
+ <input type="text" id="node-input-referenceImagePath" style="width: 70%;">
300
+ <input type="hidden" id="node-input-referenceImagePathType">
301
+ </div>
302
+ <div class="form-row">
303
+ <label for="node-input-targetImagePath"><i class="fa fa-photo"></i> Target Image</label>
304
+ <input type="text" id="node-input-targetImagePath" style="width: 70%;">
305
+ <input type="hidden" id="node-input-targetImagePathType">
306
+ </div>
307
+ <div class="form-row">
308
+ <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
309
+ <input type="text" id="node-input-outputPath" style="width: 70%;">
310
+ <input type="hidden" id="node-input-outputPathType">
311
+ </div>
312
+
313
+ <div class="form-row">
314
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
315
+ <select id="node-input-outputFormat" style="width: 200px;">
316
+ <option value="raw">Raw (fastest)</option>
317
+ <option value="jpg">JPEG</option>
318
+ <option value="png">PNG</option>
319
+ <option value="webp">WebP</option>
320
+ </select>
321
+ </div>
322
+ <div class="form-row" id="quality-row">
323
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
324
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
325
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
326
+ </div>
327
+ <div class="form-row" id="png-optimize-row" style="display: none;">
328
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
329
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
330
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
331
+ </div>
332
+
333
+ <!-- Return Matrix Option -->
334
+ <div class="form-row">
335
+ <label for="node-input-returnMatrix"><i class="fa fa-calculator"></i> Transform Matrix</label>
336
+ <input type="checkbox" id="node-input-returnMatrix" style="display:inline-block; width:auto; vertical-align:baseline;">
337
+ <label for="node-input-returnMatrix" style="width:auto; margin-left:5px;">Return transformation matrix</label>
338
+ </div>
339
+
340
+ <!-- Transform Polygon Option -->
341
+ <div class="form-row">
342
+ <label for="node-input-transformPolygon"><i class="fa fa-draw-polygon"></i> Transform Polygon</label>
343
+ <input type="checkbox" id="node-input-transformPolygon" style="display:inline-block; width:auto; vertical-align:baseline;">
344
+ <label for="node-input-transformPolygon" style="width:auto; margin-left:5px;">Transform polygon coordinates</label>
345
+ </div>
346
+ <div class="form-row" id="polygon-path-row" style="display: none;">
347
+ <label for="node-input-polygonPath"><i class="fa fa-map-marker"></i> Polygon Path</label>
348
+ <input type="text" id="node-input-polygonPath" style="width: 70%;">
349
+ <input type="hidden" id="node-input-polygonPathType">
350
+ </div>
351
+
352
+ <!-- Debug Configuration -->
353
+ <div class="form-row">
354
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
355
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
356
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show aligned image</label>
357
+ </div>
358
+ <div class="form-row" id="debug-width-row" style="display: none;">
359
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
360
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
361
+ <input type="hidden" id="node-input-debugWidthType">
362
+ <span style="margin-left: 10px; color: #666;">pixels</span>
363
+ </div>
364
+
365
+ <hr>
366
+
367
+ <div class="form-row">
368
+ <label for="node-input-preset"><i class="fa fa-tachometer"></i> Speed Preset</label>
369
+ <select id="node-input-preset" style="width: 200px;">
370
+ <option value="ultra-fast">Ultra Fast</option>
371
+ <option value="fast">Fast</option>
372
+ <option value="balanced">Balanced</option>
373
+ <option value="quality">Quality</option>
374
+ <option value="custom">Custom</option>
375
+ </select>
376
+ </div>
377
+ <div class="form-row">
378
+ <label></label>
379
+ <div id="preset-description" style="font-size: 12px; color: #666; margin-top: 5px;"></div>
380
+ </div>
381
+
382
+ <!-- Custom Parameters (only visible when Custom preset selected) -->
383
+ <div id="custom-parameters" style="display: none;">
384
+ <div class="form-row">
385
+ <label for="node-input-customScale"><i class="fa fa-search"></i> Scale</label>
386
+ <input type="text" id="node-input-customScale" style="width: 200px;">
387
+ <input type="hidden" id="node-input-customScaleType">
388
+ <span style="margin-left: 10px; color: #666;">0.1-1.0 (image downscale factor)</span>
389
+ </div>
390
+ <div class="form-row">
391
+ <label for="node-input-customMaxIterations"><i class="fa fa-repeat"></i> Max Iterations</label>
392
+ <input type="text" id="node-input-customMaxIterations" style="width: 200px;">
393
+ <input type="hidden" id="node-input-customMaxIterationsType">
394
+ <span style="margin-left: 10px; color: #666;">1-200 (alignment iterations)</span>
395
+ </div>
396
+ <div class="form-row">
397
+ <label for="node-input-customTerminationEps"><i class="fa fa-bullseye"></i> Termination Eps</label>
398
+ <input type="text" id="node-input-customTerminationEps" style="width: 200px;">
399
+ <input type="hidden" id="node-input-customTerminationEpsType">
400
+ <span style="margin-left: 10px; color: #666;">0.000001-0.1 (convergence threshold)</span>
401
+ </div>
402
+ </div>
403
+
404
+ <div class="form-tips">
405
+ <b>Flexible Paths:</b> Configure where to find reference and target images in your message.<br>
406
+ <b>Default:</b> <code>msg.payload.reference</code> and <code>msg.payload.target</code><br>
407
+ <b>Output:</b> Returns the aligned target image. Alignment info is added to <code>msg.alignment</code>.<br>
408
+ <b>Transform Matrix:</b> When enabled, includes transformation matrix with <code>dx</code>, <code>dy</code> translation values, 2x3 OpenCV matrix, and 3x3 homogeneous matrix.<br>
409
+ <b>Transform Polygon:</b> When enabled, transforms polygon coordinates using the same alignment transformation. Expects normalized coordinates (0-1 range) in the same format as add-mask node.
410
+ </div>
411
+ </script>
412
+
413
+ <script type="text/x-red" data-help-name="image-align">
414
+ <p>Aligns images using ultra-fast ECC (Enhanced Correlation Coefficient) algorithm with OpenCV backend for maximum performance.</p>
415
+
416
+ <h3>Details</h3>
417
+ <p>This node performs image alignment by finding the transformation needed to align a target image with a reference image. It uses OpenCV's ECC algorithm optimized for speed with configurable precision levels. The aligned target image is returned as output.</p>
418
+
419
+ <h3>Properties</h3>
420
+ <dl class="message-properties">
421
+ <dt>Reference Image <span class="property-type">string</span></dt>
422
+ <dd>Path to reference image in message. Defaults to <code>msg.payload.reference</code>.</dd>
423
+ <dt>Target Image <span class="property-type">string</span></dt>
424
+ <dd>Path to target image in message. Defaults to <code>msg.payload.target</code>.</dd>
425
+ <dt>Output to <span class="property-type">string</span></dt>
426
+ <dd>Location where aligned image will be stored. Defaults to <code>msg.payload</code>.</dd>
427
+ <dt>Output Format <span class="property-type">string</span></dt>
428
+ <dd>Output format: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
429
+ <dt>Speed Preset <span class="property-type">string</span></dt>
430
+ <dd>Alignment speed/quality balance: <code>ultra-fast</code>, <code>fast</code>, <code>balanced</code>, or <code>quality</code>.</dd>
431
+ <dt>Transform Polygon <span class="property-type">boolean</span></dt>
432
+ <dd>When enabled, transforms polygon coordinates from the specified path using the alignment transformation.</dd>
433
+ <dt>Polygon Path <span class="property-type">string</span></dt>
434
+ <dd>Path to polygon coordinates in message. Expected format: array of [x, y] pairs with normalized values (0-1 range).</dd>
435
+ </dl>
436
+
437
+ <h3>Inputs</h3>
438
+ <dl class="message-properties">
439
+ <dt>Images <span class="property-type">object</span></dt>
440
+ <dd>Both images must be in standard format: <code>{data: Buffer, width: number, height: number, channels: number, colorSpace: string}</code>. Images can be located anywhere in the message using the configurable paths.</dd>
441
+ </dl>
442
+
443
+ <h3>Outputs</h3>
444
+ <dl class="message-properties">
445
+ <dt>payload <span class="property-type">object|Buffer</span></dt>
446
+ <dd>Aligned target image in specified output format.</dd>
447
+ <dt>alignment <span class="property-type">object</span></dt>
448
+ <dd>Alignment information:
449
+ <ul>
450
+ <li><code>success</code>: boolean indicating alignment success</li>
451
+ <li><code>timing</code>: processing timing breakdown</li>
452
+ <li><code>preset</code>: speed preset used</li>
453
+ <li><code>transformMatrix</code>: (optional) transformation matrix when enabled:
454
+ <ul>
455
+ <li><code>dx</code>: horizontal translation in pixels</li>
456
+ <li><code>dy</code>: vertical translation in pixels</li>
457
+ <li><code>matrix2x3</code>: OpenCV 2x3 matrix format [a, b, dx, c, d, dy]</li>
458
+ <li><code>matrix3x3</code>: standard 3x3 homogeneous matrix [a, b, dx, c, d, dy, 0, 0, 1]</li>
459
+ <li><code>transform</code>: alias for matrix3x3 (backward compatibility)</li>
460
+ </ul>
461
+ </li>
462
+ <li><code>originalPolygon</code>: (optional) original polygon coordinates when Transform Polygon is enabled</li>
463
+ <li><code>transformedPolygon</code>: (optional) transformed polygon coordinates in same normalized format (0-1 range)</li>
464
+ </ul>
465
+ </dd>
466
+ </dl>
467
+
468
+ <h3>Speed Presets</h3>
469
+ <ul>
470
+ <li><strong>Ultra Fast:</strong> Maximum speed, basic accuracy (scale: 0.2, iterations: 10)</li>
471
+ <li><strong>Fast:</strong> Good speed, decent accuracy (scale: 0.3, iterations: 20)</li>
472
+ <li><strong>Balanced:</strong> Balanced speed and accuracy (scale: 0.5, iterations: 30)</li>
473
+ <li><strong>Quality:</strong> Best accuracy, slower processing (scale: 0.7, iterations: 50)</li>
474
+ <li><strong>Custom:</strong> Manual parameter control:
475
+ <ul>
476
+ <li><code>Scale</code>: Image downscale factor (0.1-1.0) - smaller values = faster processing</li>
477
+ <li><code>Max Iterations</code>: Maximum alignment iterations (1-200) - more iterations = better accuracy</li>
478
+ <li><code>Termination Eps</code>: Convergence threshold (0.000001-0.1) - smaller values = stricter convergence</li>
479
+ </ul>
480
+ </li>
481
+ </ul>
482
+
483
+ <h3>Algorithm Details</h3>
484
+ <p>Uses OpenCV's <code>findTransformECC</code> with <code>MOTION_TRANSLATION</code> for ultra-fast translation-only alignment:</p>
485
+ <ul>
486
+ <li>Images are downscaled for speed (configurable scale factor)</li>
487
+ <li>ECC alignment finds optimal translation transform</li>
488
+ <li>Transform is scaled back to full resolution and applied</li>
489
+ <li>Target image dimensions are adjusted to match reference</li>
490
+ </ul>
491
+
492
+ <h3>Flexible Input Configuration</h3>
493
+ <p>Configure where to find images in your message using the path settings:</p>
494
+ <ul>
495
+ <li><strong>Default:</strong> <code>msg.payload.reference</code> and <code>msg.payload.target</code></li>
496
+ <li><strong>Custom paths:</strong> <code>msg.referenceImage</code> and <code>msg.targetToAlign</code></li>
497
+ <li><strong>Flow context:</strong> <code>flow.template</code> and <code>msg.sample</code></li>
498
+ <li><strong>Global context:</strong> <code>global.baseImage</code> and <code>msg.testImage</code></li>
499
+ </ul>
500
+
501
+ <h3>Usage Examples</h3>
502
+ <pre><code>// Default structure (payload.reference & payload.target)
503
+ msg.payload = {
504
+ reference: { data: Buffer, width: 800, height: 600, channels: 3, colorSpace: "BGR" },
505
+ target: { data: Buffer, width: 800, height: 600, channels: 3, colorSpace: "BGR" }
506
+ };
507
+
508
+ // Custom paths (configure: referenceImage & targetImage)
509
+ msg.referenceImage = { data: Buffer, width: 800, height: 600, channels: 3, colorSpace: "BGR" };
510
+ msg.targetImage = { data: Buffer, width: 800, height: 600, channels: 3, colorSpace: "BGR" };
511
+
512
+ // Mixed sources (configure: flow.template & payload)
513
+ flow.set("template", referenceImageObject);
514
+ msg.payload = targetImageObject;</code></pre>
515
+
516
+ <h3>Common Workflows</h3>
517
+ <ul>
518
+ <li><strong>Quality Control:</strong> Image-in → Image-align → comparison analysis</li>
519
+ <li><strong>Template Matching:</strong> Template + samples → Image-align → feature extraction</li>
520
+ <li><strong>Multi-camera Calibration:</strong> Reference view + other views → Image-align → unified coordinate system</li>
521
+ </ul>
522
+
523
+ <h3>Performance</h3>
524
+ <p>Optimized for real-time processing with sub-50ms typical processing times. Uses downscaled alignment for speed while maintaining accuracy for most use cases.</p>
525
+
526
+ <h3>Error Handling</h3>
527
+ <p>If alignment fails, the target image is resized to match reference dimensions and returned. Check <code>msg.alignment.success</code> for alignment status.</p>
528
+ </script>