Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Finding Differences in Images with PHP
May 26, 2016 @ 15:56:33

The SitePoint PHP blog has posted a new tutorial from author Christopher Pitt on an interesting topic that could come in very handy in the right situations: finding differences in images with PHP.

I recently stumbled across a fascinating question: how could I tell whether an image had changed significantly? As PHP developers, the most troublesome image problem we have to deal with is how to resize an upload with an acceptable loss of quality. In the end I discovered what many before me have – that this problem becomes relatively simple given the application of some fundamental mathematical principles.

He starts off by talking about images as "bitmaps", basically a collection of pixels composed in a grid. He also mentions images as sets of vectors, but in PHP the bitmap approach is simpler and more understandable. He includes some code showing the breakdown of an image into its RBG colors values and what the data represents. He then moves into measuring the distance "in three dimensions" with a bit of geometry and applies them to a simple State class. This class breaks down the image given into RBG details then, eventually, compares the other image based on the euclidean distance between the points on the original and the ones from the new image. He filters some of these results through a standard deviation view to weed out problems with almost identical images.

tagged: image difference evaluation tutorial gd similar euclideandistance standarddeviation

Link: https://www.sitepoint.com/finding-differences-in-images-with-php/


Trending Topics: