Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare a shape in an image with PHP

I'm trying to compare shapes in php. I have a database with a lot of images, in those images there is a shape ( mostly in the center of the image ). Now I want to compare those images to a Shape.

The input is a shape (png) that is exact the same size then the images in the database.

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

The input is like this: enter image description here

The original is like this: enter image description here

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

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

The anwser in the question "Compare 2 images in php" is different then I expect. I need to compare a part of an image ( in the example the background in white, but it can be there is some noise in the background )

like image 649
S.Visser Avatar asked Oct 31 '22 22:10

S.Visser


1 Answers

This seems to be doable with the trimImage() function in ImageMagick (-trim flag on the command line). Considering you were already able to convert the image into a black foreground and white background, this function should always do what you want. At this point just compare images as stated in the question you linked.

This is the result of using trim on the command line on the image with padding:

enter image description here


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

like image 88
Anonymous Avatar answered Nov 09 '22 06:11

Anonymous