Skip to main content
Vane Data / Reference

image_hash

image_hash computes a perceptual hash of an IMAGE with a fixed byte width and MSB-first bits. It accepts all image modes and ignores alpha.

Signature

example.py
vane.image_hash(
    image, *, method="phash", hash_size=8, binbits=3, segments=3,
) -> Expression

SQL: image_hash(image, method => ..., hash_size => ..., binbits => ..., segments => ...). Expression method: expr.image_hash(...).

Parameters

NameTypeDescriptionDefault
imageIMAGE value or ExpressionInput imageRequired
methodHash method name (constant)ahash, dhash, dhash_vertical, phash, phash_simple, whash, colorhash, or crop_resistant"phash"
hash_sizeInteger constant, 2–64Hash grid size; whash requires a power of two8
binbitsInteger constant, 1–8Color-bin bits3
segmentsInteger constant, 1–16Crop-resistant grid segments3

Returns and errors

Returns FIXEDBINARY(n) content-similarity bits, zero-padded in the last byte. It is not an integrity checksum. NULL images return NULL; options must be non-NULL constants and valid for the method.

Example

example.py
import vane


con = vane.connect()
con.sql("SELECT image_hash(decode_image_file(image_file('photo.png')))").show()