@rosepetal/node-red-contrib-image-tools 1.5.3 → 1.5.4
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 +2 -2
- package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +71 -23
- 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
|
@@ -211,8 +211,8 @@
|
|
|
211
211
|
</dl>
|
|
212
212
|
|
|
213
213
|
<h3>Inputs</h3>
|
|
214
|
-
<p>Two images in the standard format (raw image object or encoded buffer). Images of different sizes are resized to match the larger one.</p>
|
|
214
|
+
<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>
|
|
215
215
|
|
|
216
216
|
<h3>Outputs</h3>
|
|
217
|
-
<p>A 3-channel BGR heat map image in the selected output format.</p>
|
|
217
|
+
<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>
|
|
218
218
|
</script>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Node-RED logic for *rosepetal-heat-diff* (C++ backend).
|
|
3
3
|
* Computes absolute difference between two images and applies a colormap
|
|
4
4
|
* to produce a heat map visualization of the differences.
|
|
5
|
+
* Accepts two single images or two same-length arrays (paired by index).
|
|
5
6
|
*
|
|
6
7
|
* Timing fields returned by C++:
|
|
7
8
|
* timing.convertMs . timing.taskMs . timing.encodeMs
|
|
@@ -67,35 +68,64 @@ module.exports = function (RED) {
|
|
|
67
68
|
details: { image1Path, image2Path, outputPath }
|
|
68
69
|
},
|
|
69
70
|
msg, send, done,
|
|
70
|
-
{ originalPayload: baseImageForPassthrough, outputPath, outputType: '
|
|
71
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'preserve' }
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
// Both inputs must have the same shape: two singles, or two same-length arrays
|
|
76
|
+
const isArray = Array.isArray(image1);
|
|
77
|
+
if (isArray !== Array.isArray(image2)) {
|
|
76
78
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
77
79
|
node,
|
|
78
80
|
{
|
|
79
|
-
message: '
|
|
80
|
-
hint: `
|
|
81
|
+
message: 'image1 and image2 must both be single images or both be arrays',
|
|
82
|
+
hint: `"${image1Path}" is ${isArray ? 'an array' : 'a single image'} but "${image2Path}" is not.`,
|
|
81
83
|
details: { image1Path, image2Path, outputPath }
|
|
82
84
|
},
|
|
83
85
|
msg, send, done,
|
|
84
|
-
{ originalPayload: baseImageForPassthrough, outputPath, outputType: '
|
|
86
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'preserve' }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (isArray && (image1.length === 0 || image1.length !== image2.length)) {
|
|
90
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
91
|
+
node,
|
|
92
|
+
{
|
|
93
|
+
message: `Image arrays must be non-empty and of equal length (got ${image1.length} and ${image2.length})`,
|
|
94
|
+
hint: 'Images are paired by index; both arrays must contain the same number of images.',
|
|
95
|
+
details: { image1Path, image2Path, outputPath }
|
|
96
|
+
},
|
|
97
|
+
msg, send, done,
|
|
98
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'preserve' }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const list1 = (isArray ? image1 : [image1])
|
|
103
|
+
.map(img => NodeUtils.validateImageStructure(img, node));
|
|
104
|
+
if (list1.some(img => !img)) {
|
|
105
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
106
|
+
node,
|
|
107
|
+
{
|
|
108
|
+
message: 'First image input is invalid or missing',
|
|
109
|
+
hint: `Check that "${image1Path}" contains valid image(s).`,
|
|
110
|
+
details: { image1Path, image2Path, outputPath }
|
|
111
|
+
},
|
|
112
|
+
msg, send, done,
|
|
113
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'preserve' }
|
|
85
114
|
);
|
|
86
115
|
}
|
|
87
116
|
|
|
88
|
-
const
|
|
89
|
-
|
|
117
|
+
const list2 = (isArray ? image2 : [image2])
|
|
118
|
+
.map(img => NodeUtils.validateImageStructure(img, node));
|
|
119
|
+
if (list2.some(img => !img)) {
|
|
90
120
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
91
121
|
node,
|
|
92
122
|
{
|
|
93
|
-
message: 'Second image is invalid or missing',
|
|
94
|
-
hint: `Check that "${image2Path}" contains
|
|
123
|
+
message: 'Second image input is invalid or missing',
|
|
124
|
+
hint: `Check that "${image2Path}" contains valid image(s).`,
|
|
95
125
|
details: { image1Path, image2Path, outputPath }
|
|
96
126
|
},
|
|
97
127
|
msg, send, done,
|
|
98
|
-
{ originalPayload: baseImageForPassthrough, outputPath, outputType: '
|
|
128
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'preserve' }
|
|
99
129
|
);
|
|
100
130
|
}
|
|
101
131
|
|
|
@@ -110,17 +140,33 @@ module.exports = function (RED) {
|
|
|
110
140
|
const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
|
|
111
141
|
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
112
142
|
|
|
113
|
-
/*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
143
|
+
/* One C++ call per pair (index-matched) */
|
|
144
|
+
const results = await Promise.all(
|
|
145
|
+
list1.map((img1, i) =>
|
|
146
|
+
Cpp.heatDiff(img1, list2[i], colormapType, blurSize, threshold,
|
|
147
|
+
cppFormat, outputQuality, pngOptimize))
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
// Aggregate timings across pairs
|
|
151
|
+
const timing = results.reduce(
|
|
152
|
+
(acc, { timing: t }) => {
|
|
153
|
+
acc.convertMs += t?.convertMs ?? 0;
|
|
154
|
+
acc.taskMs += t?.taskMs ?? 0;
|
|
155
|
+
acc.encodeMs += t?.encodeMs ?? 0;
|
|
156
|
+
return acc;
|
|
157
|
+
},
|
|
158
|
+
{ convertMs: 0, taskMs: 0, encodeMs: 0 }
|
|
159
|
+
);
|
|
160
|
+
const images = results.map(r => r.image);
|
|
117
161
|
|
|
118
162
|
if (useSharpWebp) {
|
|
119
|
-
|
|
163
|
+
for (let i = 0; i < images.length; i++) {
|
|
164
|
+
images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
|
|
165
|
+
}
|
|
120
166
|
}
|
|
121
167
|
|
|
122
|
-
/* Write result */
|
|
123
|
-
RED.util.setMessageProperty(msg, outputPath,
|
|
168
|
+
/* Write result — array in, array out */
|
|
169
|
+
RED.util.setMessageProperty(msg, outputPath, isArray ? images : images[0]);
|
|
124
170
|
|
|
125
171
|
/* Status */
|
|
126
172
|
const total = performance.now() - t0;
|
|
@@ -137,14 +183,16 @@ module.exports = function (RED) {
|
|
|
137
183
|
);
|
|
138
184
|
debugWidth = Math.max(1, parseInt(debugWidth) || 200);
|
|
139
185
|
|
|
186
|
+
// For arrays, show the first heat map as representative
|
|
140
187
|
const debugResult = await NodeUtils.debugImageDisplay(
|
|
141
|
-
|
|
188
|
+
images[0], outputFormat, outputQuality,
|
|
142
189
|
node, debugEnabled, debugWidth
|
|
143
190
|
);
|
|
144
191
|
|
|
145
192
|
if (debugResult) {
|
|
146
193
|
debugFormat = debugResult.formatMessage;
|
|
147
|
-
NodeUtils.setSuccessStatusWithDebug(node,
|
|
194
|
+
NodeUtils.setSuccessStatusWithDebug(node, results.length, total, timing,
|
|
195
|
+
debugFormat + (isArray ? ' (first)' : ''));
|
|
148
196
|
}
|
|
149
197
|
} catch (debugError) {
|
|
150
198
|
node.warn(`Debug display error: ${debugError.message}`);
|
|
@@ -152,10 +200,10 @@ module.exports = function (RED) {
|
|
|
152
200
|
}
|
|
153
201
|
|
|
154
202
|
if (!debugFormat) {
|
|
155
|
-
NodeUtils.setSuccessStatus(node,
|
|
203
|
+
NodeUtils.setSuccessStatus(node, results.length, total, timing);
|
|
156
204
|
}
|
|
157
205
|
|
|
158
|
-
NodeUtils.recordPerformanceMetrics(node, msg, timing
|
|
206
|
+
NodeUtils.recordPerformanceMetrics(node, msg, timing, total);
|
|
159
207
|
|
|
160
208
|
send(msg);
|
|
161
209
|
done && done();
|
|
@@ -165,7 +213,7 @@ module.exports = function (RED) {
|
|
|
165
213
|
{
|
|
166
214
|
originalPayload: baseImageForPassthrough,
|
|
167
215
|
outputPath,
|
|
168
|
-
outputType: '
|
|
216
|
+
outputType: 'preserve',
|
|
169
217
|
context: { image1Path, image2Path, outputPath }
|
|
170
218
|
}
|
|
171
219
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosepetal/node-red-contrib-image-tools",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
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.5.
|
|
40
|
-
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.
|
|
41
|
-
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.
|
|
42
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.
|
|
43
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.
|
|
39
|
+
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.4",
|
|
40
|
+
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.4",
|
|
41
|
+
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.4",
|
|
42
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.4",
|
|
43
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.4"
|
|
44
44
|
},
|
|
45
45
|
"node-red": {
|
|
46
46
|
"version": ">=1.0.0",
|