Skip to content

Image Processing Toolkit for Node-RED ​

@rosepetal/node-red-contrib-image-tools provides 20 nodes for Node-RED that load, transform, compose, annotate, compare and save images. The image operations run in a native C++ addon built on OpenCV; loading and saving also use sharp.

A Node-RED flow of image nodes, each showing its processing time in its status

Installation ​

bash
cd ~/.node-red
npm install @rosepetal/node-red-contrib-image-tools

Or search @rosepetal/node-red-contrib-image-tools in the Node-RED Palette Manager.

npm fetches a prebuilt native addon, with OpenCV statically linked, for linux-x64 and linux-arm64 (glibc), linuxmusl-x64 (Alpine) and darwin-arm64. On any other platform the addon has to be built from source: see Building from source.

Requirements ​

  • Node.js 18.17 or later (the sharp dependency supports ^18.17.0 || ^20.3.0 || >=21.0.0)
  • Node-RED >= 1.0.0
  • One of the platforms above, or the tools to build the addon: OpenCV 4.x, a C++17 compiler and node-gyp

Nodes ​

All node types are prefixed with rp- and appear under the RP Image category in the editor. Flows saved with the earlier type names, without the prefix (resize, crop and so on), keep working: the published package also registers those names, hidden from the palette (every node except rp-heat-diff, which never had another name).

I/O ​

NodePurpose
rp-image-inLoad an image file from disk into the raw image object that the other nodes use
rp-folder-inEmit the image files of a folder one by one at a set interval, in a loop or once, started and stopped with the node's button
rp-image-outSave images to disk as JPEG, PNG, WebP or BMP, one per message or many from an array, with timestamped file names, overwrite protection, a file limit and a disk limit

Transform ​

NodePurpose
rp-resizeScale images to a fixed size or by a factor, keeping the aspect ratio when one dimension is left empty
rp-rotateRotate images by an angle in degrees and fill the uncovered area with a pad color
rp-cropExtract a rectangular region, with normalized (0-1) or pixel coordinates
rp-paddingAdd a margin of a solid color on each side
rp-filterApply blur, sharpening, edge detection, emboss, Gaussian blur, Otsu threshold, histogram equalization or CLAHE
rp-drawOverlay points and line segments, with normalized coordinates, color and opacity
rp-color-convertConvert images between the GRAY, RGB, RGBA, BGR and BGRA color spaces

Mix ​

NodePurpose
rp-concatJoin an array of images into one, to the right, left, down or up, padding or resizing the ones that differ in size
rp-mosaicPlace the images of an array on a canvas at the positions set in the node, in pixels or normalized coordinates
rp-advanced-mosaicCompose the images of an array on a canvas with a position, size, rotation and stacking order per image, set in a visual editor

Blend ​

NodePurpose
rp-blendBlend two images with an adjustable opacity, with optional alpha compositing and background color removal
rp-add-maskBlend a polygon mask over an image, from normalized polygon coordinates, with a fill color and a strength
rp-add-masksBlend several polygon or bitmap masks over an image, with a color per class
rp-add-bbsDraw bounding boxes on an image, labelled with their tag and confidence, with a color per tag

Specialized ​

NodePurpose
rp-cropBBExtract one crop per bounding box of an inference result, filtered by a minimum confidence
rp-image-alignAlign a target image to a reference image with ECC, with ORB or SIFT features, or with features refined by ECC
rp-heat-diffCompute the per-pixel absolute difference of two images as a color-mapped heat image, with optional difference statistics

Quick start ​

[inject] → [rp-image-in] → [rp-resize] → [rp-image-out]
  1. In rp-image-in, set File Path to an image file on the Node-RED host. Any incoming message makes the node load the file into msg.payload.
  2. In rp-resize, set Width and leave Height empty to keep the aspect ratio.
  3. In rp-image-out, set Folder Path. With the default settings the image is saved there as image_<timestamp>.jpg.

Image format ​

The nodes pass raw images between them as objects:

javascript
{
  data: Buffer,        // Raw pixel data
  width: number,       // Image width in pixels
  height: number,      // Image height in pixels
  channels: number,    // Channel count (1, 3, 4)
  colorSpace: string,  // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
  dtype: string        // "uint8"
}

rp-image-in and rp-folder-in produce this object, with colorSpace GRAY, RGB or RGBA. A raw image without colorSpace is read as GRAY, RGB or RGBA from its channel count; a colorSpace that does not match the channel count is rejected. The transform, mix, blend and specialized nodes (except rp-cropBB) also accept an encoded JPEG, PNG, WebP or BMP Buffer in its place and decode it in the addon (as RGB, RGBA or GRAY); rp-image-out accepts JPEG, PNG and WebP buffers.

Common settings ​

The transform, mix, blend and specialized nodes share these settings:

  • Input from / Output to: where the image is read and where the result is written, as a msg property or a flow / global context key. The result goes to msg.payload by default. The nodes that read two inputs or extra data (rp-blend, rp-add-mask, rp-add-masks, rp-add-bbs, rp-cropBB, rp-image-align and rp-heat-diff) read and write msg properties only (except Stats to of rp-heat-diff), although their editor also offers flow and global.
  • Output Format: raw (the image object, the default) or an encoded Buffer in jpg, png or webp. Quality (1-100, default 90) applies to JPEG and WebP; PNG Optimize sets PNG compression level 6 instead of 0; the WebP options Lossless, Smart Subsample and Effort (0-6) make sharp encode the WebP instead of OpenCV. JPEG drops the alpha channel.
  • Debug: shows a preview of the result in the editor, with a configurable width (200 pixels by default).
  • Inference (rp-resize, rp-rotate, rp-crop, rp-padding, rp-concat, rp-mosaic and rp-advanced-mosaic, under Advanced options): when checked, the detections and segmentations read from msg.inference (by default) get the same geometric change as the image and are written back, so that their coordinates match the output image (for rp-advanced-mosaic, not for every rotated or one-side-resized placement: see its page). Detections are objects with raw_boxes (four normalized corner points) and segmentations objects with polygons (normalized points); other entries pass unchanged. For the nodes that combine several images, msg.inference holds one such array per input image and the result is a single array.

rp-resize, rp-rotate, rp-crop, rp-padding, rp-filter and rp-color-convert take one image or an array of images, and process the images of an array in parallel. rp-image-align and rp-heat-diff take two images or two arrays of the same length, paired by index.

Timing and errors ​

The transform, mix, blend and specialized nodes, and rp-folder-in, record their processing time in msg.performance.rpimage.<key> as { conversion, task, total }, in milliseconds. <key> is the name of the node, or its type when it has no name, in lower case and with every run of other characters replaced by _ (rp_resize).

When the processing fails, the transform, mix, blend and specialized nodes do not stop the flow: they set msg.error (message, operation, hint, details, timestamp, nodeId, nodeName, nodeType, and validationError: true when the input was rejected), log a warning, show a red Error: ... status and still send the message. The I/O nodes behave differently: see their pages.

Performance ​

  • Decoding, processing and encoding run on the libuv thread pool, not on the Node-RED event loop; the JavaScript layer only validates and routes messages.
  • The pool has 4 threads by default and is shared with sharp and file I/O. Under heavy concurrency, raise it before starting Node-RED: UV_THREADPOOL_SIZE=8 node-red.
  • Keep the raw output format between the nodes of a chain and encode only at the end.

Building from source ​

For contributors, and for platforms without a prebuilt addon:

bash
git clone https://github.com/rosepetal-ai/node-red-contrib-image-tools.git
cd node-red-contrib-image-tools
./install.sh

The script installs the build tools and OpenCV with the system's package manager (apt, dnf, yum, pacman or Homebrew) when pkg-config does not find OpenCV 4, builds the C++ addon, and offers to install the package into ~/.node-red.

Several examples in these pages collect images into an array with Array-In and Array-Out nodes. They are rp-array-in and rp-array-out, which moved from this package to @rosepetal/node-red-contrib-utils.

License ​

Apache-2.0. The package is published on npm as @rosepetal/node-red-contrib-image-tools.