0
$\begingroup$

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.

Facebook PDQ:

  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.

$\endgroup$
8
  • $\begingroup$ 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? $\endgroup$ Commented Oct 2, 2023 at 8:14
  • $\begingroup$ 'catch' means that the hamming distance between the hash of the original image and the manipulated image is large. $\endgroup$
    – Rma
    Commented Oct 2, 2023 at 9:04
  • $\begingroup$ @ 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. $\endgroup$
    – Rma
    Commented Oct 2, 2023 at 9:14
  • $\begingroup$ 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? $\endgroup$ Commented Oct 2, 2023 at 11:32
  • $\begingroup$ 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? $\endgroup$ Commented Oct 2, 2023 at 11:33

1 Answer 1

1
$\begingroup$

A) large hamming distance for manipulated images

Please answer for A.

phash scales down extremely early, so that will instantly erase many smaller modifications. So, for small-scale changes, phash will not have any hamming distance, or very small. For histogram changes, PDQ erases that part of information up front, and hence will have zero hamming distance. So, it depends on what type of change you need to detect.

But honestly, if you just want to make sure two images that are slightly different have different hashes, scale both images to the same size (say, 512×512), quantize to 8-bit single-channel and take any information-theoretical hash (xxhash XXH3 or XXH128, SHA-256, Blake2…). You get identical hashes for identical images, and a hamming distance of on average half the hash length for modified images. Can't get better than that!

The two hashes (which aren't "hashes" in the information-theoretical sense) you're looking at do the literall opposite of what you want. Their purpose is to make similar, but not necessarily identical, images have similar or identical hashes. That's what they're built for!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.