When computing the phash value for an image, why compare against the median?

The pHash algorithm for computing perceptual hashes of images is as follows:

1. Convert the image to greyscale and scale to 32x32.
2. Compute the discrete cosine transform of this scaled image.
3. Discard all components of the DCT except the upper-left 8x8 portion.
4. Find the median value of the reduced DCT.
5. 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.

Why compare against the median when building the final hash value? Since the purpose of perceptual hashing is to compare multiple images for similarity, wouldn't it be more effective to compare against something that is independent of the image being processed, such as the value 0?

It has to do with the number of ones and zeros that the median induces.

By definition it will create a binary sequence of 32 ones and 32 zeros in most cases.

So now similarity is well defined and normalized.

This comes from:

Coskun, B. and Sankur, B.: "Robust video hash extraction." In Proceedings of the Signal Processing and Communications Applications Conference, pp. 292–295. IEEE, Apr. 2004.

where they say:

• After playing around with perceptual-hash functions for a bit, I'm not convinced this is actually a useful thing to do. Usually, when using perceptual hashes, you want collisions; maximizing uniqueness will increase the rate of false negatives when looking for near-duplicates. (Using 0 as the threshold has the specific benefit that you can compute the phash of the mirror of the image by a simple XOR operation.)
– Mark
Oct 5, 2023 at 6:27