Compare the form in the image with PHP

I am trying to compare shapes in php. I have a database with a large number of images, these images have a form (mainly in the center of the image). Now I want to compare these images with a figure.

Input is a form (png) that is exactly the same size as the images in the database.

I made a function that takes the form color and turns it into black (and the background in white)

The input is as follows: enter image description here

The original looks like this: enter image description here

I can compare every pixel in the image and keep track of how many black pixels are the same, but this will require a lot of processor, and I think that it will not work every time.

I can also use another language, for example python, but I really fix this in PHP. Does anyone have an idea to do this in a practical way?

Anderser in the question " Compare 2 images in php " is different from what I expect. I need to compare part of the image (in the example, the background is white, but there may be some noise in it)

+5
source share
1 answer

This seems doable with the trimImage() function in the ImageMagick icon ( -trim on the command line). Given that you have already been able to convert the image to a black front and white background, this function should always do what you want. At this point, simply compare the images as indicated in the question you linked.

This is the result of using trim on the command line in an image with the addition:

enter image description here


I assume that the function you created is similar to the algorithm in findimagedupes . If not, you should borrow this idea.

+2
source

All Articles