ComfyUI Node

Histogram Match

The color-anchoring utility the SD-CN nodes run silently, now in your hands

By pxl-pshr·Created 5 months ago·Updated 5 months ago· 13
Histogram Match
  • source
  • reference
  • matched

Histogram Match is the one node in the ComfyUI-SD-CN-Animation pack that isn't about optical flow at all - it's the color-correction step the Txt2Vid and Vid2Vid nodes run on every frame under the hood, pulled out as a standalone utility. If you've ever generated a frame sequence and watched the white balance wander into a different color temperature every few frames, this is the fix, and now you can apply it to anything, not just SD-CN pipelines.

How it works

It takes two image batches - source and reference - and reshapes the source's color distribution to match the reference's. The important implementation detail is that it does this in LAB color space, not RGB. RGB matching adjusts each channel independently, which can't fix hue shifts (the pack's own code comments give the classic example: a green skull stays green after naive RGB matching). LAB separates lightness from the color-opponent channels, so matching there preserves hue relationships while aligning the overall look. It's built on scikit-image's match_histograms plus OpenCV's LAB conversion.

One practical detail worth knowing: the reference batch uses only its first frame (frame 0) as the target. So if you feed a whole video as the reference, only the first frame matters - matching a sequence to a single anchor frame is exactly how the parent nodes stop color drift over time.

Wiring it

  • source - the images you want recolored.
  • reference - the image (or sequence whose frame 0) defines the target palette.
  • Output matched - the source, recolored.

A typical standalone use: generate a clip with AnimateDiff or a per-frame img2img chain, keep the first frame, and match every later frame back to it. It's also handy for matching a generated batch to a photographed reference for a consistent brand look across shots.

Install

It ships inside ComfyUI-SD-CN-Animation, so you get it with the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/pxl-pshr/ComfyUI-SD-CN-Animation

or install via ComfyUI Manager (search "ComfyUI-SD-CN-Animation"), then restart. Its dependency is the pack's scikit-image - already handled by the pack install.

Gotchas

Don't expect it to invent detail - histogram matching only redistributes color, it can't align composition or exposure structure frame-by-frame. And matching against a single dark or blown-out reference will crush your highlights accordingly. It's a blunt but reliable tool, which is exactly why the main nodes trust it: it's the reason SD-CN output doesn't slowly turn green by frame 40.

CategorySD-CN-Animation/utils

Inputs (2)

NameTypeDefaultDescription
sourceIMAGE
referenceIMAGE

Outputs (1)

NameTypeDescription
matchedIMAGE