与php + gd的图像比较 [英] Image comparison with php + gd

查看:149
本文介绍了与php + gd的图像比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用php和, Gmagick 开罗对于PHP,但我宁愿避免使用其他语言而不是PHP。



提前致谢。

解决方案

我原以为你了方法似乎是合理的,但将整个图像缩小到1x1像素可能是一个步骤太远。



但是,如果您将每个图像转换为相同的大小然后计算每个16x16(或32x32,64x64等等的平均颜色取决于您希望使用多少处理时间/功率)单元格,您应该能够形成某种明智的(-ish)比较。


What's the best approach to comparing two images with php and the Graphic Draw (GD) Library?

This is the scenario:

alt text http://img262.imageshack.us/img262/4849/imagecomparison.jpg

I have an image, and I want to find which image of a given set is the most similar to it. The most similar image is in fact the same image, not pixel perfect match but the same image. I've dramatised the difference between the two images with the number one on the example just to ease the understanding of what I meant.

Even though it brought no consistent results, my approach was to reduce the images to 1px using the imagecopyresampled function and see how close the RGB values where between images.

The sum of the values of deducting each red, green and blue decimal equivalent value from the red, green and blue decimal equivalent value of the possible match gave me a dissimilarity index that, even though it didn't work as expected since not always the most RGB similar image was the target image, I could use to select an image from the available targets.

Here's a sample of the output when comparing 4 images against a target image, in this case the apple logo, that matches one of them but is not exactly the same:

Original image:

http://www.lshtm.ac.uk/its/remote/images/os-apple.png Red:222 Green:226 Blue:232

Compared against:

http://a1.twimg.com/profile_images/571171388/logo-twitter_normal.png Red:183 Green:212 Blue:212 and an index of similarity of 56

http://icons-search.com/img/fasticon/fruits_lnx.zip/fruits_lnx-Icons-48X48-apple.png-48x48.png Red:117 Green:028 Blue:028 and an index of dissimilarity 530

http://www.1sd.org/wp-content/uploads/2008/10/48x48-apple.png Red:218 Green:221 Blue:221 and an index of dissimilarity 13 Matched Correctly.

Red:061 Green:063 Blue:063 and an index of dissimilarity 491

May not even be doable better with better results than what I'm already getting and I'm wasting my time here but since there seems to be a lot of experienced php programmers I guess you can point me in the right directions on how to improve this.

I'm open to other image libraries such as iMagick, Gmagick or Cairo for php but I'd prefer to avoid using other languages than php.

Thanks in advance.

解决方案

I'd have thought your approach seems reasonable, but reducing an entire image to 1x1 pixel in size is probably a step too far.

However, if you converted each image to the same size and then computed the average colour in each 16x16 (or 32x32, 64x64, etc. depending on how much processing time/power you wish to use) cell you should be able to form some kind of sensible(-ish) comparison.

这篇关于与php + gd的图像比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆