@rosepetal/node-red-contrib-image-tools 1.6.0 → 1.6.2
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/lib/bmp-decode.js +79 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +10 -6
- package/node-red-contrib-image-tools/nodes/io/image-in.js +11 -4
- 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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Pure-JS BMP decoder for uncompressed BI_RGB files (8/24/32-bit).
|
|
3
|
+
* Read-side counterpart of encodeBmpRaw in image-out; Sharp cannot read BMP.
|
|
4
|
+
* @author Rosepetal
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function isBmp(buf) {
|
|
8
|
+
return Buffer.isBuffer(buf) && buf.length >= 2 && buf[0] === 0x42 && buf[1] === 0x4D;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Decodes a BMP buffer to the toolkit's raw image object.
|
|
12
|
+
// Supports 8-bit palette, 24-bit and 32-bit uncompressed, top-down and bottom-up.
|
|
13
|
+
function decodeBmp(buf) {
|
|
14
|
+
if (!isBmp(buf) || buf.length < 54) throw new Error('Invalid BMP file');
|
|
15
|
+
|
|
16
|
+
const pixelOffset = buf.readUInt32LE(10);
|
|
17
|
+
const infoSize = buf.readUInt32LE(14);
|
|
18
|
+
if (infoSize < 40) throw new Error(`Unsupported BMP header (size ${infoSize})`);
|
|
19
|
+
|
|
20
|
+
const width = buf.readInt32LE(18);
|
|
21
|
+
const rawHeight = buf.readInt32LE(22);
|
|
22
|
+
const bpp = buf.readUInt16LE(28);
|
|
23
|
+
const compression = buf.readUInt32LE(30);
|
|
24
|
+
|
|
25
|
+
const topDown = rawHeight < 0;
|
|
26
|
+
const height = Math.abs(rawHeight);
|
|
27
|
+
if (width <= 0 || height === 0) throw new Error('Invalid BMP dimensions');
|
|
28
|
+
if (compression !== 0) throw new Error(`Unsupported BMP compression ${compression} (only uncompressed BI_RGB)`);
|
|
29
|
+
if (bpp !== 8 && bpp !== 24 && bpp !== 32) throw new Error(`Unsupported BMP bit depth ${bpp} (only 8/24/32)`);
|
|
30
|
+
|
|
31
|
+
const srcStride = (width * (bpp / 8) + 3) & ~3;
|
|
32
|
+
if (pixelOffset + srcStride * height > buf.length) throw new Error('Corrupt BMP: pixel data truncated');
|
|
33
|
+
|
|
34
|
+
// 8-bit files carry a BGRA palette; an all-gray palette maps to a GRAY image
|
|
35
|
+
let palette = null;
|
|
36
|
+
let grayPalette = false;
|
|
37
|
+
if (bpp === 8) {
|
|
38
|
+
const colors = buf.readUInt32LE(46) || 256;
|
|
39
|
+
const palOffset = 14 + infoSize;
|
|
40
|
+
if (palOffset + colors * 4 > buf.length) throw new Error('Corrupt BMP: palette truncated');
|
|
41
|
+
palette = [];
|
|
42
|
+
grayPalette = true;
|
|
43
|
+
for (let i = 0; i < colors; i++) {
|
|
44
|
+
const b = buf[palOffset + i * 4], g = buf[palOffset + i * 4 + 1], r = buf[palOffset + i * 4 + 2];
|
|
45
|
+
if (r !== g || g !== b) grayPalette = false;
|
|
46
|
+
palette.push([r, g, b]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const channels = bpp === 32 ? 4 : (bpp === 24 || !grayPalette) ? 3 : 1;
|
|
51
|
+
const colorSpace = channels === 4 ? 'RGBA' : channels === 3 ? 'RGB' : 'GRAY';
|
|
52
|
+
const out = Buffer.alloc(width * height * channels);
|
|
53
|
+
|
|
54
|
+
for (let y = 0; y < height; y++) {
|
|
55
|
+
const srcRow = pixelOffset + (topDown ? y : height - 1 - y) * srcStride;
|
|
56
|
+
const dstRow = y * width * channels;
|
|
57
|
+
if (bpp === 8) {
|
|
58
|
+
for (let x = 0; x < width; x++) {
|
|
59
|
+
const entry = palette[buf[srcRow + x]] || [0, 0, 0];
|
|
60
|
+
if (channels === 1) {
|
|
61
|
+
out[dstRow + x] = entry[0];
|
|
62
|
+
} else {
|
|
63
|
+
const d = dstRow + x * 3;
|
|
64
|
+
out[d] = entry[0]; out[d + 1] = entry[1]; out[d + 2] = entry[2];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
for (let x = 0; x < width; x++) {
|
|
69
|
+
const s = srcRow + x * (bpp / 8), d = dstRow + x * channels;
|
|
70
|
+
out[d] = buf[s + 2]; out[d + 1] = buf[s + 1]; out[d + 2] = buf[s]; // BGR → RGB
|
|
71
|
+
if (channels === 4) out[d + 3] = buf[s + 3];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { data: out, width, height, channels, colorSpace, dtype: 'uint8' };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { isBmp, decodeBmp };
|
|
@@ -14,6 +14,7 @@ try {
|
|
|
14
14
|
}
|
|
15
15
|
const fs = require('fs').promises;
|
|
16
16
|
const path = require('path');
|
|
17
|
+
const BmpDecode = require('../../lib/bmp-decode.js');
|
|
17
18
|
|
|
18
19
|
module.exports = function(RED) {
|
|
19
20
|
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
@@ -103,13 +104,16 @@ module.exports = function(RED) {
|
|
|
103
104
|
// Read encoded file once so we can reuse it for both decoding and debug preview
|
|
104
105
|
const fileBuffer = await fs.readFile(filePath);
|
|
105
106
|
|
|
106
|
-
//
|
|
107
|
-
const sharpInstance = sharp(fileBuffer);
|
|
107
|
+
// Decode: BMP natively (Sharp cannot read it), everything else via Sharp
|
|
108
108
|
const decodeStart = performance.now();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.
|
|
112
|
-
|
|
109
|
+
let data, info;
|
|
110
|
+
if (BmpDecode.isBmp(fileBuffer)) {
|
|
111
|
+
const decoded = BmpDecode.decodeBmp(fileBuffer);
|
|
112
|
+
data = decoded.data;
|
|
113
|
+
info = { width: decoded.width, height: decoded.height, channels: decoded.channels };
|
|
114
|
+
} else {
|
|
115
|
+
({ data, info } = await sharp(fileBuffer).raw().toBuffer({ resolveWithObject: true }));
|
|
116
|
+
}
|
|
113
117
|
const decodeMs = performance.now() - decodeStart;
|
|
114
118
|
|
|
115
119
|
// Determine colorSpace from Sharp info
|
|
@@ -11,6 +11,7 @@ try {
|
|
|
11
11
|
sharp = null;
|
|
12
12
|
}
|
|
13
13
|
const fs = require('fs').promises;
|
|
14
|
+
const BmpDecode = require('../../lib/bmp-decode.js');
|
|
14
15
|
|
|
15
16
|
module.exports = function(RED) {
|
|
16
17
|
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
@@ -46,10 +47,16 @@ module.exports = function(RED) {
|
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
//
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// Decode: BMP natively (Sharp cannot read it), everything else via Sharp
|
|
51
|
+
const fileBuffer = await fs.readFile(filePath);
|
|
52
|
+
let data, info;
|
|
53
|
+
if (BmpDecode.isBmp(fileBuffer)) {
|
|
54
|
+
const decoded = BmpDecode.decodeBmp(fileBuffer);
|
|
55
|
+
data = decoded.data;
|
|
56
|
+
info = { width: decoded.width, height: decoded.height, channels: decoded.channels };
|
|
57
|
+
} else {
|
|
58
|
+
({ data, info } = await sharp(fileBuffer).raw().toBuffer({ resolveWithObject: true }));
|
|
59
|
+
}
|
|
53
60
|
|
|
54
61
|
// Determine colorSpace from Sharp info
|
|
55
62
|
let colorSpace;
|
|
@@ -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.2",
|
|
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.2",
|
|
40
|
+
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.6.2",
|
|
41
|
+
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.6.2",
|
|
42
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.6.2",
|
|
43
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.6.2"
|
|
44
44
|
},
|
|
45
45
|
"node-red": {
|
|
46
46
|
"version": ">=1.0.0",
|