Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image comparison in php

My scenario is as follows: I have to save 1000 of images in database, and then I have to compare new image with database images for matches (match should be 70% or more) to get the best match image from database in php.

is there any algorithm or method for fast comparison with better result ...

Thanks in advance :)

like image 684
VRK Avatar asked Aug 20 '26 08:08

VRK


1 Answers

I would suggest you use a Perceptual Hash or similar - mainly for reasons of performance. In essence, you create a single number, or hash, for each image ONCE in your database at the point where you insert it, and retain that hash in the database. Then when you get a new image to insert, you calculate its hash and compare it to the PRE-CALCULATED hash of all the other images so that you don't have to drag all the megabytes of pixels of your existing images from disk to compare them.

The best pHASHes are scale-invariant and image format invariant. Here is an article by Dr Neal Krawetz... Perceptual Hashing.

ImageMagick can also do Perceptual Hashing and is callable from PHP - see here.

like image 125
Mark Setchell Avatar answered Aug 22 '26 12:08

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!