Nodes/Duanyll Nodepack/Image Difference with Colormap
ComfyUI Node

Image Difference with Colormap

See exactly where two images differ — as a heatmap, not a number

By Duanyll·Created about a year ago·Updated 4 months ago· 2
Image Difference with Colormap
  • image1
  • image2
  • difference
cmapviridis

A single number like "MSE 0.003" tells you that two images differ, but not where. Image Difference with Colormap turns the difference into an image you can actually look at - a heatmap where bright spots show exactly which pixels changed and how much. It's the kind of node you reach for when you're debugging img2img drift, checking whether an upscaler actually preserved detail, or A/B-testing two generations of the same prompt.

How it works

The math is honest and simple. It takes both images in ComfyUI's standard [B, H, W, C] float format, subtracts them pixel-by-pixel to get a difference in [-1, 1] per channel, then collapses the channels into a single magnitude using the L2 (Euclidean) norm per pixel. That magnitude gets normalized to [0, 1] and run through a Matplotlib colormap to produce a colored RGB image.

What that means in practice: a pixel where the two images agree comes out dark; a pixel where they diverge a lot comes out bright. Because it's a magnitude, it doesn't care about the direction of the change - a pixel that went from black to white and one that went white to black both light up the same. If you need to know direction, this isn't the node; for "where and how much," it's exactly right.

One requirement you can't skip: both inputs must be the same shape. The code checks and if they don't match it prints an error and returns image1 unchanged rather than crashing - which is friendly, but also easy to miss if you're not watching the console. Resize or pad your pair into the same dimensions first.

The inputs that matter

  • image1, image2 - the two images to compare.
  • cmap - one of 18 Matplotlib colormaps, default viridis. The useful families: perceptually-uniform maps (viridis, plasma, inferno, magma, cividis) read well for "how big is the difference" and don't trick the eye; diverging maps (bwr, coolwarm, seismic) are only really useful if you had signed values, which this node normalizes away; jet and hot look flashy but hide detail. viridis is the boring right answer.

Output is a single difference IMAGE. Wire it to a Preview Image or Save node and look at it.

Installing it

It ships in Duanyll Nodepack. ComfyUI Manager: search "Duanyll Nodepack" and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/duanyll_nodepack

Restart ComfyUI and you'll find it under duanyll/image. The pack needs matplotlib for this node, and it's in the pack's requirements - ComfyUI Manager installs those for you on first load.

A small tip from someone who's stared at too many diff maps: the colormap normalizes against the maximum difference in this particular pair, so the scale is relative, not absolute. A pair of nearly-identical images will still show a bright spot at their one point of difference. That's great for spotting where, but don't read absolute intensity as absolute change. Pair it with the pack's Image Diff Metrics if you also want the actual numbers.

Categoryduanyll/image

Inputs (3)

NameTypeDefaultDescription
image1IMAGE
image2IMAGE
cmapCOMBOviridis18 options: viridis, plasma, inferno, magma, cividis, jet, +12

Outputs (1)

NameTypeDescription
differenceIMAGE