The pHash algorithm for computing perceptual hashes of images is as follows:
- Convert the image to greyscale and scale to 32x32.
- Compute the discrete cosine transform of this scaled image.
- Discard all components of the DCT except the upper-left 8x8 portion.
- Find the median value of the reduced DCT.
- 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?