@rosepetal/node-red-contrib-image-tools 1.6.2 → 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.
@@ -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 updateStatsPathVisibility(){
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', updateStatsPathVisibility);
50
- updateStatsPathVisibility();
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
- debugWidthRow.toggle(debugCheckbox.is(':checked'));
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
- // Stats on by default; existing flows without the property get them too
143
- const statsEnabled = config.statsEnabled !== false && config.statsEnabled !== 'false';
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' && NodeUtils.hasAdvancedWebpOptions(config);
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
- RED.util.setMessageProperty(msg, outputPath, isArray ? images : images[0]);
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 = config.debugEnabled === true || config.debugEnabled === 'true';
197
+ const debugEnabled = imageEnabled &&
198
+ (config.debugEnabled === true || config.debugEnabled === 'true');
188
199
  if (debugEnabled) {
189
200
  try {
190
201
  let debugWidth = NodeUtils.resolveDimension(
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-arm64",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Prebuilt native binary for macOS ARM64 (Apple Silicon)",
5
5
  "os": ["darwin"],
6
6
  "cpu": ["arm64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-x64",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Prebuilt native binary for macOS x64 (Intel)",
5
5
  "os": ["darwin"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linux-arm64",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Prebuilt native binary for Linux ARM64 (glibc)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["arm64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linux-x64",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Prebuilt native binary for Linux x64 (glibc)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Prebuilt native binary for Linux x64 (musl/Alpine)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/rosepetal-engine-win32-x64",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Prebuilt rosepetal-image-engine binary for Windows x64",
5
5
  "os": ["win32"],
6
6
  "cpu": ["x64"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools",
3
- "version": "1.6.2",
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.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"
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
- cv::applyColorMap(diff, result, colormapType);
108
- // applyColorMap outputs BGR
109
- outputChannel = "BGR";
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 = (outputFormat != "raw")
122
- ? VectorToBuffer(env, std::move(encodedBuf))
123
- : MatToRawJS(env, result, outputChannel);
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", statSsim);
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
- statSsim = MaskedSSIM(gray1, gray2, valid);
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
  }