@rosepetal/node-red-contrib-image-tools 1.6.1 → 1.6.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/node-red-contrib-image-tools/nodes/specialized/heat-diff.html +50 -15
- package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +19 -8
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +14 -14
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +96 -47
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64/package.json +1 -1
- package/npm/linux-x64/package.json +1 -1
- package/npm/linuxmusl-x64/package.json +1 -1
- package/npm/win32-x64/package.json +1 -1
- package/package.json +6 -6
- package/rosepetal-image-engine/src/heat-diff.cpp +31 -14
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
colormap:{value:"JET"},
|
|
23
23
|
blurSize:{value:0}, blurSizeType:{value:"num"},
|
|
24
24
|
threshold:{value:0}, thresholdType:{value:"num"},
|
|
25
|
+
imageEnabled:{value:true},
|
|
25
26
|
statsEnabled:{value:true},
|
|
27
|
+
ssimEnabled:{value:true},
|
|
26
28
|
statsPath:{value:"diffStats"}, statsPathType:{value:"msg"}
|
|
27
29
|
},
|
|
28
30
|
inputs:1,outputs:1,
|
|
@@ -41,13 +43,13 @@
|
|
|
41
43
|
default:'msg',types:['msg','flow','global'],
|
|
42
44
|
typeField:"#node-input-statsPathType"});
|
|
43
45
|
|
|
44
|
-
// Stats path only relevant when stats are enabled
|
|
46
|
+
// Stats path and SSIM option only relevant when stats are enabled
|
|
45
47
|
var statsCheckbox = $('#node-input-statsEnabled');
|
|
46
|
-
function
|
|
47
|
-
$("#stats-path-row").toggle(statsCheckbox.is(':checked'));
|
|
48
|
+
function updateStatsVisibility(){
|
|
49
|
+
$("#stats-path-row, #ssim-row").toggle(statsCheckbox.is(':checked'));
|
|
48
50
|
}
|
|
49
|
-
statsCheckbox.on('change',
|
|
50
|
-
|
|
51
|
+
statsCheckbox.on('change', updateStatsVisibility);
|
|
52
|
+
updateStatsVisibility();
|
|
51
53
|
|
|
52
54
|
$("#node-input-blurSize").typedInput({
|
|
53
55
|
default:'num',types:['num','msg','flow','global'],
|
|
@@ -58,10 +60,11 @@
|
|
|
58
60
|
|
|
59
61
|
// Output format visibility
|
|
60
62
|
function updateQualityVisibility(){
|
|
63
|
+
var withImage = $("#node-input-imageEnabled").is(':checked');
|
|
61
64
|
var format = $("#node-input-outputFormat").val();
|
|
62
|
-
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
63
|
-
$("#png-optimize-row").toggle(format === "png");
|
|
64
|
-
var isWebp = format === 'webp';
|
|
65
|
+
$("#quality-row").toggle(withImage && (format === "jpg" || format === "webp"));
|
|
66
|
+
$("#png-optimize-row").toggle(withImage && format === "png");
|
|
67
|
+
var isWebp = withImage && format === 'webp';
|
|
65
68
|
$("#webp-lossless-row").toggle(isWebp);
|
|
66
69
|
$("#webp-smartsubsample-row").toggle(isWebp);
|
|
67
70
|
$("#webp-effort-row").toggle(isWebp);
|
|
@@ -78,10 +81,25 @@
|
|
|
78
81
|
typeField: "#node-input-debugWidthType"
|
|
79
82
|
});
|
|
80
83
|
function updateDebugWidthVisibility() {
|
|
81
|
-
|
|
84
|
+
var withImage = $("#node-input-imageEnabled").is(':checked');
|
|
85
|
+
debugWidthRow.toggle(withImage && debugCheckbox.is(':checked'));
|
|
82
86
|
}
|
|
83
|
-
updateDebugWidthVisibility();
|
|
84
87
|
debugCheckbox.on('change', updateDebugWidthVisibility);
|
|
88
|
+
|
|
89
|
+
// Stats-only mode: every image-output option becomes irrelevant
|
|
90
|
+
var imageCheckbox = $('#node-input-imageEnabled');
|
|
91
|
+
function updateImageVisibility(){
|
|
92
|
+
var withImage = imageCheckbox.is(':checked');
|
|
93
|
+
$("#output-path-row, #output-format-row, #debug-row").toggle(withImage);
|
|
94
|
+
// Without an image, stats are the only output left
|
|
95
|
+
if (!withImage) statsCheckbox.prop('checked', true);
|
|
96
|
+
statsCheckbox.prop('disabled', !withImage);
|
|
97
|
+
updateStatsVisibility();
|
|
98
|
+
updateQualityVisibility();
|
|
99
|
+
updateDebugWidthVisibility();
|
|
100
|
+
}
|
|
101
|
+
imageCheckbox.on('change', updateImageVisibility);
|
|
102
|
+
updateImageVisibility();
|
|
85
103
|
}
|
|
86
104
|
});
|
|
87
105
|
</script>
|
|
@@ -105,12 +123,18 @@
|
|
|
105
123
|
</div>
|
|
106
124
|
|
|
107
125
|
<div class="form-row">
|
|
126
|
+
<label for="node-input-imageEnabled"><i class="fa fa-fire"></i> Heat Image</label>
|
|
127
|
+
<input type="checkbox" id="node-input-imageEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
128
|
+
<label for="node-input-imageEnabled" style="width:auto; margin-left:5px;">Render the heat map (off = statistics only)</label>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<div class="form-row" id="output-path-row">
|
|
108
132
|
<label><i class="fa fa-sign-out"></i> Output</label>
|
|
109
133
|
<input type="text" id="node-input-outputPath" style="width:70%;">
|
|
110
134
|
<input type="hidden" id="node-input-outputPathType">
|
|
111
135
|
</div>
|
|
112
136
|
|
|
113
|
-
<div class="form-row">
|
|
137
|
+
<div class="form-row" id="output-format-row">
|
|
114
138
|
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
115
139
|
<select id="node-input-outputFormat" style="width: 200px;">
|
|
116
140
|
<option value="raw">Raw (fastest)</option>
|
|
@@ -130,6 +154,11 @@
|
|
|
130
154
|
<input type="text" id="node-input-statsPath" style="width:70%;">
|
|
131
155
|
<input type="hidden" id="node-input-statsPathType">
|
|
132
156
|
</div>
|
|
157
|
+
<div class="form-row" id="ssim-row">
|
|
158
|
+
<label for="node-input-ssimEnabled"><i class="fa fa-clone"></i> SSIM</label>
|
|
159
|
+
<input type="checkbox" id="node-input-ssimEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
160
|
+
<label for="node-input-ssimEnabled" style="width:auto; margin-left:5px;">Compute SSIM (dominates the stats cost)</label>
|
|
161
|
+
</div>
|
|
133
162
|
|
|
134
163
|
<div class="form-row" id="quality-row">
|
|
135
164
|
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
@@ -159,7 +188,7 @@
|
|
|
159
188
|
</div>
|
|
160
189
|
|
|
161
190
|
<!-- Debug Configuration -->
|
|
162
|
-
<div class="form-row">
|
|
191
|
+
<div class="form-row" id="debug-row">
|
|
163
192
|
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
164
193
|
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
165
194
|
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
@@ -218,8 +247,11 @@
|
|
|
218
247
|
<dt>Image 2 <span class="property-type">string</span></dt>
|
|
219
248
|
<dd>Path to the second image (e.g. the golden/reference image).</dd>
|
|
220
249
|
|
|
250
|
+
<dt>Heat Image <span class="property-type">boolean</span></dt>
|
|
251
|
+
<dd>When enabled (default), the colormapped heat map is rendered and written to the output property. Disable it for a statistics-only pass: the colormap and the image encoding are skipped entirely and no image buffer is allocated. Statistics are then always computed, since they are the node's only output.</dd>
|
|
252
|
+
|
|
221
253
|
<dt>Output to <span class="property-type">string</span></dt>
|
|
222
|
-
<dd>Message property where the heat map image will be stored.</dd>
|
|
254
|
+
<dd>Message property where the heat map image will be stored. Left untouched when Heat Image is disabled.</dd>
|
|
223
255
|
|
|
224
256
|
<dt>Colormap <span class="property-type">string</span></dt>
|
|
225
257
|
<dd>Color mapping applied to the difference: JET, HOT, INFERNO, TURBO, BONE, COOL, RAINBOW, OCEAN, PINK, HSV.</dd>
|
|
@@ -233,6 +265,9 @@
|
|
|
233
265
|
<dt>Statistics <span class="property-type">boolean</span></dt>
|
|
234
266
|
<dd>When enabled (default), numeric diff statistics are computed.</dd>
|
|
235
267
|
|
|
268
|
+
<dt>SSIM <span class="property-type">boolean</span></dt>
|
|
269
|
+
<dd>When enabled (default), structural similarity is included in the statistics. It is by far the most expensive statistic — six full-resolution floating-point blurs, typically more than the rest of the node put together — so disable it when the flow only uses the ratios and blobs. <code>ssim</code> is then reported as <code>null</code>.</dd>
|
|
270
|
+
|
|
236
271
|
<dt>Stats to <span class="property-type">string</span></dt>
|
|
237
272
|
<dd>Message property where the statistics object is stored. Default <code>msg.diffStats</code>.</dd>
|
|
238
273
|
</dl>
|
|
@@ -241,7 +276,7 @@
|
|
|
241
276
|
<p>Two images in the standard format (raw image object or encoded buffer), or two arrays of images of the same length — images are paired by index and one heat map is produced per pair. Mixing a single image with an array, or arrays of different lengths, raises an error. Images of different sizes are resized to match the larger one.</p>
|
|
242
277
|
|
|
243
278
|
<h3>Outputs</h3>
|
|
244
|
-
<p>A 3-channel BGR heat map image in the selected output format. If the inputs were arrays, the output is an array of heat maps in the same order.</p>
|
|
279
|
+
<p>A 3-channel BGR heat map image in the selected output format. If the inputs were arrays, the output is an array of heat maps in the same order. With Heat Image disabled the output property is not written at all, so the message passes through unchanged apart from the statistics.</p>
|
|
245
280
|
<p>When Statistics is enabled, the configured stats property (default <code>msg.diffStats</code>) holds an object (or array, matching the input shape) with:</p>
|
|
246
281
|
<dl class="message-properties">
|
|
247
282
|
<dt>validRatio <span class="property-type">number</span></dt>
|
|
@@ -251,7 +286,7 @@
|
|
|
251
286
|
<dt>meanDiff / maxDiff / p50 / p95 / p99 <span class="property-type">number</span></dt>
|
|
252
287
|
<dd>Mean, maximum and percentiles of the difference values (0-255) over valid pixels.</dd>
|
|
253
288
|
<dt>rmse / psnr / ssim <span class="property-type">number</span></dt>
|
|
254
|
-
<dd>Root-mean-square error, peak signal-to-noise ratio (dB, 100 = identical) and structural similarity (0-1, 1 = identical).</dd>
|
|
289
|
+
<dd>Root-mean-square error, peak signal-to-noise ratio (dB, 100 = identical) and structural similarity (0-1, 1 = identical). <code>ssim</code> is <code>null</code> when the SSIM option is disabled.</dd>
|
|
255
290
|
<dt>blobCount / largestBlobArea / blobs <span class="property-type">number | array</span></dt>
|
|
256
291
|
<dd>Connected regions of changed pixels. <code>blobs</code> lists up to 50 regions, largest first, each with <code>x, y, w, h, area, cx, cy</code> in output-image coordinates.</dd>
|
|
257
292
|
</dl>
|
|
@@ -139,18 +139,26 @@ module.exports = function (RED) {
|
|
|
139
139
|
const outputFormat = config.outputFormat || 'raw';
|
|
140
140
|
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
141
141
|
const pngOptimize = config.pngOptimize || false;
|
|
142
|
-
//
|
|
143
|
-
const
|
|
142
|
+
// Heat image on by default; off = stats-only (no colormap, no encode, no buffer)
|
|
143
|
+
const imageEnabled = config.imageEnabled !== false && config.imageEnabled !== 'false';
|
|
144
|
+
// Stats on by default; existing flows without the property get them too.
|
|
145
|
+
// Stats-only mode forces them on, otherwise the node would produce nothing.
|
|
146
|
+
const statsEnabled = !imageEnabled ||
|
|
147
|
+
(config.statsEnabled !== false && config.statsEnabled !== 'false');
|
|
148
|
+
// SSIM is by far the costliest stat; flows that ignore it can opt out
|
|
149
|
+
const ssimEnabled = config.ssimEnabled !== false && config.ssimEnabled !== 'false';
|
|
144
150
|
const statsPath = config.statsPath || 'diffStats';
|
|
145
151
|
const statsPathType = config.statsPathType || 'msg';
|
|
146
|
-
const useSharpWebp = outputFormat === 'webp' &&
|
|
152
|
+
const useSharpWebp = imageEnabled && outputFormat === 'webp' &&
|
|
153
|
+
NodeUtils.hasAdvancedWebpOptions(config);
|
|
147
154
|
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
148
155
|
|
|
149
156
|
/* One C++ call per pair (index-matched) */
|
|
150
157
|
const results = await Promise.all(
|
|
151
158
|
list1.map((img1, i) =>
|
|
152
159
|
Cpp.heatDiff(img1, list2[i], colormapType, blurSize, threshold,
|
|
153
|
-
cppFormat, outputQuality, pngOptimize, statsEnabled
|
|
160
|
+
cppFormat, outputQuality, pngOptimize, statsEnabled,
|
|
161
|
+
imageEnabled, ssimEnabled))
|
|
154
162
|
);
|
|
155
163
|
|
|
156
164
|
// Aggregate timings across pairs
|
|
@@ -163,7 +171,7 @@ module.exports = function (RED) {
|
|
|
163
171
|
},
|
|
164
172
|
{ convertMs: 0, taskMs: 0, encodeMs: 0 }
|
|
165
173
|
);
|
|
166
|
-
const images = results.map(r => r.image);
|
|
174
|
+
const images = imageEnabled ? results.map(r => r.image) : [];
|
|
167
175
|
|
|
168
176
|
if (useSharpWebp) {
|
|
169
177
|
for (let i = 0; i < images.length; i++) {
|
|
@@ -171,8 +179,10 @@ module.exports = function (RED) {
|
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
181
|
|
|
174
|
-
/* Write result — array in, array out */
|
|
175
|
-
|
|
182
|
+
/* Write result — array in, array out; stats-only leaves the output path untouched */
|
|
183
|
+
if (imageEnabled) {
|
|
184
|
+
RED.util.setMessageProperty(msg, outputPath, isArray ? images : images[0]);
|
|
185
|
+
}
|
|
176
186
|
|
|
177
187
|
/* Diff statistics, same shape as the image output */
|
|
178
188
|
if (statsEnabled) {
|
|
@@ -184,7 +194,8 @@ module.exports = function (RED) {
|
|
|
184
194
|
const total = performance.now() - t0;
|
|
185
195
|
|
|
186
196
|
let debugFormat = null;
|
|
187
|
-
const debugEnabled =
|
|
197
|
+
const debugEnabled = imageEnabled &&
|
|
198
|
+
(config.debugEnabled === true || config.debugEnabled === 'true');
|
|
188
199
|
if (debugEnabled) {
|
|
189
200
|
try {
|
|
190
201
|
let debugWidth = NodeUtils.resolveDimension(
|
|
@@ -797,14 +797,14 @@
|
|
|
797
797
|
<p>Aligns images using ultra-fast ECC (Enhanced Correlation Coefficient) algorithm with OpenCV backend for maximum performance.</p>
|
|
798
798
|
|
|
799
799
|
<h3>Details</h3>
|
|
800
|
-
<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>
|
|
800
|
+
<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. Both inputs may also be same-length arrays: images are paired by index, each pair is aligned independently, and the output is an array of aligned images.</p>
|
|
801
801
|
|
|
802
802
|
<h3>Properties</h3>
|
|
803
803
|
<dl class="message-properties">
|
|
804
804
|
<dt>Reference Image <span class="property-type">string</span></dt>
|
|
805
|
-
<dd>Path to reference image in message. Defaults to <code>msg.payload.reference</code>.</dd>
|
|
805
|
+
<dd>Path to reference image (or array of images) in message. Defaults to <code>msg.payload.reference</code>.</dd>
|
|
806
806
|
<dt>Target Image <span class="property-type">string</span></dt>
|
|
807
|
-
<dd>Path to target image in message. Defaults to <code>msg.payload.target</code>.</dd>
|
|
807
|
+
<dd>Path to target image (or array of images) in message. Defaults to <code>msg.payload.target</code>.</dd>
|
|
808
808
|
<dt>Output to <span class="property-type">string</span></dt>
|
|
809
809
|
<dd>Location where aligned image will be stored. Defaults to <code>msg.payload</code>.</dd>
|
|
810
810
|
<dt>Output Format <span class="property-type">string</span></dt>
|
|
@@ -847,14 +847,14 @@
|
|
|
847
847
|
|
|
848
848
|
<h3>Inputs</h3>
|
|
849
849
|
<dl class="message-properties">
|
|
850
|
-
<dt>Images <span class="property-type">object</span></dt>
|
|
851
|
-
<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>
|
|
850
|
+
<dt>Images <span class="property-type">object | array</span></dt>
|
|
851
|
+
<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. Reference and target must have the same shape: two single images, or two non-empty arrays of equal length (paired by index).</dd>
|
|
852
852
|
</dl>
|
|
853
853
|
|
|
854
854
|
<h3>Outputs</h3>
|
|
855
855
|
<dl class="message-properties">
|
|
856
|
-
<dt>payload <span class="property-type">object|Buffer</span></dt>
|
|
857
|
-
<dd>Aligned target image in specified output format
|
|
856
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
857
|
+
<dd>Aligned target image in specified output format. Array in, array out: with array inputs this is an array of aligned images, and per-pair alignment fields (<code>success</code> aggregated with AND, <code>transformMatrix</code>, transformed polygons) become arrays in <code>msg.alignment</code>.</dd>
|
|
858
858
|
<dt>alignment <span class="property-type">object</span></dt>
|
|
859
859
|
<dd>Alignment information:
|
|
860
860
|
<ul>
|
|
@@ -952,14 +952,14 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
952
952
|
<p>Aligns images using ultra-fast ECC (Enhanced Correlation Coefficient) algorithm with OpenCV backend for maximum performance.</p>
|
|
953
953
|
|
|
954
954
|
<h3>Details</h3>
|
|
955
|
-
<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>
|
|
955
|
+
<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. Both inputs may also be same-length arrays: images are paired by index, each pair is aligned independently, and the output is an array of aligned images.</p>
|
|
956
956
|
|
|
957
957
|
<h3>Properties</h3>
|
|
958
958
|
<dl class="message-properties">
|
|
959
959
|
<dt>Reference Image <span class="property-type">string</span></dt>
|
|
960
|
-
<dd>Path to reference image in message. Defaults to <code>msg.payload.reference</code>.</dd>
|
|
960
|
+
<dd>Path to reference image (or array of images) in message. Defaults to <code>msg.payload.reference</code>.</dd>
|
|
961
961
|
<dt>Target Image <span class="property-type">string</span></dt>
|
|
962
|
-
<dd>Path to target image in message. Defaults to <code>msg.payload.target</code>.</dd>
|
|
962
|
+
<dd>Path to target image (or array of images) in message. Defaults to <code>msg.payload.target</code>.</dd>
|
|
963
963
|
<dt>Output to <span class="property-type">string</span></dt>
|
|
964
964
|
<dd>Location where aligned image will be stored. Defaults to <code>msg.payload</code>.</dd>
|
|
965
965
|
<dt>Output Format <span class="property-type">string</span></dt>
|
|
@@ -1002,14 +1002,14 @@ msg.payload = targetImageObject;</code></pre>
|
|
|
1002
1002
|
|
|
1003
1003
|
<h3>Inputs</h3>
|
|
1004
1004
|
<dl class="message-properties">
|
|
1005
|
-
<dt>Images <span class="property-type">object</span></dt>
|
|
1006
|
-
<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>
|
|
1005
|
+
<dt>Images <span class="property-type">object | array</span></dt>
|
|
1006
|
+
<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. Reference and target must have the same shape: two single images, or two non-empty arrays of equal length (paired by index).</dd>
|
|
1007
1007
|
</dl>
|
|
1008
1008
|
|
|
1009
1009
|
<h3>Outputs</h3>
|
|
1010
1010
|
<dl class="message-properties">
|
|
1011
|
-
<dt>payload <span class="property-type">object|Buffer</span></dt>
|
|
1012
|
-
<dd>Aligned target image in specified output format
|
|
1011
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
1012
|
+
<dd>Aligned target image in specified output format. Array in, array out: with array inputs this is an array of aligned images, and per-pair alignment fields (<code>success</code> aggregated with AND, <code>transformMatrix</code>, transformed polygons) become arrays in <code>msg.alignment</code>.</dd>
|
|
1013
1013
|
<dt>alignment <span class="property-type">object</span></dt>
|
|
1014
1014
|
<dd>Alignment information:
|
|
1015
1015
|
<ul>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Node-RED logic for the image-align node (C++-driven ECC alignment).
|
|
3
3
|
* Ultra-fast image alignment using OpenCV ECC algorithm.
|
|
4
|
+
* Accepts two single images or two same-length arrays (paired by index).
|
|
4
5
|
* @author Rosepetal
|
|
5
6
|
*/
|
|
6
7
|
const { performance } = require('perf_hooks');
|
|
@@ -151,17 +152,45 @@ module.exports = function (RED) {
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
/* ▸ Read images from message ------------------------------------ */
|
|
154
|
-
//
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
155
|
+
// Both inputs must have the same shape: two singles, or two same-length arrays
|
|
156
|
+
const isArray = Array.isArray(referenceImage);
|
|
157
|
+
if (isArray !== Array.isArray(targetImage)) {
|
|
158
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
159
|
+
node,
|
|
160
|
+
{
|
|
161
|
+
message: 'Reference and target must both be single images or both be arrays',
|
|
162
|
+
hint: `"${referenceImagePath}" is ${isArray ? 'an array' : 'a single image'} but "${targetImagePath}" is not.`,
|
|
163
|
+
details: { referenceImagePath, targetImagePath, outputPath }
|
|
164
|
+
},
|
|
165
|
+
msg, send, done,
|
|
166
|
+
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if (isArray && (referenceImage.length === 0 || referenceImage.length !== targetImage.length)) {
|
|
170
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
171
|
+
node,
|
|
172
|
+
{
|
|
173
|
+
message: `Image arrays must be non-empty and of equal length (got ${referenceImage.length} and ${targetImage.length})`,
|
|
174
|
+
hint: 'Images are paired by index; both arrays must contain the same number of images.',
|
|
175
|
+
details: { referenceImagePath, targetImagePath, outputPath }
|
|
176
|
+
},
|
|
177
|
+
msg, send, done,
|
|
178
|
+
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const refList = (isArray ? referenceImage : [referenceImage])
|
|
183
|
+
.map(img => NodeUtils.validateImageStructure(img, node));
|
|
184
|
+
if (refList.some(img => !img)) {
|
|
157
185
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
158
186
|
node, 'Reference image is invalid or missing', msg, send, done,
|
|
159
187
|
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
160
188
|
);
|
|
161
189
|
}
|
|
162
190
|
|
|
163
|
-
const
|
|
164
|
-
|
|
191
|
+
const targetList = (isArray ? targetImage : [targetImage])
|
|
192
|
+
.map(img => NodeUtils.validateImageStructure(img, node));
|
|
193
|
+
if (targetList.some(img => !img)) {
|
|
165
194
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
166
195
|
node, 'Target image is invalid or missing', msg, send, done,
|
|
167
196
|
{ originalPayload: passthroughImage, outputPath, outputType: 'single' }
|
|
@@ -326,26 +355,43 @@ module.exports = function (RED) {
|
|
|
326
355
|
}
|
|
327
356
|
}
|
|
328
357
|
|
|
329
|
-
/* ▸
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
358
|
+
/* ▸ One C++ call per pair (index-matched) ------------------------- */
|
|
359
|
+
const results = await Promise.all(
|
|
360
|
+
refList.map((refImg, i) =>
|
|
361
|
+
CppProcessor.imageAlign(
|
|
362
|
+
refImg,
|
|
363
|
+
targetList[i],
|
|
364
|
+
scale,
|
|
365
|
+
maxIterations,
|
|
366
|
+
terminationEps,
|
|
367
|
+
cppFormat,
|
|
368
|
+
outputQuality,
|
|
369
|
+
pngOptimize,
|
|
370
|
+
returnMatrix,
|
|
371
|
+
polygon,
|
|
372
|
+
motionModel,
|
|
373
|
+
pipeline,
|
|
374
|
+
eccRefine,
|
|
375
|
+
detector
|
|
376
|
+
))
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
// Aggregate timings across pairs
|
|
380
|
+
const timing = results.reduce(
|
|
381
|
+
(acc, { timing: t }) => {
|
|
382
|
+
acc.convertMs += t?.convertMs ?? 0;
|
|
383
|
+
acc.taskMs += t?.taskMs ?? 0;
|
|
384
|
+
acc.encodeMs += t?.encodeMs ?? 0;
|
|
385
|
+
return acc;
|
|
386
|
+
},
|
|
387
|
+
{ convertMs: 0, taskMs: 0, encodeMs: 0 }
|
|
345
388
|
);
|
|
389
|
+
const images = results.map(r => r.image);
|
|
346
390
|
|
|
347
391
|
if (useSharpWebp) {
|
|
348
|
-
|
|
392
|
+
for (let i = 0; i < images.length; i++) {
|
|
393
|
+
images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
|
|
394
|
+
}
|
|
349
395
|
}
|
|
350
396
|
|
|
351
397
|
/* ▸ Status: standardized success formatting ----------------------- */
|
|
@@ -364,65 +410,68 @@ module.exports = function (RED) {
|
|
|
364
410
|
msg
|
|
365
411
|
);
|
|
366
412
|
debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
|
|
367
|
-
|
|
413
|
+
|
|
414
|
+
// For arrays, show the first aligned image as representative
|
|
368
415
|
const debugResult = await NodeUtils.debugImageDisplay(
|
|
369
|
-
|
|
416
|
+
images[0],
|
|
370
417
|
outputFormat,
|
|
371
418
|
outputQuality,
|
|
372
419
|
node,
|
|
373
420
|
debugEnabled,
|
|
374
421
|
debugWidth
|
|
375
422
|
);
|
|
376
|
-
|
|
423
|
+
|
|
377
424
|
if (debugResult) {
|
|
378
425
|
debugFormat = debugResult.formatMessage;
|
|
379
426
|
// Update node status with debug info
|
|
380
|
-
NodeUtils.setSuccessStatusWithDebug(node,
|
|
427
|
+
NodeUtils.setSuccessStatusWithDebug(node, results.length, total, timing,
|
|
428
|
+
debugFormat + (isArray ? ' (first)' : ''));
|
|
381
429
|
}
|
|
382
430
|
} catch (debugError) {
|
|
383
431
|
node.warn(`Debug display error: ${debugError.message}`);
|
|
384
432
|
}
|
|
385
433
|
}
|
|
386
|
-
|
|
434
|
+
|
|
387
435
|
// Set regular status if debug not enabled or failed
|
|
388
436
|
if (!debugFormat) {
|
|
389
|
-
NodeUtils.setSuccessStatus(node,
|
|
437
|
+
NodeUtils.setSuccessStatus(node, results.length, total, timing);
|
|
390
438
|
}
|
|
391
439
|
|
|
392
|
-
NodeUtils.recordPerformanceMetrics(node, msg,
|
|
440
|
+
NodeUtils.recordPerformanceMetrics(node, msg, timing, total);
|
|
393
441
|
|
|
394
|
-
/* ▸ Write the result back to msg
|
|
395
|
-
RED.util.setMessageProperty(msg, outputPath,
|
|
442
|
+
/* ▸ Write the result back to msg (array in, array out) ------------ */
|
|
443
|
+
RED.util.setMessageProperty(msg, outputPath, isArray ? images : images[0]);
|
|
396
444
|
|
|
397
|
-
// Add alignment info to message
|
|
445
|
+
// Add alignment info to message; per-pair fields follow the output
|
|
446
|
+
// shape (single in -> single out, array in -> array out)
|
|
398
447
|
msg.alignment = {
|
|
399
|
-
success:
|
|
400
|
-
timing:
|
|
448
|
+
success: isArray ? results.every(r => r.success) : results[0].success,
|
|
449
|
+
timing: timing,
|
|
401
450
|
preset: preset,
|
|
402
451
|
motionModel: motionModel,
|
|
403
452
|
pipeline: pipeline,
|
|
404
453
|
eccRefine: eccRefine,
|
|
405
454
|
detector: detector
|
|
406
455
|
};
|
|
407
|
-
|
|
456
|
+
|
|
408
457
|
// Add transformation matrix if returned
|
|
409
|
-
|
|
410
|
-
|
|
458
|
+
const matrices = results.map(r => r.transformMatrix);
|
|
459
|
+
if (matrices.some(Boolean)) {
|
|
460
|
+
msg.alignment.transformMatrix = isArray ? matrices : matrices[0];
|
|
411
461
|
}
|
|
412
|
-
|
|
462
|
+
|
|
413
463
|
// Add polygon data if polygon transformation was requested
|
|
414
464
|
if (transformPolygon && polygon) {
|
|
415
|
-
// Store original polygon(s)
|
|
465
|
+
// Store original polygon(s); the same polygon(s) are transformed
|
|
466
|
+
// per pair, each with that pair's matrix
|
|
416
467
|
msg.alignment.originalPolygon = polygon;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// For array of polygons
|
|
423
|
-
msg.alignment.transformedPolygons = result.transformedPolygons;
|
|
468
|
+
|
|
469
|
+
const transformed = results.map(r => r.transformedPolygon ?? r.transformedPolygons ?? null);
|
|
470
|
+
if (transformed.some(Boolean)) {
|
|
471
|
+
const key = isPolygonArray ? 'transformedPolygons' : 'transformedPolygon';
|
|
472
|
+
msg.alignment[key] = isArray ? transformed : transformed[0];
|
|
424
473
|
}
|
|
425
|
-
|
|
474
|
+
|
|
426
475
|
// Store whether input was array for clarity
|
|
427
476
|
msg.alignment.isPolygonArray = isPolygonArray;
|
|
428
477
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosepetal/node-red-contrib-image-tools",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "Node-RED Image Processing Toolkit",
|
|
5
5
|
"main": "install.sh",
|
|
6
6
|
"directories": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"sharp": "^0.34.2"
|
|
37
37
|
},
|
|
38
38
|
"optionalDependencies": {
|
|
39
|
-
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.6.
|
|
40
|
-
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.6.
|
|
41
|
-
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.6.
|
|
42
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.6.
|
|
43
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.6.
|
|
39
|
+
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.6.3",
|
|
40
|
+
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.6.3",
|
|
41
|
+
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.6.3",
|
|
42
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.6.3",
|
|
43
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.6.3"
|
|
44
44
|
},
|
|
45
45
|
"node-red": {
|
|
46
46
|
"version": ">=1.0.0",
|
|
@@ -37,7 +37,9 @@ public:
|
|
|
37
37
|
std::string outputFormat,
|
|
38
38
|
int quality = 90,
|
|
39
39
|
bool pngOptimize = false,
|
|
40
|
-
bool computeStats = false
|
|
40
|
+
bool computeStats = false,
|
|
41
|
+
bool emitImage = true,
|
|
42
|
+
bool computeSsim = true)
|
|
41
43
|
: Napi::AsyncWorker(cb),
|
|
42
44
|
colormapType(colormapType),
|
|
43
45
|
blurSize(blurSize),
|
|
@@ -45,7 +47,9 @@ public:
|
|
|
45
47
|
outputFormat(std::move(outputFormat)),
|
|
46
48
|
quality(quality),
|
|
47
49
|
pngOptimize(pngOptimize),
|
|
48
|
-
computeStats(computeStats)
|
|
50
|
+
computeStats(computeStats),
|
|
51
|
+
emitImage(emitImage),
|
|
52
|
+
computeSsim(computeSsim)
|
|
49
53
|
{
|
|
50
54
|
const int64 t0 = cv::getTickCount();
|
|
51
55
|
mat1 = ConvertToMat(jsImg1);
|
|
@@ -103,14 +107,16 @@ protected:
|
|
|
103
107
|
|
|
104
108
|
if (computeStats) ComputeStats(diff, gray1, gray2);
|
|
105
109
|
|
|
106
|
-
// Apply colormap
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
// Apply colormap (skipped in stats-only mode)
|
|
111
|
+
if (emitImage) {
|
|
112
|
+
cv::applyColorMap(diff, result, colormapType);
|
|
113
|
+
// applyColorMap outputs BGR
|
|
114
|
+
outputChannel = "BGR";
|
|
115
|
+
}
|
|
110
116
|
|
|
111
117
|
taskMs = (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
|
|
112
118
|
|
|
113
|
-
if (outputFormat != "raw") {
|
|
119
|
+
if (emitImage && outputFormat != "raw") {
|
|
114
120
|
cv::Mat tmp = PrepareForEncoding(result, outputChannel, outputFormat);
|
|
115
121
|
encodeMs = EncodeToFormat(tmp, encodedBuf, outputFormat, quality, pngOptimize);
|
|
116
122
|
}
|
|
@@ -118,9 +124,12 @@ protected:
|
|
|
118
124
|
|
|
119
125
|
void OnOK() override {
|
|
120
126
|
Napi::Env env = Env();
|
|
121
|
-
Napi::Value jsImg = (
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
Napi::Value jsImg = env.Null();
|
|
128
|
+
if (emitImage) {
|
|
129
|
+
jsImg = (outputFormat != "raw")
|
|
130
|
+
? VectorToBuffer(env, std::move(encodedBuf))
|
|
131
|
+
: MatToRawJS(env, result, outputChannel);
|
|
132
|
+
}
|
|
124
133
|
|
|
125
134
|
Napi::Object out = Napi::Object::New(env);
|
|
126
135
|
out.Set("image", jsImg);
|
|
@@ -137,7 +146,8 @@ protected:
|
|
|
137
146
|
st.Set("p99", statP99);
|
|
138
147
|
st.Set("rmse", statRmse);
|
|
139
148
|
st.Set("psnr", statPsnr);
|
|
140
|
-
st.Set("ssim",
|
|
149
|
+
if (computeSsim) st.Set("ssim", statSsim);
|
|
150
|
+
else st.Set("ssim", env.Null());
|
|
141
151
|
st.Set("threshold", threshold);
|
|
142
152
|
st.Set("blobCount", statBlobCount);
|
|
143
153
|
st.Set("largestBlobArea", statLargestBlobArea);
|
|
@@ -202,7 +212,8 @@ private:
|
|
|
202
212
|
statRmse = std::sqrt(meanSq);
|
|
203
213
|
statPsnr = meanSq > 0 ? 10.0 * std::log10(255.0 * 255.0 / meanSq) : 100.0;
|
|
204
214
|
|
|
205
|
-
|
|
215
|
+
// SSIM is by far the costliest stat (6 full-res float blurs); optional
|
|
216
|
+
if (computeSsim) statSsim = MaskedSSIM(gray1, gray2, valid);
|
|
206
217
|
|
|
207
218
|
// Connected components on the changed mask -> blobs (largest first, capped)
|
|
208
219
|
cv::Mat labels, ccStats, centroids;
|
|
@@ -235,6 +246,8 @@ private:
|
|
|
235
246
|
int quality;
|
|
236
247
|
bool pngOptimize;
|
|
237
248
|
bool computeStats;
|
|
249
|
+
bool emitImage;
|
|
250
|
+
bool computeSsim;
|
|
238
251
|
double convertMs = 0, taskMs = 0, encodeMs = 0;
|
|
239
252
|
std::vector<uchar> encodedBuf;
|
|
240
253
|
|
|
@@ -249,7 +262,7 @@ Napi::Value HeatDiff(const Napi::CallbackInfo& info) {
|
|
|
249
262
|
|
|
250
263
|
if (info.Length() < 3 || !info[info.Length() - 1].IsFunction()) {
|
|
251
264
|
Napi::TypeError::New(env,
|
|
252
|
-
"heatDiff(image1, image2, colormapType, [blurSize], [threshold], [outputFormat], [quality], [pngOptimize], [computeStats], callback)")
|
|
265
|
+
"heatDiff(image1, image2, colormapType, [blurSize], [threshold], [outputFormat], [quality], [pngOptimize], [computeStats], [emitImage], [computeSsim], callback)")
|
|
253
266
|
.ThrowAsJavaScriptException();
|
|
254
267
|
return env.Null();
|
|
255
268
|
}
|
|
@@ -264,6 +277,8 @@ Napi::Value HeatDiff(const Napi::CallbackInfo& info) {
|
|
|
264
277
|
int quality = 90;
|
|
265
278
|
bool pngOptimize = false;
|
|
266
279
|
bool computeStats = false;
|
|
280
|
+
bool emitImage = true;
|
|
281
|
+
bool computeSsim = true;
|
|
267
282
|
size_t cbIdx = 3;
|
|
268
283
|
|
|
269
284
|
if (info.Length() >= 5) { blurSize = info[3].As<Napi::Number>().Int32Value(); cbIdx = 4; }
|
|
@@ -272,9 +287,11 @@ Napi::Value HeatDiff(const Napi::CallbackInfo& info) {
|
|
|
272
287
|
if (info.Length() >= 8) { quality = info[6].As<Napi::Number>().Int32Value(); cbIdx = 7; }
|
|
273
288
|
if (info.Length() >= 9) { pngOptimize = info[7].As<Napi::Boolean>().Value(); cbIdx = 8; }
|
|
274
289
|
if (info.Length() >= 10) { computeStats = info[8].As<Napi::Boolean>().Value(); cbIdx = 9; }
|
|
290
|
+
if (info.Length() >= 11) { emitImage = info[9].As<Napi::Boolean>().Value(); cbIdx = 10; }
|
|
291
|
+
if (info.Length() >= 12) { computeSsim = info[10].As<Napi::Boolean>().Value(); cbIdx = 11; }
|
|
275
292
|
|
|
276
293
|
(new HeatDiffWorker(info[cbIdx].As<Napi::Function>(),
|
|
277
294
|
jsImg1, jsImg2, colormapType, blurSize, threshold, outputFormat, quality, pngOptimize,
|
|
278
|
-
computeStats))->Queue();
|
|
295
|
+
computeStats, emitImage, computeSsim))->Queue();
|
|
279
296
|
return env.Undefined();
|
|
280
297
|
}
|