@rosepetal/node-red-contrib-image-tools 1.7.0 → 1.8.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.
Files changed (35) hide show
  1. package/.github/workflows/build-prebuild.yml +1 -1
  2. package/README.md +39 -21
  3. package/docs/index.md +156 -0
  4. package/docs/nodes/blend/add-bbs.md +116 -0
  5. package/docs/nodes/blend/add-mask.md +67 -224
  6. package/docs/nodes/blend/add-masks.md +74 -196
  7. package/docs/nodes/blend/blend.md +84 -200
  8. package/docs/nodes/io/folder-in.md +92 -0
  9. package/docs/nodes/io/image-in.md +61 -52
  10. package/docs/nodes/io/image-out.md +114 -93
  11. package/docs/nodes/mix/advanced-mosaic.md +124 -78
  12. package/docs/nodes/mix/concat.md +71 -56
  13. package/docs/nodes/mix/mosaic.md +81 -91
  14. package/docs/nodes/specialized/cropBB.md +76 -214
  15. package/docs/nodes/specialized/heat-diff.md +111 -0
  16. package/docs/nodes/specialized/image-align.md +125 -387
  17. package/docs/nodes/transform/color-convert.md +101 -0
  18. package/docs/nodes/transform/crop.md +56 -58
  19. package/docs/nodes/transform/draw.md +46 -26
  20. package/docs/nodes/transform/filter.md +110 -46
  21. package/docs/nodes/transform/padding.md +55 -55
  22. package/docs/nodes/transform/resize.md +81 -56
  23. package/docs/nodes/transform/rotate.md +67 -50
  24. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +11 -4
  25. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +2 -1
  26. package/npm/darwin-arm64/package.json +1 -1
  27. package/npm/darwin-x64/package.json +1 -1
  28. package/npm/linux-arm64/package.json +1 -1
  29. package/npm/linux-x64/package.json +1 -1
  30. package/npm/linuxmusl-x64/package.json +1 -1
  31. package/npm/win32-x64/package.json +1 -1
  32. package/package.json +6 -6
  33. package/rosepetal-image-engine/src/heat-diff.cpp +4 -0
  34. package/rosepetal-image-engine/src/image-align.cpp +71 -3
  35. package/scripts/build-opencv-static.sh +6 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-arm64",
3
- "version": "1.7.0",
3
+ "version": "1.8.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.7.0",
3
+ "version": "1.8.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.7.0",
3
+ "version": "1.8.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.7.0",
3
+ "version": "1.8.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.7.0",
3
+ "version": "1.8.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.7.0",
3
+ "version": "1.8.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.7.0",
3
+ "version": "1.8.1",
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.7.0",
40
- "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.7.0",
41
- "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.7.0",
42
- "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.7.0",
43
- "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.7.0"
39
+ "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.8.1",
40
+ "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.8.1",
41
+ "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.8.1",
42
+ "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.8.1",
43
+ "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.8.1"
44
44
  },
45
45
  "node-red": {
46
46
  "version": ">=1.0.0",
@@ -109,6 +109,10 @@ protected:
109
109
  cv::Mat diff;
110
110
  cv::absdiff(gray1, gray2, diff);
111
111
 
112
+ // Pure black in either input is alignment border / padding (the stats below ignore it).
113
+ // Zero it BEFORE the blur too, or its huge diff bleeds ~ksize/2 px into the valid area.
114
+ diff.setTo(0, (gray1 == 0) | (gray2 == 0));
115
+
112
116
  // Optional Gaussian blur to smooth noise
113
117
  if (blurSize > 0) {
114
118
  int ksize = blurSize | 1; // ensure odd
@@ -158,14 +158,43 @@ static int ParseMotionModel(const std::string& name) {
158
158
  // ECC - intensity-based ECC only, identity init (legacy default)
159
159
  // FEATURES - ORB+RANSAC only, no ECC refinement
160
160
  // FEATURES_ECC - ORB seed -> ECC refinement (best accuracy, recommended for new nodes)
161
- enum class AlignPipeline { ECC, FEATURES, FEATURES_ECC };
161
+ // SHIFT - exhaustive translation search (template matching); always a pure
162
+ // translation, for low-texture or line-scan images where features fail
163
+ enum class AlignPipeline { ECC, FEATURES, FEATURES_ECC, SHIFT };
162
164
 
163
165
  static AlignPipeline ParsePipeline(const std::string& name) {
164
166
  if (name == "ecc") return AlignPipeline::ECC;
165
167
  if (name == "features") return AlignPipeline::FEATURES;
166
168
  if (name == "features+ecc") return AlignPipeline::FEATURES_ECC;
169
+ if (name == "shift") return AlignPipeline::SHIFT;
167
170
  throw std::runtime_error("Unknown pipeline: " + name +
168
- " (expected: ecc, features, or features+ecc)");
171
+ " (expected: ecc, features, features+ecc, or shift)");
172
+ }
173
+
174
+ // Shift search tuning. The window is a fraction of the image (or a floor in full-res px,
175
+ // whichever is larger), capped at a quarter so the template keeps half of each axis.
176
+ constexpr double kShiftRangeY = 0.10, kShiftRangeX = 0.04;
177
+ constexpr double kShiftFloorY = 150.0, kShiftFloorX = 60.0;
178
+ constexpr double kShiftMinScore = 0.15; // normalized correlation below this = no match
179
+
180
+ // Zero-mean, high-passed copy for the shift search. Removes the per-column gain (line-scan
181
+ // cameras: identical in both images, so it pulls any correlation toward zero shift), the
182
+ // per-line brightness (lamp flicker, different in every capture) and slow shading.
183
+ static cv::Mat FlattenForShift(const cv::Mat& gray, double sigma) {
184
+ cv::Mat f, colMean, rowMean, low;
185
+ gray.convertTo(f, CV_32F);
186
+ cv::reduce(f, colMean, 0, cv::REDUCE_AVG);
187
+ f -= cv::repeat(colMean, f.rows, 1);
188
+ cv::reduce(f, rowMean, 1, cv::REDUCE_AVG);
189
+ f -= cv::repeat(rowMean, 1, f.cols);
190
+ cv::GaussianBlur(f, low, cv::Size(0, 0), sigma);
191
+ return f - low;
192
+ }
193
+
194
+ // Sub-pixel offset of a peak from its two neighbours (parabola through three samples).
195
+ static double ParabolicPeak(float left, float centre, float right) {
196
+ const float d = left - 2.0f * centre + right;
197
+ return std::abs(d) > 1e-12f ? 0.5 * (left - right) / d : 0.0;
169
198
  }
170
199
 
171
200
  // ECC refinement policy (only meaningful when pipeline == FEATURES_ECC):
@@ -243,8 +272,13 @@ public:
243
272
  motionFlag = ParseMotionModel(motionModelName);
244
273
  useHomography = (motionFlag == cv::MOTION_HOMOGRAPHY);
245
274
 
246
- // Same for pipeline mode (ecc / features / features+ecc).
275
+ // Same for pipeline mode (ecc / features / features+ecc / shift).
247
276
  pipelineMode = ParsePipeline(pipelineName);
277
+ // The shift search only ever returns a translation, whatever the motion model says
278
+ if (pipelineMode == AlignPipeline::SHIFT) {
279
+ motionFlag = cv::MOTION_TRANSLATION;
280
+ useHomography = false;
281
+ }
248
282
 
249
283
  // And the ECC refinement policy (always / auto / never).
250
284
  eccRefineMode = ParseEccRefine(eccRefineName);
@@ -849,7 +883,38 @@ private:
849
883
  }
850
884
  }
851
885
 
886
+ // Exhaustive translation search on the small frames: the centre of the target slides
887
+ // over the reference within the shift window (matchTemplate, normalized correlation),
888
+ // then a parabolic sub-pixel step. Fails (no matrix) on a weak peak or a peak on the
889
+ // window edge, where the true shift may lie outside: invalid beats a wrong warp.
890
+ bool FindShift(const cv::Mat& refSmall, const cv::Mat& targetSmall, cv::Mat& transformMatrix) const {
891
+ const cv::Mat ref = FlattenForShift(refSmall, std::max(2.0, 16.0 * scale));
892
+ const cv::Mat tgt = FlattenForShift(targetSmall, std::max(2.0, 16.0 * scale));
893
+ const int W = std::min(ref.cols, tgt.cols), H = std::min(ref.rows, tgt.rows);
894
+ const int sx = std::min(W / 4, static_cast<int>(std::ceil(std::max(kShiftRangeX * W, kShiftFloorX * scale))));
895
+ const int sy = std::min(H / 4, static_cast<int>(std::ceil(std::max(kShiftRangeY * H, kShiftFloorY * scale))));
896
+ if (W - 2 * sx < 16 || H - 2 * sy < 16) return false;
897
+
898
+ cv::Mat res;
899
+ cv::matchTemplate(ref(cv::Rect(0, 0, W, H)), tgt(cv::Rect(sx, sy, W - 2 * sx, H - 2 * sy)),
900
+ res, cv::TM_CCOEFF_NORMED);
901
+ double best = 0.0;
902
+ cv::Point p;
903
+ cv::minMaxLoc(res, nullptr, &best, nullptr, &p);
904
+ if (!std::isfinite(best) || best < kShiftMinScore) return false;
905
+ if (p.x == 0 || p.y == 0 || p.x == res.cols - 1 || p.y == res.rows - 1) return false;
906
+
907
+ const double fx = p.x + ParabolicPeak(res.at<float>(p.y, p.x - 1), res.at<float>(p.y, p.x), res.at<float>(p.y, p.x + 1));
908
+ const double fy = p.y + ParabolicPeak(res.at<float>(p.y - 1, p.x), res.at<float>(p.y, p.x), res.at<float>(p.y + 1, p.x));
909
+ // target (x, y) lies on reference (x + dx, y + dy); the warp matrix maps reference -> target
910
+ const double dx = (fx - sx) / scale, dy = (fy - sy) / scale;
911
+ transformMatrix = (cv::Mat_<float>(2, 3) << 1.0f, 0.0f, static_cast<float>(-dx),
912
+ 0.0f, 1.0f, static_cast<float>(-dy));
913
+ return true;
914
+ }
915
+
852
916
  // Find transformation matrix - dispatches on the configured pipeline:
917
+ // SHIFT -> FindShift (exhaustive translation search, no ECC)
853
918
  // ECC -> identity init -> findTransformECC (legacy path)
854
919
  // FEATURES -> ORB+RANSAC seed only, no ECC
855
920
  // FEATURES_ECC -> ORB seed -> findTransformECC refinement.
@@ -893,6 +958,9 @@ private:
893
958
  resizeOrCached(refGray, refSmall);
894
959
  resizeOrCached(targetGray, targetSmall);
895
960
 
961
+ if (pipelineMode == AlignPipeline::SHIFT)
962
+ return FindShift(refSmall, targetSmall, transformMatrix);
963
+
896
964
  // -------- Stage 1: optional ORB feature seed -----------------
897
965
  cv::Mat seedMatrix; // small-frame coords
898
966
  int seedInliers = 0;
@@ -41,9 +41,14 @@ echo "Configuring OpenCV..."
41
41
 
42
42
  # Detect platform for platform-specific flags
43
43
  PLATFORM_FLAGS=""
44
+ C_FLAGS=""
44
45
  if [[ "$OSTYPE" == "darwin"* ]]; then
45
46
  # macOS specific settings
46
47
  PLATFORM_FLAGS="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15"
48
+ # The Xcode 16 SDK defines TARGET_OS_MAC, which the bundled zlib 1.2.13 and libpng 1.6.37 read as
49
+ # classic Mac OS: zlib turns fdopen() into NULL (clashes with stdio.h) and libpng includes <fp.h>.
50
+ # Defining fdopen keeps zlib's macro out; math.h first sets the guard that skips <fp.h>.
51
+ C_FLAGS="-Dfdopen=fdopen -include math.h"
47
52
 
48
53
  # For Apple Silicon cross-compilation support
49
54
  if [[ "$(uname -m)" == "arm64" ]]; then
@@ -63,6 +68,7 @@ fi
63
68
 
64
69
  cmake .. \
65
70
  -DCMAKE_BUILD_TYPE=Release \
71
+ ${C_FLAGS:+"-DCMAKE_C_FLAGS=${C_FLAGS}"} \
66
72
  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
67
73
  \
68
74
  -DBUILD_SHARED_LIBS=OFF \