@rosepetal/node-red-contrib-image-tools 1.5.0 → 1.5.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.
Files changed (37) hide show
  1. package/.claude/CLAUDE.md +33 -0
  2. package/.claude/agents/doc-env-validator.md +136 -0
  3. package/.claude/agents/doc-reviewer.md +78 -0
  4. package/.claude/agents/doc-writer.md +67 -0
  5. package/.claude/agents/gif-recorder.md +143 -0
  6. package/.claude/rules/claude-code-conventions.md +58 -0
  7. package/.claude/rules/documentation-conventions.md +136 -0
  8. package/.claude/rules/node-implementation-template.md +125 -0
  9. package/.claude/scripts/announce-orphans.sh +70 -0
  10. package/.claude/skills/doctor/SKILL.md +37 -0
  11. package/.claude/skills/document-all-nodes/SKILL.md +48 -0
  12. package/.claude/skills/document-node/SKILL.md +131 -0
  13. package/.claude/skills/document-node/prompts/synthesize-help.md +33 -0
  14. package/.claude/skills/document-node/prompts/synthesize-md.md +48 -0
  15. package/.claude/skills/document-node/templates/help-block.html.tmpl +34 -0
  16. package/.claude/skills/document-node/templates/node-doc.md.tmpl +43 -0
  17. package/artifacts/darwin-arm64/package.json +1 -1
  18. package/artifacts/linux-arm64/package.json +1 -1
  19. package/artifacts/linux-x64/package.json +1 -1
  20. package/artifacts/linuxmusl-x64/package.json +1 -1
  21. package/node-red-contrib-image-tools/nodes/io/image-out.html +22 -3
  22. package/node-red-contrib-image-tools/nodes/io/image-out.js +8 -4
  23. package/node-red-contrib-image-tools/nodes/specialized/heat-diff.html +218 -0
  24. package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +177 -0
  25. package/node-red-contrib-image-tools/nodes/transform/filter.html +106 -3
  26. package/node-red-contrib-image-tools/nodes/transform/filter.js +31 -4
  27. package/npm/darwin-arm64/package.json +1 -1
  28. package/npm/darwin-x64/package.json +1 -1
  29. package/npm/linux-arm64/package.json +1 -1
  30. package/npm/linux-x64/package.json +1 -1
  31. package/npm/linuxmusl-x64/package.json +1 -1
  32. package/npm/win32-x64/package.json +1 -1
  33. package/package.json +8 -7
  34. package/rosepetal-image-engine/binding.gyp +2 -1
  35. package/rosepetal-image-engine/src/filter.cpp +144 -0
  36. package/rosepetal-image-engine/src/heat-diff.cpp +146 -0
  37. package/rosepetal-image-engine/src/main.cpp +2 -0
@@ -24,11 +24,12 @@
24
24
  outputQuality: { value: 90 },
25
25
  pngCompression: { value: 8 },
26
26
  webpLossless: { value: false },
27
- webpEffort: { value: "" },
27
+ webpEffort: { value: 0 },
28
28
  webpSmartSubsample: { value: false },
29
29
  overwriteProtection: { value: true },
30
30
  maxImages: { value: "" },
31
31
  maxImagesType: { value: "num" },
32
+ diskThreshold: { value: 95 },
32
33
  active: { value: true },
33
34
  debugEnabled: { value: false },
34
35
  debugWidth: { value: 200 },
@@ -481,7 +482,7 @@
481
482
 
482
483
  <div class="form-row" id="webp-effort-row" style="display: none;">
483
484
  <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> WebP Effort</label>
484
- <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
485
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="0" style="width: 70px;">
485
486
  <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
486
487
  </div>
487
488
 
@@ -501,6 +502,12 @@
501
502
  <span style="margin-left: 10px; color: #666;">0 or blank keeps all files.</span>
502
503
  </div>
503
504
 
505
+ <div class="form-row">
506
+ <label for="node-input-diskThreshold"><i class="fa fa-hdd-o"></i> Disk Limit</label>
507
+ <input type="number" id="node-input-diskThreshold" min="0" max="100" step="1" style="width: 70px;">
508
+ <span style="margin-left: 10px; color: #666;">% full — skip saving above this. 0 disables check.</span>
509
+ </div>
510
+
504
511
  <!-- Debug Configuration -->
505
512
  <div class="form-row">
506
513
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -638,7 +645,7 @@
638
645
 
639
646
  <div class="form-row" id="webp-effort-row" style="display: none;">
640
647
  <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> WebP Effort</label>
641
- <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
648
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="0" style="width: 70px;">
642
649
  <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
643
650
  </div>
644
651
 
@@ -658,6 +665,12 @@
658
665
  <span style="margin-left: 10px; color: #666;">0 or blank keeps all files.</span>
659
666
  </div>
660
667
 
668
+ <div class="form-row">
669
+ <label for="node-input-diskThreshold"><i class="fa fa-hdd-o"></i> Disk Limit</label>
670
+ <input type="number" id="node-input-diskThreshold" min="0" max="100" step="1" style="width: 70px;">
671
+ <span style="margin-left: 10px; color: #666;">% full — skip saving above this. 0 disables check.</span>
672
+ </div>
673
+
661
674
  <!-- Debug Configuration -->
662
675
  <div class="form-row">
663
676
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -736,6 +749,9 @@
736
749
  <dt>Max Images <span class="property-type">number | msg | flow | global</span></dt>
737
750
  <dd>FIFO retention: deletes oldest files to keep at most this many.</dd>
738
751
 
752
+ <dt>Disk Limit <span class="property-type">number</span></dt>
753
+ <dd>Percentage of disk usage above which saving is skipped (default 95). Set to 0 to disable the check.</dd>
754
+
739
755
  <dt>Active Button <span class="property-type">button</span></dt>
740
756
  <dd>Enable/disable saving without modifying the flow.</dd>
741
757
  </dl>
@@ -819,6 +835,9 @@
819
835
  <dt>Max Images <span class="property-type">number | msg | flow | global</span></dt>
820
836
  <dd>FIFO retention: deletes oldest files to keep at most this many.</dd>
821
837
 
838
+ <dt>Disk Limit <span class="property-type">number</span></dt>
839
+ <dd>Percentage of disk usage above which saving is skipped (default 95). Set to 0 to disable the check.</dd>
840
+
822
841
  <dt>Active Button <span class="property-type">button</span></dt>
823
842
  <dd>Enable/disable saving without modifying the flow.</dd>
824
843
  </dl>
@@ -44,6 +44,10 @@ module.exports = function(RED) {
44
44
 
45
45
  // Initialize node state
46
46
  node.active = config.active !== false;
47
+ const diskThresholdPct = parseInt(config.diskThreshold, 10);
48
+ const diskThreshold = (Number.isInteger(diskThresholdPct) && diskThresholdPct > 0 && diskThresholdPct <= 100)
49
+ ? diskThresholdPct / 100
50
+ : 0;
47
51
  let diskCheckErrorLogged = false;
48
52
 
49
53
  updateNodeStatus();
@@ -268,8 +272,8 @@ module.exports = function(RED) {
268
272
  await fs.mkdir(folderPath, { recursive: true });
269
273
 
270
274
  // Disk check
271
- const diskInfo = await getDiskUsageInfo(folderPath);
272
- if (diskInfo && diskInfo.usedRatio >= 0.9) {
275
+ const diskInfo = diskThreshold > 0 ? await getDiskUsageInfo(folderPath) : null;
276
+ if (diskInfo && diskInfo.usedRatio >= diskThreshold) {
273
277
  const pct = (diskInfo.usedRatio * 100).toFixed(1);
274
278
  node.warn(`Storage ${pct}% full, skipping remaining items.`);
275
279
  node.status({ fill: 'yellow', shape: 'ring', text: `disk ${pct}% full` });
@@ -486,8 +490,8 @@ module.exports = function(RED) {
486
490
  }
487
491
  }
488
492
 
489
- const diskInfo = await getDiskUsageInfo(folderPath);
490
- if (diskInfo && diskInfo.usedRatio >= 0.9) {
493
+ const diskInfo = diskThreshold > 0 ? await getDiskUsageInfo(folderPath) : null;
494
+ if (diskInfo && diskInfo.usedRatio >= diskThreshold) {
491
495
  const usedPercent = (diskInfo.usedRatio * 100).toFixed(1);
492
496
  node.warn(`Storage at "${folderPath}" is ${usedPercent}% full. Skipping image save to avoid exhausting disk space.`);
493
497
  node.status({ fill: "yellow", shape: "ring", text: `disk ${usedPercent}% full` });
@@ -0,0 +1,218 @@
1
+ <!-- nodes/specialized/heat-diff.html -->
2
+
3
+ <script type="text/javascript">
4
+ RED.nodes.registerType('rp-heat-diff',{
5
+ category:'RP Image',
6
+ color:'#FF6B6B',
7
+ icon:'font-awesome/fa-fire',
8
+ defaults:{
9
+ name:{value:""},
10
+ image1Path:{value:"payload"}, image1PathType:{value:"msg"},
11
+ image2Path:{value:"goldenImage"}, image2PathType:{value:"msg"},
12
+ outputPath:{value:"payload"},outputPathType:{value:"msg"},
13
+ outputFormat:{value:"raw"},
14
+ outputQuality:{value:90},
15
+ pngOptimize:{value:false},
16
+ webpLossless:{value:false},
17
+ webpSmartSubsample:{value:false},
18
+ webpEffort:{value:""},
19
+ debugEnabled:{value:false},
20
+ debugWidth:{value:200},
21
+ debugWidthType:{value:"num"},
22
+ colormap:{value:"JET"},
23
+ blurSize:{value:0},
24
+ threshold:{value:0}
25
+ },
26
+ inputs:1,outputs:1,
27
+ label:function(){return this.name||"rp-heat-diff";},
28
+ oneditprepare:function(){
29
+ $("#node-input-image1Path").typedInput({
30
+ default:'msg',types:['msg','flow','global'],
31
+ typeField:"#node-input-image1PathType"});
32
+ $("#node-input-image2Path").typedInput({
33
+ default:'msg',types:['msg','flow','global'],
34
+ typeField:"#node-input-image2PathType"});
35
+ $("#node-input-outputPath").typedInput({
36
+ default:'msg',types:['msg','flow','global'],
37
+ typeField:"#node-input-outputPathType"});
38
+
39
+ // Threshold slider
40
+ var $thresholdSlider = $("#node-input-threshold");
41
+ var $thresholdValue = $("#threshold-value");
42
+ function updateThresholdDisplay() {
43
+ $thresholdValue.text($thresholdSlider.val());
44
+ }
45
+ $thresholdSlider.on("input", updateThresholdDisplay);
46
+ updateThresholdDisplay();
47
+
48
+ // Output format visibility
49
+ function updateQualityVisibility(){
50
+ var format = $("#node-input-outputFormat").val();
51
+ $("#quality-row").toggle(format === "jpg" || format === "webp");
52
+ $("#png-optimize-row").toggle(format === "png");
53
+ var isWebp = format === 'webp';
54
+ $("#webp-lossless-row").toggle(isWebp);
55
+ $("#webp-smartsubsample-row").toggle(isWebp);
56
+ $("#webp-effort-row").toggle(isWebp);
57
+ }
58
+ $("#node-input-outputFormat").on("change", updateQualityVisibility);
59
+ updateQualityVisibility();
60
+
61
+ // Debug display
62
+ var debugCheckbox = $('#node-input-debugEnabled');
63
+ var debugWidthRow = $('#debug-width-row');
64
+ $("#node-input-debugWidth").typedInput({
65
+ default: 'num',
66
+ types: ['num', 'msg', 'flow', 'global'],
67
+ typeField: "#node-input-debugWidthType"
68
+ });
69
+ function updateDebugWidthVisibility() {
70
+ debugWidthRow.toggle(debugCheckbox.is(':checked'));
71
+ }
72
+ updateDebugWidthVisibility();
73
+ debugCheckbox.on('change', updateDebugWidthVisibility);
74
+ }
75
+ });
76
+ </script>
77
+
78
+ <script type="text/x-red" data-template-name="rp-heat-diff">
79
+ <div class="form-row">
80
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
81
+ <input type="text" id="node-input-name" placeholder="Name">
82
+ </div>
83
+
84
+ <div class="form-row">
85
+ <label><i class="fa fa-picture-o"></i> Image 1</label>
86
+ <input type="text" id="node-input-image1Path" style="width:70%;">
87
+ <input type="hidden" id="node-input-image1PathType">
88
+ </div>
89
+
90
+ <div class="form-row">
91
+ <label><i class="fa fa-picture-o"></i> Image 2</label>
92
+ <input type="text" id="node-input-image2Path" style="width:70%;">
93
+ <input type="hidden" id="node-input-image2PathType">
94
+ </div>
95
+
96
+ <div class="form-row">
97
+ <label><i class="fa fa-sign-out"></i> Output</label>
98
+ <input type="text" id="node-input-outputPath" style="width:70%;">
99
+ <input type="hidden" id="node-input-outputPathType">
100
+ </div>
101
+
102
+ <div class="form-row">
103
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
104
+ <select id="node-input-outputFormat" style="width: 200px;">
105
+ <option value="raw">Raw (fastest)</option>
106
+ <option value="jpg">JPEG</option>
107
+ <option value="png">PNG</option>
108
+ <option value="webp">WebP</option>
109
+ </select>
110
+ </div>
111
+
112
+ <div class="form-row" id="quality-row">
113
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
114
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
115
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
116
+ </div>
117
+
118
+ <div class="form-row" id="png-optimize-row" style="display: none;">
119
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
120
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
121
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
122
+ </div>
123
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
124
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
125
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
126
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
127
+ </div>
128
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
129
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
130
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
131
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
132
+ </div>
133
+ <div class="form-row" id="webp-effort-row" style="display: none;">
134
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
135
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
136
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
137
+ </div>
138
+
139
+ <!-- Debug Configuration -->
140
+ <div class="form-row">
141
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
142
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
143
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
144
+ </div>
145
+ <div class="form-row" id="debug-width-row" style="display: none;">
146
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
147
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
148
+ <input type="hidden" id="node-input-debugWidthType">
149
+ <span style="margin-left: 10px; color: #666;">pixels</span>
150
+ </div>
151
+
152
+ <hr/>
153
+
154
+ <div class="form-row">
155
+ <label for="node-input-colormap"><i class="fa fa-fire"></i> Colormap</label>
156
+ <select id="node-input-colormap" style="width: 200px;">
157
+ <option value="JET">Jet (blue-cyan-green-yellow-red)</option>
158
+ <option value="HOT">Hot (black-red-yellow-white)</option>
159
+ <option value="INFERNO">Inferno (black-purple-red-yellow)</option>
160
+ <option value="TURBO">Turbo (improved rainbow)</option>
161
+ <option value="BONE">Bone (blue-tinted grayscale)</option>
162
+ <option value="COOL">Cool (cyan-magenta)</option>
163
+ <option value="RAINBOW">Rainbow</option>
164
+ <option value="OCEAN">Ocean (blue shades)</option>
165
+ <option value="PINK">Pink</option>
166
+ <option value="HSV">HSV</option>
167
+ </select>
168
+ </div>
169
+
170
+ <div class="form-row">
171
+ <label for="node-input-blurSize"><i class="fa fa-circle-o"></i> Blur</label>
172
+ <input type="number" id="node-input-blurSize" min="0" max="99" value="0" style="width: 70px;">
173
+ <span style="margin-left: 10px; color: #666;">Gaussian blur kernel size (0 = off, odd values)</span>
174
+ </div>
175
+
176
+ <div class="form-row">
177
+ <label for="node-input-threshold"><i class="fa fa-filter"></i> Threshold</label>
178
+ <input type="range" id="node-input-threshold" min="0" max="255" value="0" style="width: 200px;">
179
+ <span id="threshold-value" style="margin-left: 10px; font-weight: bold;">0</span>
180
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
181
+ Pixel differences below this value are suppressed (0 = show all)
182
+ </div>
183
+ </div>
184
+ </script>
185
+
186
+ <script type="text/x-red" data-help-name="rp-heat-diff">
187
+ <p><b>rosepetal-heat-diff</b> computes the absolute pixel difference between two images and visualizes the result as a color-mapped heat image. Useful for comparing a scanned image against a golden reference after alignment.</p>
188
+
189
+ <h3>Details</h3>
190
+ <p>Both input images are converted to grayscale, then the per-pixel absolute difference is computed. The difference map is passed through a configurable colormap to produce a heat visualization where brighter/warmer colors indicate larger differences.</p>
191
+
192
+ <h3>Properties</h3>
193
+ <dl class="message-properties">
194
+ <dt>Image 1 <span class="property-type">string</span></dt>
195
+ <dd>Path to the first image (e.g. the scanned/test image).</dd>
196
+
197
+ <dt>Image 2 <span class="property-type">string</span></dt>
198
+ <dd>Path to the second image (e.g. the golden/reference image).</dd>
199
+
200
+ <dt>Output to <span class="property-type">string</span></dt>
201
+ <dd>Message property where the heat map image will be stored.</dd>
202
+
203
+ <dt>Colormap <span class="property-type">string</span></dt>
204
+ <dd>Color mapping applied to the difference: JET, HOT, INFERNO, TURBO, BONE, COOL, RAINBOW, OCEAN, PINK, HSV.</dd>
205
+
206
+ <dt>Blur <span class="property-type">number</span></dt>
207
+ <dd>Gaussian blur kernel size applied to the difference before colormapping. Smooths noise. 0 to disable.</dd>
208
+
209
+ <dt>Threshold <span class="property-type">number</span></dt>
210
+ <dd>Pixel differences below this value (0-255) are set to zero before colormapping. Suppresses minor noise.</dd>
211
+ </dl>
212
+
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>
215
+
216
+ <h3>Outputs</h3>
217
+ <p>A 3-channel BGR heat map image in the selected output format.</p>
218
+ </script>
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Node-RED logic for *rosepetal-heat-diff* (C++ backend).
3
+ * Computes absolute difference between two images and applies a colormap
4
+ * to produce a heat map visualization of the differences.
5
+ *
6
+ * Timing fields returned by C++:
7
+ * timing.convertMs . timing.taskMs . timing.encodeMs
8
+ */
9
+ const { performance } = require('perf_hooks');
10
+ const Cpp = require('../../lib/cpp-bridge.js');
11
+
12
+ // OpenCV COLORMAP constants
13
+ const COLORMAP = {
14
+ 'JET': 2,
15
+ 'HOT': 11,
16
+ 'INFERNO': 14,
17
+ 'TURBO': 20,
18
+ 'BONE': 1,
19
+ 'COOL': 8,
20
+ 'RAINBOW': 4,
21
+ 'OCEAN': 5,
22
+ 'PINK': 10,
23
+ 'HSV': 9
24
+ };
25
+
26
+ module.exports = function (RED) {
27
+ const NodeUtils = require('../../lib/node-utils.js')(RED);
28
+
29
+ function HeatDiffNode (config) {
30
+ RED.nodes.createNode(this, config);
31
+ const node = this;
32
+
33
+ node.on('input', async (msg, send, done) => {
34
+ const outputPath = config.outputPath || 'payload';
35
+ const image1Path = config.image1Path || 'payload';
36
+ const image2Path = config.image2Path || 'payload.image2';
37
+
38
+ const { value: image1, error: image1Err } =
39
+ NodeUtils.safeGetMessageProperty(msg, image1Path);
40
+ if (image1Err) {
41
+ return NodeUtils.handleValidationErrorWithPassthrough(
42
+ node,
43
+ {
44
+ message: `Invalid image1Path "${image1Path}": ${image1Err.message}`,
45
+ hint: `Ensure "${image1Path}" exists on msg before this node.`,
46
+ details: { image1Path, image2Path, outputPath }
47
+ },
48
+ msg, send, done,
49
+ { originalPayload: undefined, outputPath: null, outputType: 'preserve' }
50
+ );
51
+ }
52
+
53
+ const baseImageForPassthrough = image1;
54
+
55
+ try {
56
+ const t0 = performance.now();
57
+ node.status({});
58
+
59
+ const { value: image2, error: image2Err } =
60
+ NodeUtils.safeGetMessageProperty(msg, image2Path);
61
+ if (image2Err) {
62
+ return NodeUtils.handleValidationErrorWithPassthrough(
63
+ node,
64
+ {
65
+ message: `Invalid image2Path "${image2Path}": ${image2Err.message}`,
66
+ hint: `Ensure "${image2Path}" exists on msg before this node.`,
67
+ details: { image1Path, image2Path, outputPath }
68
+ },
69
+ msg, send, done,
70
+ { originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
71
+ );
72
+ }
73
+
74
+ const img1 = NodeUtils.validateImageStructure(image1, node);
75
+ if (!img1) {
76
+ return NodeUtils.handleValidationErrorWithPassthrough(
77
+ node,
78
+ {
79
+ message: 'First image is invalid or missing',
80
+ hint: `Check that "${image1Path}" contains a valid image.`,
81
+ details: { image1Path, image2Path, outputPath }
82
+ },
83
+ msg, send, done,
84
+ { originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
85
+ );
86
+ }
87
+
88
+ const img2 = NodeUtils.validateImageStructure(image2, node);
89
+ if (!img2) {
90
+ return NodeUtils.handleValidationErrorWithPassthrough(
91
+ node,
92
+ {
93
+ message: 'Second image is invalid or missing',
94
+ hint: `Check that "${image2Path}" contains a valid image.`,
95
+ details: { image1Path, image2Path, outputPath }
96
+ },
97
+ msg, send, done,
98
+ { originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
99
+ );
100
+ }
101
+
102
+ /* Options from the editor */
103
+ const colormapName = config.colormap || 'JET';
104
+ const colormapType = COLORMAP[colormapName] !== undefined ? COLORMAP[colormapName] : 2;
105
+ const blurSize = Math.max(0, parseInt(config.blurSize) || 0);
106
+ const threshold = Math.max(0, Math.min(255, parseInt(config.threshold) || 0));
107
+ const outputFormat = config.outputFormat || 'raw';
108
+ const outputQuality = parseInt(config.outputQuality) || 90;
109
+ const pngOptimize = config.pngOptimize || false;
110
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
111
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
112
+
113
+ /* Single call to the C++ addon */
114
+ let { image, timing = {} } =
115
+ await Cpp.heatDiff(img1, img2, colormapType, blurSize, threshold,
116
+ cppFormat, outputQuality, pngOptimize);
117
+
118
+ if (useSharpWebp) {
119
+ image = await NodeUtils.encodeWebpAdvanced(image, config);
120
+ }
121
+
122
+ /* Write result */
123
+ RED.util.setMessageProperty(msg, outputPath, image);
124
+
125
+ /* Status */
126
+ const total = performance.now() - t0;
127
+
128
+ let debugFormat = null;
129
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
130
+ if (debugEnabled) {
131
+ try {
132
+ let debugWidth = NodeUtils.resolveDimension(
133
+ node,
134
+ config.debugWidthType || 'num',
135
+ config.debugWidth,
136
+ msg
137
+ );
138
+ debugWidth = Math.max(1, parseInt(debugWidth) || 200);
139
+
140
+ const debugResult = await NodeUtils.debugImageDisplay(
141
+ image, outputFormat, outputQuality,
142
+ node, debugEnabled, debugWidth
143
+ );
144
+
145
+ if (debugResult) {
146
+ debugFormat = debugResult.formatMessage;
147
+ NodeUtils.setSuccessStatusWithDebug(node, 1, total, timing, debugFormat);
148
+ }
149
+ } catch (debugError) {
150
+ node.warn(`Debug display error: ${debugError.message}`);
151
+ }
152
+ }
153
+
154
+ if (!debugFormat) {
155
+ NodeUtils.setSuccessStatus(node, 1, total, timing);
156
+ }
157
+
158
+ NodeUtils.recordPerformanceMetrics(node, msg, timing || {}, total);
159
+
160
+ send(msg);
161
+ done && done();
162
+ } catch (err) {
163
+ NodeUtils.handleNodeErrorWithPassthrough(
164
+ node, err, msg, send, done, 'heat-diff processing',
165
+ {
166
+ originalPayload: baseImageForPassthrough,
167
+ outputPath,
168
+ outputType: 'single',
169
+ context: { image1Path, image2Path, outputPath }
170
+ }
171
+ );
172
+ }
173
+ });
174
+ }
175
+
176
+ RED.nodes.registerType('rp-heat-diff', HeatDiffNode);
177
+ };
@@ -24,7 +24,14 @@
24
24
  kernelSize: { value: "3" },
25
25
  kernelSizeType: { value: "num" },
26
26
  intensity: { value: "1.0" },
27
- intensityType: { value: "num" }
27
+ intensityType: { value: "num" },
28
+ // Otsu-specific
29
+ otsuInvert: { value: false },
30
+ otsuPreBlur: { value: 0 },
31
+ otsuPreBlurType: { value: "num" },
32
+ // Histogram EQ-specific
33
+ histEqStrength: { value: 100 },
34
+ histEqStrengthType: { value: "num" }
28
35
  },
29
36
  inputs: 1,
30
37
  outputs: 1,
@@ -58,13 +65,30 @@
58
65
  typeField: "#node-input-intensityType"
59
66
  });
60
67
 
61
- // === Dynamic parameter updates based on filter type ===
68
+ // === Otsu / Histogram EQ TypedInputs (dynamic values) ===
69
+ $("#node-input-otsuPreBlur").typedInput({
70
+ default: 'num',
71
+ types: ['num', 'msg', 'flow', 'global'],
72
+ typeField: "#node-input-otsuPreBlurType"
73
+ });
74
+ $("#node-input-histEqStrength").typedInput({
75
+ default: 'num',
76
+ types: ['num', 'msg', 'flow', 'global'],
77
+ typeField: "#node-input-histEqStrengthType"
78
+ });
79
+
62
80
  function updateFilterParameters() {
63
81
  const filterType = $("#node-input-filterType").val();
64
82
  const kernelSizeRow = $("#kernel-size-row");
65
83
  const intensityRow = $("#intensity-row");
66
84
  const intensityLabel = $("#intensity-label");
67
-
85
+ const otsuRows = $("#otsu-params");
86
+ const histEqRows = $("#histeq-params");
87
+
88
+ // Hide all filter-specific rows first
89
+ otsuRows.hide();
90
+ histEqRows.hide();
91
+
68
92
  // Show/hide and update labels based on filter type
69
93
  switch (filterType) {
70
94
  case 'blur':
@@ -92,6 +116,21 @@
92
116
  intensityRow.show();
93
117
  intensityLabel.text("Blur Radius");
94
118
  break;
119
+ case 'otsu':
120
+ kernelSizeRow.hide();
121
+ intensityRow.hide();
122
+ otsuRows.show();
123
+ break;
124
+ case 'histogram_eq':
125
+ kernelSizeRow.hide();
126
+ intensityRow.hide();
127
+ histEqRows.show();
128
+ break;
129
+ case 'clahe':
130
+ kernelSizeRow.show();
131
+ intensityRow.show();
132
+ intensityLabel.text("Clip Limit");
133
+ break;
95
134
  default:
96
135
  kernelSizeRow.show();
97
136
  intensityRow.show();
@@ -342,6 +381,9 @@
342
381
  <option value="edge">Edge Detection</option>
343
382
  <option value="emboss">Emboss</option>
344
383
  <option value="gaussian">Gaussian Blur</option>
384
+ <option value="otsu">Otsu Threshold</option>
385
+ <option value="histogram_eq">Histogram Equalization</option>
386
+ <option value="clahe">CLAHE (Adaptive Hist. Eq.)</option>
345
387
  </select>
346
388
  </div>
347
389
 
@@ -357,6 +399,35 @@
357
399
  <input type="hidden" id="node-input-intensityType">
358
400
  </div>
359
401
 
402
+ <!-- Otsu-specific parameters -->
403
+ <div id="otsu-params" style="display: none;">
404
+ <div class="form-row">
405
+ <label for="node-input-otsuInvert"><i class="fa fa-exchange"></i> Invert</label>
406
+ <input type="checkbox" id="node-input-otsuInvert" style="display:inline-block; width:auto; vertical-align:baseline;">
407
+ <label for="node-input-otsuInvert" style="width:auto; margin-left:5px;">Invert binary output (white background, black foreground)</label>
408
+ </div>
409
+ <div class="form-row">
410
+ <label for="node-input-otsuPreBlur"><i class="fa fa-circle-o"></i> Pre-blur</label>
411
+ <input type="text" id="node-input-otsuPreBlur" style="width: 70%;" placeholder="0 = off, odd 3-15">
412
+ <input type="hidden" id="node-input-otsuPreBlurType">
413
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
414
+ Gaussian blur before thresholding to reduce noise (0 = off, odd values 3-15)
415
+ </div>
416
+ </div>
417
+ </div>
418
+
419
+ <!-- Histogram EQ-specific parameters -->
420
+ <div id="histeq-params" style="display: none;">
421
+ <div class="form-row">
422
+ <label for="node-input-histEqStrength"><i class="fa fa-sliders"></i> Strength</label>
423
+ <input type="text" id="node-input-histEqStrength" style="width: 70%;" placeholder="0-100">
424
+ <input type="hidden" id="node-input-histEqStrengthType">
425
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
426
+ Blend between original (0%) and fully equalized (100%)
427
+ </div>
428
+ </div>
429
+ </div>
430
+
360
431
  <div class="form-tips">
361
432
  <b>Tips:</b>
362
433
  <ul>
@@ -445,6 +516,9 @@
445
516
  <option value="edge">Edge Detection</option>
446
517
  <option value="emboss">Emboss</option>
447
518
  <option value="gaussian">Gaussian Blur</option>
519
+ <option value="otsu">Otsu Threshold</option>
520
+ <option value="histogram_eq">Histogram Equalization</option>
521
+ <option value="clahe">CLAHE (Adaptive Hist. Eq.)</option>
448
522
  </select>
449
523
  </div>
450
524
 
@@ -460,6 +534,35 @@
460
534
  <input type="hidden" id="node-input-intensityType">
461
535
  </div>
462
536
 
537
+ <!-- Otsu-specific parameters -->
538
+ <div id="otsu-params" style="display: none;">
539
+ <div class="form-row">
540
+ <label for="node-input-otsuInvert"><i class="fa fa-exchange"></i> Invert</label>
541
+ <input type="checkbox" id="node-input-otsuInvert" style="display:inline-block; width:auto; vertical-align:baseline;">
542
+ <label for="node-input-otsuInvert" style="width:auto; margin-left:5px;">Invert binary output (white background, black foreground)</label>
543
+ </div>
544
+ <div class="form-row">
545
+ <label for="node-input-otsuPreBlur"><i class="fa fa-circle-o"></i> Pre-blur</label>
546
+ <input type="text" id="node-input-otsuPreBlur" style="width: 70%;" placeholder="0 = off, odd 3-15">
547
+ <input type="hidden" id="node-input-otsuPreBlurType">
548
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
549
+ Gaussian blur before thresholding to reduce noise (0 = off, odd values 3-15)
550
+ </div>
551
+ </div>
552
+ </div>
553
+
554
+ <!-- Histogram EQ-specific parameters -->
555
+ <div id="histeq-params" style="display: none;">
556
+ <div class="form-row">
557
+ <label for="node-input-histEqStrength"><i class="fa fa-sliders"></i> Strength</label>
558
+ <input type="text" id="node-input-histEqStrength" style="width: 70%;" placeholder="0-100">
559
+ <input type="hidden" id="node-input-histEqStrengthType">
560
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
561
+ Blend between original (0%) and fully equalized (100%)
562
+ </div>
563
+ </div>
564
+ </div>
565
+
463
566
  <div class="form-tips">
464
567
  <b>Tips:</b>
465
568
  <ul>