# Comparision of phash and Facebook PDQ

The phash algorithm is as follows:

1. Convert the image to greyscale and scale to 32x32.
2. Compute the discrete cosine transform of this scaled image. Discard all components of the DCT except the upper-left 8x8 portion.
3. Find the median value of the reduced DCT.
4. For each bit in the output hash,set it to 1 if the corresponding component of the reduced DCT is greater than the median, or 0 otherwise.

1. PDQ begins with a normalization step, which processes the luminance data from the input image.
2. A two-pass Jarosz filter to downsample the image to 64 × 64. Within the downsampled image, compute a sum of absolute values of horizontal and vertical gradients along with a two-dimensional discrete cosine transform, resulting in a 16 × 16 DCT.
3. For each of the 16x16 bits of the output hash, emit a 1 if the corresponding element of transform is greater than the median, otherwise emit a 0; the resulting 256 bits form the output digest.

The facebook PDQ algorithms is an extended version of the phash algorithms. The output of the phash algorithm is 64 bit where as the output of the Facebook PDQ algorithm is 256 bits. The number of bits used by PDQ is very high as compared to the phash, Thus my question is, Is it a good idea to say that PDQ is better than phash? Note that better means robust which means it can catch the manipulations on the images.

• what do you mean with "catch"? Like, neither is actually a "hash" in the cryptographic sense. Both have the same purpose: that similar images get the same, or very similar, "hashes". So, "catching manipulations" is not at all what they're designed to do? Commented Oct 2, 2023 at 8:14
• 'catch' means that the hamming distance between the hash of the original image and the manipulated image is large.
– Rma
Commented Oct 2, 2023 at 9:04
• @ Marcus Müller Thanks for the comment. assume that both have purpose that similar images get the similar or very similar hashing, then for this purpose which one is better.
– Rma
Commented Oct 2, 2023 at 9:14
• You're now directly contradicting yourself in two consecutive comments – so which comment is what you mean, and which is the opposite of what you actually mean? Commented Oct 2, 2023 at 11:32
• because you brought up Hamming distance: if that is involved, how do you fairly compare Hamming distances between 64 bit values and 256 bit values? Commented Oct 2, 2023 at 11:33