OpenCV compareHist_0
One number that says 'these two images have the same color feel' (OpenCV compareHist_0)
- H1
- H2
- float
Sometimes you don't care about pixels at all - you care about vibe. Is this generated image closer in color to reference A or reference B? Does this frame match the style of the ones before it? That's histogram territory, and compareHist_0 is the OpenCV function cv2.compareHist with a ComfyUI face on it. Feed it two histograms, get back a single float that tells you how much they agree.
What it is
One of the auto-generated opencv-comfyui nodes, and it's the purest kind: no image in, no image out. Inputs are two histograms (H1, H2), the output is a FLOAT score. It's a measurement node, the kind you wire into a comparison or a conditional rather than straight into a preview.
How it works
A histogram is just a distribution - "how much of this image sits in each brightness/color bin." compareHist measures how far apart two distributions are, and which method changes what the score means:
0- CORREL: higher = more similar (-1..1)1- CHISQR: lower = more similar (0 = identical)2- INTERSECT: higher = more similar (raw bin overlap)3- BHATTACHARYYA: lower = more similar (0 = identical)
If you're doing "is this like that", 2 (intersect) is the intuitive one - it's literally how much the histograms overlap. 0 and 3 are the ones the image-retrieval crowd actually uses, because they're normalized and behave better across brightness changes.
The honest caveat: this pack can't make histograms
Here's where people get burned. compareHist_0 compares histograms, but the pack has no calcHist node - I grepped the source, it isn't there (its return type wasn't supported by the generator). So you can't build the H1/H2 inputs inside opencv-comfyui itself. You need them from elsewhere: a tiny custom Python node running cv2.calcHist, or any node that outputs an array you can treat as a distribution.
That makes this one of the most "you probably won't use it" nodes in the pack - unless you already have a histogram source, in which case it's a genuinely handy similarity score for duplicate detection or checking that a batch of renders didn't drift in color.
The inputs and outputs that matter
- H1 / H2 (NPARRAY) - the two histograms. Same size and type, or expect an assertion.
- method (INT) - pick from the list above;
2to start. - Output:
float- the score. This is not an image. Do not wire it intoNparrays2Image; you'll get the README's'NoneType' object has no attribute 'shape'because it's a scalar, not an array. Feed it into a math or logic node instead.
Install and gotchas
Same pack install as everything else - ComfyUI Manager, search "opencv-comfyui", or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes. Requires opencv-python-contrib. Watch for the guidedFilter import conflict if you have multiple OpenCV installs. And remember the golden rule of this pack: any node whose output you try to render as an image will remind you the hard way that some functions just return numbers.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| H1 | NPARRAY | — | |
| H2 | NPARRAY | — | |
| method | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |