I have a table A which has a column \'template_phash\'. I store the phash generated from 400K images.
Now I take a random image and generate a phash from that image.
I figured out that the hamming distance is just the count of different bits between the two hashes. First xor the two hashes then get the count of binary ones:
SELECT product_id, BIT_COUNT(phash1 ^ phash2) as hd from A ORDER BY hd ASC;