ios - 求比较两幅图片是相似度的代码范例
PHP中文网
PHP中文网 2017-04-17 11:38:05
0
2
706

如题,如果有iOS客和Android客户端的示例代码,那是最好了。
如果只有服务端的也可以,参考着做。

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
Ty80

Perceptual hash algorithm - Perceptual hash algorithm

Simple steps:

  1. The first step is to reduce the size.
  2. The second step is to simplify the colors.
  3. The third step is to calculate the average.
  4. The fourth step is to compare the grayscale of pixels.
  5. The fifth step is to calculate the hash value.

Reference link: Principle of similar image search - Ruan Yifeng | Color distribution method and content feature method


左手右手慢动作

Similarity is a very vague thing. . . If you just want to implement a simple version, I found a very interesting algorithm on stackoverflow:

  1. Reduce the two images to a smaller, same size, such as 64*64 or 32*32. When zooming out, the value of each pixel is a function of the values ​​of the surrounding n pixels. To put it simply, average is used.
  2. Expand the color range so that the darkest color in the picture is completely black and the lightest color is completely white
  3. Rotate/flip the image so that the pixels in the four corners of the image are arranged clockwise in descending order starting from the upper left corner.

Then find the average similarity of each point of the two pictures (the similarity can be calculated by using the difference, the square of the difference, or multiplying it by a weight based on the position. Get some data and run it to select the one with the best effect).

Interestingly, this algorithm can even support pre-computing a batch of images and then querying similar ones from the database:

To look up a possible match in a database, store the pixel colors as inpidual columns in the database, index a bunch of them (but not all, unless you use a very small image), and do a query that uses a range for each pixel value, ie. every image where the pixel in the small image is between -5 and +5 of the image you want to look up.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template