Nodes/comfyui_cv/CV Image Hash Compare
ComfyUI Node

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.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Image Hash Compare
  • image_a
  • image_b
  • distance
  • similar
  • hash_a
  • hash_b
algorithmpHash (DCT, best all-round)
threshold10.0
Categoryimage/CV/contrib

Inputs (4)

NameTypeDefaultDescription
image_aNPARRAY,IMAGEFirst 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_bNPARRAY,IMAGESecond 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.
algorithmCOMBOpHash (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.
thresholdFLOAT10.00–1000Distance 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)

NameTypeDescription
distanceFLOATHow 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).
similarBOOLEANTrue when distance <= threshold. Feed it to a 'Basic data handling: IfElse' to pick between two branches of the graph.
hash_aNPARRAYRaw hash of image_a - keep it to compare against many candidates without re-hashing.
hash_bNPARRAYRaw hash of image_b.