For a couple days now, I’ve been stuck on a task involving image comparison using PHP. I’m beginning to think that PHP isn’t the language to do this sort of task.
The Objective:
Use a base, compare a new line-art to it, and return the percentage difference between them.
I’ve tried a couple ways of going about this: Compare the differences in pixel count (which doesn’t really solve the goal of line-art difference), make all pixels that overlap, white, and find pixels without transparency/the color white and divide by non-transparent pixels in the base (which doesn’t seem to get the correct number)
Here’s an example:


— — — — — — — — Base — — — — — — — — — — — Line-Art — — — — — — —
The percentage difference should be around 54%. However, none of the ways I’ve tried get close (~5%) to this.
My question is: Can/How can this be done in PHP?
Thanks!
Images © Aywas.com
You might try using the ImageMagick function compareimagechannels(), using only the black channel?
Edit: Here’s a basic attempt, and its output. You might be able to manipulate the output numbers to figure out your thresholds. Images 1 and 2 are the line art and image 3 is the Google header logo resized to 200×200.
Output: