@rosepetal/node-red-contrib-image-tools 1.4.3 → 1.5.1

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-arm64",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
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.4.3",
3
+ "version": "1.5.1",
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.4.3",
3
+ "version": "1.5.1",
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.4.3",
3
+ "version": "1.5.1",
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.4.3",
3
+ "version": "1.5.1",
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.4.3",
3
+ "version": "1.5.1",
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.4.3",
3
+ "version": "1.5.1",
4
4
  "description": "Node-RED Image Processing Toolkit",
5
5
  "main": "install.sh",
6
6
  "directories": {
@@ -35,11 +35,11 @@
35
35
  "sharp": "^0.34.2"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.1.3",
39
- "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.1.3",
40
- "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.1.3",
41
- "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.1.3",
42
- "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.1.3"
38
+ "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.1",
39
+ "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.1",
40
+ "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.1",
41
+ "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.1",
42
+ "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.1"
43
43
  },
44
44
  "node-red": {
45
45
  "version": ">=1.0.0",
@@ -62,7 +62,8 @@
62
62
  "rp-blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
63
63
  "rp-add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
64
64
  "rp-add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
65
- "rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js"
65
+ "rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
66
+ "rp-heat-diff": "node-red-contrib-image-tools/nodes/specialized/heat-diff.js"
66
67
  }
67
68
  }
68
69
  }
@@ -22,7 +22,8 @@
22
22
  "src/add-bbs.cpp",
23
23
  "src/image-align.cpp",
24
24
  "src/draw.cpp",
25
- "src/color-convert.cpp"
25
+ "src/color-convert.cpp",
26
+ "src/heat-diff.cpp"
26
27
  ],
27
28
  "defines": [
28
29
  "NAPI_CPP_EXCEPTIONS"
@@ -37,6 +38,9 @@
37
38
  ["OS=='linux'", {
38
39
  "libraries": [
39
40
  "<(opencv_lib_dir)/libopencv_imgcodecs.a",
41
+ "<(opencv_lib_dir)/libopencv_calib3d.a",
42
+ "<(opencv_lib_dir)/libopencv_features2d.a",
43
+ "<(opencv_lib_dir)/libopencv_flann.a",
40
44
  "<(opencv_lib_dir)/libopencv_video.a",
41
45
  "<(opencv_lib_dir)/libopencv_imgproc.a",
42
46
  "<(opencv_lib_dir)/libopencv_core.a",
@@ -44,6 +48,7 @@
44
48
  "<(opencv_lib_dir)/opencv4/3rdparty/liblibpng.a",
45
49
  "<(opencv_lib_dir)/opencv4/3rdparty/liblibwebp.a",
46
50
  "<(opencv_lib_dir)/opencv4/3rdparty/libzlib.a",
51
+ "<(opencv_lib_dir)/opencv4/3rdparty/libtbb.a",
47
52
  "-lpthread",
48
53
  "-ldl"
49
54
  ],
@@ -54,6 +59,19 @@
54
59
  "-frtti",
55
60
  "-fno-omit-frame-pointer"
56
61
  ],
62
+ "conditions": [
63
+ ["target_arch=='x64'", {
64
+ "cflags_cc": [
65
+ "-march=x86-64-v3",
66
+ "-mtune=generic"
67
+ ]
68
+ }],
69
+ ["target_arch=='arm64'", {
70
+ "cflags_cc": [
71
+ "-march=armv8-a"
72
+ ]
73
+ }]
74
+ ],
57
75
  "ldflags": [
58
76
  "-static-libgcc",
59
77
  "-static-libstdc++"
@@ -62,13 +80,17 @@
62
80
  ["OS=='mac'", {
63
81
  "libraries": [
64
82
  "<(opencv_lib_dir)/libopencv_imgcodecs.a",
83
+ "<(opencv_lib_dir)/libopencv_calib3d.a",
84
+ "<(opencv_lib_dir)/libopencv_features2d.a",
85
+ "<(opencv_lib_dir)/libopencv_flann.a",
65
86
  "<(opencv_lib_dir)/libopencv_video.a",
66
87
  "<(opencv_lib_dir)/libopencv_imgproc.a",
67
88
  "<(opencv_lib_dir)/libopencv_core.a",
68
89
  "<(opencv_lib_dir)/opencv4/3rdparty/liblibjpeg-turbo.a",
69
90
  "<(opencv_lib_dir)/opencv4/3rdparty/liblibpng.a",
70
91
  "<(opencv_lib_dir)/opencv4/3rdparty/liblibwebp.a",
71
- "<(opencv_lib_dir)/opencv4/3rdparty/libzlib.a"
92
+ "<(opencv_lib_dir)/opencv4/3rdparty/libzlib.a",
93
+ "<(opencv_lib_dir)/opencv4/3rdparty/libtbb.a"
72
94
  ],
73
95
  "xcode_settings": {
74
96
  "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
@@ -83,13 +105,17 @@
83
105
  ["OS=='win'", {
84
106
  "libraries": [
85
107
  "<(opencv_lib_dir)/opencv_imgcodecs4.lib",
108
+ "<(opencv_lib_dir)/opencv_calib3d4.lib",
109
+ "<(opencv_lib_dir)/opencv_features2d4.lib",
110
+ "<(opencv_lib_dir)/opencv_flann4.lib",
86
111
  "<(opencv_lib_dir)/opencv_video4.lib",
87
112
  "<(opencv_lib_dir)/opencv_imgproc4.lib",
88
113
  "<(opencv_lib_dir)/opencv_core4.lib",
89
114
  "<(opencv_lib_dir)/opencv4/3rdparty/libjpeg-turbo.lib",
90
115
  "<(opencv_lib_dir)/opencv4/3rdparty/libpng.lib",
91
116
  "<(opencv_lib_dir)/opencv4/3rdparty/libwebp.lib",
92
- "<(opencv_lib_dir)/opencv4/3rdparty/zlib.lib"
117
+ "<(opencv_lib_dir)/opencv4/3rdparty/zlib.lib",
118
+ "<(opencv_lib_dir)/opencv4/3rdparty/tbb.lib"
93
119
  ],
94
120
  "msvs_settings": {
95
121
  "VCCLCompilerTool": {
@@ -68,6 +68,12 @@ protected:
68
68
  ApplyEmbossFilter();
69
69
  } else if (filterType_ == "gaussian") {
70
70
  ApplyGaussianFilter();
71
+ } else if (filterType_ == "otsu") {
72
+ ApplyOtsuFilter();
73
+ } else if (filterType_ == "histogram_eq") {
74
+ ApplyHistogramEqualization();
75
+ } else if (filterType_ == "clahe") {
76
+ ApplyCLAHE();
71
77
  } else {
72
78
  throw std::runtime_error("Unknown filter type: " + filterType_);
73
79
  }
@@ -181,6 +187,144 @@ private:
181
187
  double sigma = kernelSize_ / 6.0 * intensity_; // Scale sigma with intensity
182
188
  cv::GaussianBlur(input_, result_, ksize, sigma);
183
189
  }
190
+
191
+ void ApplyOtsuFilter() {
192
+ // kernelSize_ = pre-blur kernel (0 = none, 3+ = Gaussian blur)
193
+ // intensity_ = invert flag (0 = normal THRESH_BINARY, >0 = THRESH_BINARY_INV)
194
+
195
+ // Convert to grayscale if needed
196
+ cv::Mat gray;
197
+ bool wasColor = (input_.channels() > 1);
198
+
199
+ if (wasColor) {
200
+ if (channel_ == "BGR" || channel_ == "BGRA")
201
+ cv::cvtColor(input_, gray, input_.channels() == 4 ? cv::COLOR_BGRA2GRAY : cv::COLOR_BGR2GRAY);
202
+ else
203
+ cv::cvtColor(input_, gray, input_.channels() == 4 ? cv::COLOR_RGBA2GRAY : cv::COLOR_RGB2GRAY);
204
+ } else {
205
+ gray = input_;
206
+ }
207
+
208
+ // Optional pre-blur to reduce noise before thresholding
209
+ if (kernelSize_ >= 3) {
210
+ int k = kernelSize_ | 1; // ensure odd
211
+ cv::GaussianBlur(gray, gray, cv::Size(k, k), 0);
212
+ }
213
+
214
+ int threshType = (intensity_ > 0.5) ? cv::THRESH_BINARY_INV : cv::THRESH_BINARY;
215
+ cv::Mat binary;
216
+ cv::threshold(gray, binary, 0, 255, threshType | cv::THRESH_OTSU);
217
+
218
+ // Convert back to original channel count
219
+ if (wasColor) {
220
+ if (channel_ == "BGR" || channel_ == "BGRA") {
221
+ cv::cvtColor(binary, result_, cv::COLOR_GRAY2BGR);
222
+ if (input_.channels() == 4) cv::cvtColor(result_, result_, cv::COLOR_BGR2BGRA);
223
+ } else {
224
+ cv::cvtColor(binary, result_, cv::COLOR_GRAY2RGB);
225
+ if (input_.channels() == 4) cv::cvtColor(result_, result_, cv::COLOR_RGB2RGBA);
226
+ }
227
+ } else {
228
+ result_ = binary;
229
+ }
230
+ }
231
+
232
+ void ApplyHistogramEqualization() {
233
+ // intensity_ = strength blend factor (0.0 = original, 1.0 = fully equalized)
234
+ cv::Mat equalized;
235
+
236
+ if (input_.channels() == 1) {
237
+ cv::equalizeHist(input_, equalized);
238
+ } else {
239
+ // For color images, convert to YCrCb, equalize Y channel, convert back
240
+ cv::Mat ycrcb;
241
+ if (channel_ == "BGR" || channel_ == "BGRA") {
242
+ cv::Mat bgr = input_;
243
+ if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_BGRA2BGR);
244
+ cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
245
+ } else {
246
+ cv::Mat bgr;
247
+ if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_RGBA2BGR);
248
+ else cv::cvtColor(input_, bgr, cv::COLOR_RGB2BGR);
249
+ cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
250
+ }
251
+
252
+ std::vector<cv::Mat> channels;
253
+ cv::split(ycrcb, channels);
254
+ cv::equalizeHist(channels[0], channels[0]);
255
+ cv::merge(channels, ycrcb);
256
+
257
+ cv::Mat bgr_out;
258
+ cv::cvtColor(ycrcb, bgr_out, cv::COLOR_YCrCb2BGR);
259
+
260
+ if (channel_ == "BGR") {
261
+ equalized = bgr_out;
262
+ } else if (channel_ == "BGRA") {
263
+ cv::cvtColor(bgr_out, equalized, cv::COLOR_BGR2BGRA);
264
+ } else if (channel_ == "RGB") {
265
+ cv::cvtColor(bgr_out, equalized, cv::COLOR_BGR2RGB);
266
+ } else if (channel_ == "RGBA") {
267
+ cv::cvtColor(bgr_out, equalized, cv::COLOR_BGR2RGBA);
268
+ } else {
269
+ equalized = bgr_out;
270
+ }
271
+ }
272
+
273
+ // Blend between original and equalized based on strength
274
+ double strength = std::max(0.0, std::min(intensity_, 1.0));
275
+ if (strength >= 0.999) {
276
+ result_ = equalized;
277
+ } else if (strength <= 0.001) {
278
+ result_ = input_.clone();
279
+ } else {
280
+ cv::addWeighted(equalized, strength, input_, 1.0 - strength, 0, result_);
281
+ }
282
+ }
283
+
284
+ void ApplyCLAHE() {
285
+ // Contrast Limited Adaptive Histogram Equalization
286
+ // intensity_ controls clip limit (default 2.0), kernelSize_ controls tile grid
287
+ double clipLimit = std::max(1.0, intensity_ * 4.0); // scale intensity 0-2 -> clipLimit 0-8
288
+ int tileSize = std::max(2, kernelSize_); // use kernel size as tile grid size
289
+
290
+ auto clahe = cv::createCLAHE(clipLimit, cv::Size(tileSize, tileSize));
291
+
292
+ if (input_.channels() == 1) {
293
+ clahe->apply(input_, result_);
294
+ } else {
295
+ cv::Mat ycrcb;
296
+ if (channel_ == "BGR" || channel_ == "BGRA") {
297
+ cv::Mat bgr = input_;
298
+ if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_BGRA2BGR);
299
+ cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
300
+ } else {
301
+ cv::Mat bgr;
302
+ if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_RGBA2BGR);
303
+ else cv::cvtColor(input_, bgr, cv::COLOR_RGB2BGR);
304
+ cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
305
+ }
306
+
307
+ std::vector<cv::Mat> channels;
308
+ cv::split(ycrcb, channels);
309
+ clahe->apply(channels[0], channels[0]);
310
+ cv::merge(channels, ycrcb);
311
+
312
+ cv::Mat bgr_out;
313
+ cv::cvtColor(ycrcb, bgr_out, cv::COLOR_YCrCb2BGR);
314
+
315
+ if (channel_ == "BGR") {
316
+ result_ = bgr_out;
317
+ } else if (channel_ == "BGRA") {
318
+ cv::cvtColor(bgr_out, result_, cv::COLOR_BGR2BGRA);
319
+ } else if (channel_ == "RGB") {
320
+ cv::cvtColor(bgr_out, result_, cv::COLOR_BGR2RGB);
321
+ } else if (channel_ == "RGBA") {
322
+ cv::cvtColor(bgr_out, result_, cv::COLOR_BGR2RGBA);
323
+ } else {
324
+ result_ = bgr_out;
325
+ }
326
+ }
327
+ }
184
328
  };
185
329
 
186
330
  /*──────── binding: filter(image, filterType, kernelSize, intensity, [outputFormat], [quality], [pngOptimize], callback) ─*/
@@ -0,0 +1,146 @@
1
+ #include <napi.h>
2
+ #include <opencv2/opencv.hpp>
3
+ #include "utils.h"
4
+
5
+ class HeatDiffWorker final : public Napi::AsyncWorker {
6
+ public:
7
+ HeatDiffWorker(Napi::Function cb,
8
+ const Napi::Value& jsImg1,
9
+ const Napi::Value& jsImg2,
10
+ int colormapType,
11
+ int blurSize,
12
+ int threshold,
13
+ std::string outputFormat,
14
+ int quality = 90,
15
+ bool pngOptimize = false)
16
+ : Napi::AsyncWorker(cb),
17
+ colormapType(colormapType),
18
+ blurSize(blurSize),
19
+ threshold(threshold),
20
+ outputFormat(std::move(outputFormat)),
21
+ quality(quality),
22
+ pngOptimize(pngOptimize)
23
+ {
24
+ const int64 t0 = cv::getTickCount();
25
+ mat1 = ConvertToMat(jsImg1);
26
+ mat2 = ConvertToMat(jsImg2);
27
+ format1 = DetectChannelFormatShared(jsImg1, mat1);
28
+ format2 = DetectChannelFormatShared(jsImg2, mat2);
29
+ convertMs = (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
30
+ }
31
+
32
+ protected:
33
+ void Execute() override {
34
+ const int64 t0 = cv::getTickCount();
35
+
36
+ // Convert both to grayscale for diff computation
37
+ cv::Mat gray1, gray2;
38
+
39
+ if (mat1.channels() == 1) {
40
+ gray1 = mat1;
41
+ } else if (format1 == "BGR" || format1 == "BGRA") {
42
+ cv::cvtColor(mat1, gray1, mat1.channels() == 4 ? cv::COLOR_BGRA2GRAY : cv::COLOR_BGR2GRAY);
43
+ } else {
44
+ cv::cvtColor(mat1, gray1, mat1.channels() == 4 ? cv::COLOR_RGBA2GRAY : cv::COLOR_RGB2GRAY);
45
+ }
46
+
47
+ if (mat2.channels() == 1) {
48
+ gray2 = mat2;
49
+ } else if (format2 == "BGR" || format2 == "BGRA") {
50
+ cv::cvtColor(mat2, gray2, mat2.channels() == 4 ? cv::COLOR_BGRA2GRAY : cv::COLOR_BGR2GRAY);
51
+ } else {
52
+ cv::cvtColor(mat2, gray2, mat2.channels() == 4 ? cv::COLOR_RGBA2GRAY : cv::COLOR_RGB2GRAY);
53
+ }
54
+
55
+ // Resize if dimensions differ
56
+ if (gray1.size() != gray2.size()) {
57
+ cv::Size targetSize(std::max(gray1.cols, gray2.cols),
58
+ std::max(gray1.rows, gray2.rows));
59
+ if (gray1.size() != targetSize) cv::resize(gray1, gray1, targetSize);
60
+ if (gray2.size() != targetSize) cv::resize(gray2, gray2, targetSize);
61
+ }
62
+
63
+ // Absolute difference
64
+ cv::Mat diff;
65
+ cv::absdiff(gray1, gray2, diff);
66
+
67
+ // Optional Gaussian blur to smooth noise
68
+ if (blurSize > 0) {
69
+ int ksize = blurSize | 1; // ensure odd
70
+ cv::GaussianBlur(diff, diff, cv::Size(ksize, ksize), 0);
71
+ }
72
+
73
+ // Optional threshold to suppress small differences
74
+ if (threshold > 0) {
75
+ cv::threshold(diff, diff, threshold, 0, cv::THRESH_TOZERO);
76
+ }
77
+
78
+ // Apply colormap
79
+ cv::applyColorMap(diff, result, colormapType);
80
+ // applyColorMap outputs BGR
81
+ outputChannel = "BGR";
82
+
83
+ taskMs = (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
84
+
85
+ if (outputFormat != "raw") {
86
+ cv::Mat tmp = PrepareForEncoding(result, outputChannel, outputFormat);
87
+ encodeMs = EncodeToFormat(tmp, encodedBuf, outputFormat, quality, pngOptimize);
88
+ }
89
+ }
90
+
91
+ void OnOK() override {
92
+ Napi::Env env = Env();
93
+ Napi::Value jsImg = (outputFormat != "raw")
94
+ ? VectorToBuffer(env, std::move(encodedBuf))
95
+ : MatToRawJS(env, result, outputChannel);
96
+
97
+ Napi::Object out = Napi::Object::New(env);
98
+ out.Set("image", jsImg);
99
+ out.Set("timing", MakeTimingJS(env, convertMs, taskMs, encodeMs));
100
+ Callback().Call({env.Null(), out});
101
+ }
102
+
103
+ private:
104
+ cv::Mat mat1, mat2, result;
105
+ std::string format1, format2, outputChannel;
106
+ int colormapType;
107
+ int blurSize;
108
+ int threshold;
109
+ std::string outputFormat;
110
+ int quality;
111
+ bool pngOptimize;
112
+ double convertMs = 0, taskMs = 0, encodeMs = 0;
113
+ std::vector<uchar> encodedBuf;
114
+ };
115
+
116
+ Napi::Value HeatDiff(const Napi::CallbackInfo& info) {
117
+ Napi::Env env = info.Env();
118
+
119
+ if (info.Length() < 3 || !info[info.Length() - 1].IsFunction()) {
120
+ Napi::TypeError::New(env,
121
+ "heatDiff(image1, image2, colormapType, [blurSize], [threshold], [outputFormat], [quality], [pngOptimize], callback)")
122
+ .ThrowAsJavaScriptException();
123
+ return env.Null();
124
+ }
125
+
126
+ Napi::Value jsImg1 = info[0];
127
+ Napi::Value jsImg2 = info[1];
128
+ int colormapType = info[2].As<Napi::Number>().Int32Value();
129
+
130
+ int blurSize = 0;
131
+ int threshold = 0;
132
+ std::string outputFormat = "raw";
133
+ int quality = 90;
134
+ bool pngOptimize = false;
135
+ size_t cbIdx = 3;
136
+
137
+ if (info.Length() >= 5) { blurSize = info[3].As<Napi::Number>().Int32Value(); cbIdx = 4; }
138
+ if (info.Length() >= 6) { threshold = info[4].As<Napi::Number>().Int32Value(); cbIdx = 5; }
139
+ if (info.Length() >= 7) { outputFormat = info[5].As<Napi::String>().Utf8Value(); cbIdx = 6; }
140
+ if (info.Length() >= 8) { quality = info[6].As<Napi::Number>().Int32Value(); cbIdx = 7; }
141
+ if (info.Length() >= 9) { pngOptimize = info[7].As<Napi::Boolean>().Value(); cbIdx = 8; }
142
+
143
+ (new HeatDiffWorker(info[cbIdx].As<Napi::Function>(),
144
+ jsImg1, jsImg2, colormapType, blurSize, threshold, outputFormat, quality, pngOptimize))->Queue();
145
+ return env.Undefined();
146
+ }