Nodes/ComfyUI-StableXWrapper/Extract Difference
ComfyUI Node

Extract Difference

Extract Difference — the little node that turns a de-lit image into a light map

By kijai·Created 2 years ago·Updated 2 years ago· 69
Extract Difference
  • original_image
  • processed_image
  • IMAGE
amplification1.00

Every once in a while a pack ships a node that seems like an afterthought and turns out to be the point. This is that node. On the surface it's a plain image math utility: take two images, subtract one from the other, amplify, output the difference. But the example workflow uses it in a way that makes the whole StableXWrapper pack click.

Here's the setup: load a photo once, run StableX Process Image with the delight model on it, and you get the same scene with glare, specular highlights and reflections scrubbed out. Then wire the original into original_image, the de-lit result into processed_image, and this node draws exactly what the model removed. Bright pixels = where the original was brighter = the specular and lighting component. You've just turned a "remove the reflection" model into a "give me the reflection map" tool, which is genuinely useful for compositing, relighting, and matte work.

How it works

It's pure PyTorch, no models, no GPU pressure beyond the two tensors you hand it. Each image is converted from RGB to a single luminosity channel using the classic Rec. 709 weights (0.2126 red, 0.7152 green, 0.0722 blue), because that's how you weight luminance the way a human eye does. Then it computes (original - processed) × amplification, clamps to 0–1, and replicates the one channel back out to RGB so it's a normal image again.

Worth knowing: the subtraction only goes one way. Because of the clamp, only pixels where the original is brighter than the processed image survive - highlights stick around, shadows don't. If you flip the inputs you get the opposite side of the coin. And amplification (default 1.0, range 0.1–10) is your contrast knob: crank it to 2–3 when the difference is subtle and you want the map to pop, keep it at 1 when you're after a faithful mask.

Inputs and output

  • original_image - the before.
  • processed_image - the after.
  • amplification - multiplies the difference; higher = higher-contrast map.
  • Output: one IMAGE, the grayscale-ish difference map. Wire it to Preview Image to eyeball it, or into a mask, blend, or inpaint node downstream.

The catch

It expects the two images to be the same resolution - the delight node upscales internally but returns your original resolution, so in the intended workflow this works out automatically. Feed it mismatched sizes and you'll get a tensor shape error. That's about it for failure modes; there's no state, no model download, nothing to configure beyond those three inputs. It lives in its own iStableXWrapper category rather than the main StableXWrapper one, which is a hint it was bolted on after the fact - but it's in the same file, ships with the pack, and it's the piece that makes the example workflow more than two preview windows.

CategoryiStableXWrapper

Inputs (3)

NameTypeDefaultDescription
original_imageIMAGE
processed_imageIMAGE
amplificationFLOAT1.000.1–10

Outputs (1)

NameTypeDescription
IMAGEIMAGE