Similar images - how to compare them

2019-02-10 17:54发布

I have over 1.3milion images that I have to compare with each other, and a few hundreds per day are added.

My company take an image and create a version that can be utilized by our vendors.

The files are often very similar to each other, for example two different companies can send us two different images, a JPG and a GIF, both with the McDonald Logo, with months between the submissions.

What is happening is that at the end we find ourselves creating two different times the same logo when we could simply copy/paste the already created one or at least suggest it as a possible starting point for the artists.

I have looked around for algorithms to create a fingerprint or something that will allow me to do a simple query when a new image is uploaded, time is relatively not an issues, if it takes 1 second to create the fingerprint it will take 150 days to create the fingerprints but it will be a great deal in saving that we might even get 3 or 4 servers to do it.

I am fluent in PHP, but if the algorithm is in pseudocode or even C I can read it and try to translate (unless it uses some C specific libraries)

Currently I am doing an MD5 of all the images to catch the ones that are exactly the same, this question came up when I was thinking to do a resize of the image and run the md5 on the resized image to catch the ones that have been saved in a different format and resized, but then I would still not have a good enough recognition.

If I didn't mention it, I will be happy with something that just suggest possible "similar" images.

EDIT

Keep in mind that the check needs to be done multiple times per minute, so the best solution is one that gives me some values per image that I can store and use in the future to compare with the image that I am looking at without having to re-scan the whole server.

I am reading some pages that mention histograms, or resizing the image to a very small size, strip possible tags and then convert it in grayscale, do the hash of that files and use it for comparison. If I am succesful I will post the code/answer here

4条回答
萌系小妹纸
2楼-- · 2019-02-10 18:32

There is a PHP ImageMagick extension that you could use.

查看更多
三岁会撩人
3楼-- · 2019-02-10 18:43

To speedup the process, sort all the files with size and compare internals only if two sizes are equal. To compare internal data, using hash comparison is also fastest way. Hope this helps.

查看更多
姐就是有狂的资本
4楼-- · 2019-02-10 18:53

Try using file_get_contents and: http://www.php.net/manual/en/function.hash-file.php

If the hashes match, then you know they are the exact same.

EDIT: If possible I would think storing the image hashes, and the image path in a database table might help you limit server load. It is much easier to run the hash algorithm once on your initial images and store the hash in a table... Then when new images are submitted you can hash the image and then do a lookup on the database table. If the hash is already there discard it. You can use the hash as the table index and so once you find a match you dont need to check the rest.

The other option is to not use a database...But then you would have to always do a n lookup. That is check hash the incoming image and then run in memory a n time search against all saved images.

EDIT #2: Please view the solution here: Image comparison - fast algorithm

查看更多
老娘就宠你
5楼-- · 2019-02-10 18:56

A similar question to yours already exists, check it if it works for you : Compare 2 images in PHP

查看更多
登录 后发表回答