CV Image Hash Compare
Decides whether two images are the SAME PICTURE (cv2.img_hash), tolerating rescaling, compression and mild edits - unlike a pixel diff. Use it to skip duplicate outputs, detect that a generation barely changed, or find which reference a result resembles. Outputs the distance, a similarity flag against your threshold, and both hashes. The distance always reads the SAME WAY - 0 = identical, larger = more different - for every algorithm (cv2 itself returns a similarity for 'radial variance'; this node converts it). The SCALE still differs: the bit-based hashes report a Hamming distance in BITS (~2 = a rescaled copy, ~30 = unrelated), while 'colour moment' and 'radial variance' report small floating-point distances - so tune 'threshold' per algorithm.
- image_a
- image_b
- distance
- similar
- hash_a
- hash_b
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image_a | NPARRAY,IMAGE | First image (3-channel). Frame 0 of a batch. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size. | |
| image_b | NPARRAY,IMAGE | Second image. It may be a different SIZE - that is the point of a perceptual hash. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size. | |
| algorithm | COMBO | pHash (DCT, best all-round) | pHash is the robust default. 'average' is fastest but brightness-sensitive. 'colour moment' and 'radial variance' survive ROTATION. 'Marr-Hildreth' is the most sensitive to structural edits. |
| threshold | FLOAT | 10.00–1000 | Distance at or below which the images count as similar. For the bit-based hashes this is in bits (~5 = near-identical, ~10 = same scene, >20 = unrelated); for 'colour moment' use a much smaller value (~1). |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| distance | FLOAT | How far apart the two hashes are, ALWAYS in the same direction: 0 = identical, larger = more different. The useful scale depends on the algorithm (see the node description). |
| similar | BOOLEAN | True when distance <= threshold. Feed it to a 'Basic data handling: IfElse' to pick between two branches of the graph. |
| hash_a | NPARRAY | Raw hash of image_a - keep it to compare against many candidates without re-hashing. |
| hash_b | NPARRAY | Raw hash of image_b. |