Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Hash algorithm for Image similarity

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of image similarity Hash algorithm, which is very detailed and has a certain reference value. Interested friends must read it!

Image similarity Hash algorithm

There are three kinds of Hash algorithms, which are average hash algorithm (aHash), perceptual hash algorithm you (pHash) and differential hash algorithm (dHash).

This paper implements the average hash algorithm.

1 average hash algorithm (aHash) 1.1 algorithm steps

The average hash algorithm is the simplest of the three Hash algorithms. It obtains the hash value of the picture through the following steps: (1) zoom the picture; (2) convert the grayscale image; (3) calculate the pixel mean; and (4) calculate the fingerprint according to the similar mean. The specific algorithm is as follows:

Table 1 aHash algorithm to get the hash value of the picture

Zoom the picture

The size of the input picture is different. In order to unify the input of the picture, the size of the picture is scaled to 8x8, and a total of 64 pixels are obtained.

Convert grayscale image

Some of the input pictures are single-channel grayscale images, some RGB three-channel color images, and some RGBA four-channel color images. In order to unify the next input standard, all non-single-channel images are converted into single-channel grayscale images. Among them, RGB three-channel to single-channel algorithm has the following:

1. Floating-point algorithm: Gray=R0.3+G0.59+B0.11

two。 Integer method: Gray= (R30+G59+B11) / 100

3. Shift method: Gray = (R76+G151+B*28) > > 8

4. Average method: Gray= (R+G+B) / 3

5. Green only: Gray=G

Calculate the pixel mean

Through the previous step, we can get an integer matrix G of 8x8, and calculate the average value of all elements in this matrix, assuming that its value is a.

Calculate fingerprints according to pixel mean

Initialize the ahash of the input picture = ""

Traversing matrix G row by row from left to right if row I j column element G (iMaginj) > = a, then ahash + = "1" if row I j column element G (iMaginj) avg); finally bmp.Free; end; end; 1: / / pHash aware hash algorithm begin end; 2: / / dHash differential hash algorithm begin end; end Result: = ret;end

Calculate the hamming distance function:

Function TForm1.Hamming (Hash2, Hash3: Int64): Integer;var A: Int64;begin Result: = 0; A: = Hash2 xor Hash3; while A0 do begin A: = An and (Amur1); Inc (Result); end;end; is all the contents of this article "sample Analysis of Image similarity Hash algorithm". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report