Heat-Diff Node
Type:
rp-heat-diff· Category: Specialized · Since: v1.5.1
Overview
Heat-Diff compares two images pixel by pixel: it takes the absolute difference of their grayscale versions, optionally blurs it and suppresses small values, and returns it as a heat map in a chosen colormap. It can also measure the difference (mean, maximum, percentiles, RMSE, PSNR, SSIM, share of changed pixels and the changed regions), with or without the heat image.
Use cases
- Compare each product image with a golden image and see where they differ
- Decide pass or fail from
changedRatio,maxDiffor the largest changed region, without rendering an image - Check the result of image-align before comparing
Inputs
Only msg properties are read for the images: the editor also offers flow and global, but the node reads the typed text as a msg path.
- Image 1 (
msg.payloadby default) and Image 2 (msg.goldenImageby default): raw image objects or encoded JPEG/PNG/WebP/BMPBuffers, in any color space. Both may also be arrays of the same length: the images are then paired by index, compared in parallel, and the outputs become arrays in the same order. - Images of different sizes are both scaled (without keeping the aspect ratio) to the largest width and height of the two.
Outputs
One output.
- Output (
msg.payloadby default; amsgproperty): the heat image, a 3-channel image (colorSpaceBGRin raw form) of the compared size, or an encodedBuffer. With Heat Image off, Output is left untouched. - Stats to (
msg.diffStatsby default;msg,floworglobal), with Statistics on:
{
validRatio: 0.98, // share of pixels compared (see below)
changedRatio: 0.012, // share of compared pixels whose difference is above Threshold
meanDiff: 3.4, // mean difference, 0-255
maxDiff: 187, // largest difference
p50: 2, p95: 11, p99: 40, // difference percentiles
rmse: 6.1,
psnr: 32.4, // dB; 100 when the images are identical
ssim: 0.97, // null when SSIM is off
threshold: 25,
blobCount: 3, // connected regions of changed pixels
largestBlobArea: 412, // pixels
blobs: [ { x, y, w, h, area, cx, cy }, ... ] // up to 50 regions, largest first, in pixels
}Pixels that are pure black (0) in either grayscale image are left out of every statistic: they are usually the borders of an alignment or the padding of a composite. validRatio is the share of pixels that remain. The statistics are computed on the difference after Blur and Threshold, except SSIM, which compares the two grayscale images.
msg.performance.rpimage.<key>:{ conversion, task, total }in milliseconds.- On failure:
msg.error(message,operation,hint,details,timestamp,nodeId,nodeName,nodeType), with Image 1 written to Output; the message is still sent.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
| Name | string | empty | Label of the node; also the key of its timings in msg.performance.rpimage |
| Image 1 | msg path | msg.payload | First image (for example the capture) |
| Image 2 | msg path | msg.goldenImage | Second image (for example the golden image) |
| Heat Image | boolean | on | Render the heat map (off = statistics only). Off also turns Statistics on |
| Output | msg path | msg.payload | Where the heat image is written |
| Output Format | enum | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP, with Quality (90), PNG Optimize and the WebP options as in resize |
| Statistics | boolean | on | Compute diff statistics |
| Stats to | TypedInput (msg/flow/global) | msg.diffStats | Where the statistics are written |
| SSIM | boolean | on | Compute SSIM (dominates the stats cost): structural similarity with an 11 × 11 Gaussian window |
| Debug / Debug Width | boolean / number | off / 200 | Show processed image under the node in the editor |
| Colormap | enum | Jet | Jet, Hot, Inferno, Turbo, Bone, Cool, Rainbow, Ocean, Pink or HSV (the OpenCV colormaps of those names) |
| Blur | number | 0 | Gaussian blur of the difference: kernel size, made odd; 0 = off. Number, or read from msg, flow or global |
| Threshold | number | 0 | 0-255: differences at or below it are set to 0, and only larger ones count as changed. Number, or read from msg, flow or global |
The status shows a green dot OK: <n> img in <t> ms (conv <c> ms | task <k> ms), where <n> is the number of pairs, and a red ring Error: <first 30 characters> after a failure. Failures include image1 and image2 must both be single images or both be arrays, Image arrays must be non-empty and of equal length (got <a> and <b>), First image input is invalid or missing and Second image input is invalid or missing.
Examples
[camera] → [rp-image-align: reference golden] → [Change: msg.goldenImage = golden] → [rp-heat-diff: Threshold 25, Blur 5] → [rp-image-out]Aligns each capture with the golden image, then saves a heat map of what changed; small differences from noise are suppressed.
[camera] → [rp-heat-diff: Heat Image off, SSIM off, Threshold 30] → [Switch: msg.diffStats.largestBlobArea > 200] → [reject]Statistics only: rejects a part when a changed region larger than 200 pixels appears.
Troubleshooting
- The whole heat map is bright — Cause: the images are not aligned, or differ in exposure. · Solution: align them first with image-align; raise Threshold.
validRatiois low — Cause: large black areas (alignment borders, padding, dark backgrounds) are left out of the statistics. · Solution: expected for black borders; for dark scenes, keep in mind that pixels of value 0 are never compared.changedRatiocounts noise — Cause: Threshold is 0, so any difference counts. · Solution: set Threshold, or Blur, to ignore small differences.- Statistics are slow — Cause: SSIM costs more than all other statistics. · Solution: turn SSIM off when it is not used.
Second image input is invalid or missing— Cause: Image 2 is not atmsg.goldenImage. · Solution: point Image 2 at themsgproperty that holds the golden image.
See Also
- image-align: align the two images before comparing them
- blend: overlay the heat map on the original image
- cropBB: cut out regions for closer inspection