Aware Hash Algorithm

Source: Internet
Author: User

Perceptual hash algorithm generates a "fingerprint" (fingerprint) string for each image, and then compares the fingerprints of different images. The closer the result is, the more similar the image is.

Advantage: it is simple and fast, and is not affected by the image size scaling.

Disadvantage: The image content cannot be changed.

Main Purpose: Find the source Image Based on the thumbnail and search for similar images in the search engine.

Hash algorithm principle

Step 1: Reduce the size.

Reduce the image size to 8x8, with a total of 64 pixels. The purpose of this step is to remove the image details, retain only the basic information such as structure and brightness, and discard the image differences caused by different sizes and proportions.

Step 2: simplify the color.

Convert the reduced image to 64-level gray scale. That is to say, all pixels have only 64 colors in total.

Step 3: calculate the average value.

Calculate the average gray scale of all 64 pixels.

Step 4: Compare the gray scale of pixels.

Compare the gray scale of each pixel with the average value. If the value is greater than or equal to the average value, it is recorded as 1. If the value is smaller than the average value, it is recorded as 0.

Step 5: Calculate the hash value.

The comparison result in the previous step is combined to form a 64-bit integer, which is the fingerprint of the image. The order of the combination is not important, as long as all images are in the same order.

After obtaining the fingerprint, you can compare different images to see how many digits are different in the 64-bit format. In theory, this is equivalent to calculating Hamming distance ). If the number of different data bits does not exceed 5, the two images are very similar. If the number is greater than 10, the two images are different.

Phash algorithm principle:

Although the mean hash is simple, it is greatly affected by the mean. For example, performing Gamma Correction or histogram balancing on an image affects the mean value and the final hash value. There is a more robust algorithm called phash. It maximizes the mean method. The discrete cosine transform (DCT) is used to obtain the low-frequency components of an image.

The extraction process is as follows:

(1) Reduced Size:Phash starts with a small image, but an image larger than 8x8 and 32x32 is the best. The purpose of this operation is to simplify the calculation of DCT, rather than reduce the frequency.

(2) Simplified colors:Converting images into grayscale images further simplifies the calculation workload.

(3) Calculate DCT:Calculate the DCT transformation of the image to obtain the 32*32 DCT coefficient matrix.

(4) Reduce DCT:Although the result of DCT is a 32*32 matrix, we only need to keep the 8*8 matrix in the upper left corner, which shows the lowest frequency in the image.

(5) calculate the average value:Calculate the mean value of DCT just like the mean hash.

(6) Calculate the hash value:This is the most important step. Based on the 8*8 DCT matrix, set the 64-bit hash value of 0 or 1 to "1" if it is greater than or equal to the mean value of DCT ", the value smaller than the DCT mean is set to "0 ". The combination constitutes a 64-bit integer, which is the fingerprint of the image.

The results do not tell us the low frequency of authenticity, but roughly tell us the relative ratio to the average frequency. As long as the overall structure of the image remains unchanged, the hash result value remains unchanged. This avoids the impact of Gamma Correction or color histogram adjustment.

Like the mean hash, phash can also be compared using the Hamming distance. (You only need to compare the positions of each bit and calculate the number of different bits)

The phash algorithm and the sift algorithm can find images with a deformation of no more than 25%.

Related blog posts include:

Visual Object Tracking Based on Hash Algorithm

It looks like it-image search is actually not difficult

Similar image search principles

Tineye image search website

Google Image Search Engine

Baidu's deep learning-based Baidu Image Recognition

Aware Hash Algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.