一如既往,有一个built-in PHP function for this。只是在开玩笑。 =)
我见过的所有平面图都非常单调,我认为你可以用颜色和颜色饱和度来玩一个很好的猜测,就是图像是一个标志或一个平面图。
如:is the image has less than 2 or 3 colors is a floor plan.
如:if the sum/average of the saturation is less than X it's a floor plan.
黑色和白色(以及在平面图中使用其他类似的颜色)的饱和是零,或者非常接近于零,而标志往往更具视觉吸引力,因此使用更饱和的颜色。
下面是一个简单的函数来计算一个十六进制RGB颜色的饱和度:
function Saturation($color)
{
$color = array_map('hexdec', str_split($color, 2));
if (max($color) > 0)
{
return (max($color) - min($color))/max($color);
}
return 0;
}
var_dump(Saturation('000000')); // black 0.0000000000000000
var_dump(Saturation('FFFFFF')); // white 0.0000000000000000
var_dump(Saturation('818185')); // grey 0.0300751879699249
var_dump(Saturation('5B9058')); // green 0.3888888888888889
var_dump(Saturation('DE1C5F')); // pink 0.8738738738738738
var_dump(Saturation('FE7A15')); // orange 0.9173228346456692
var_dump(Saturation('FF0000')); // red 1.0000000000000000
var_dump(Saturation('80FF80')); // --- 0.4980392156862745
var_dump(Saturation('000080')); // --- 1.0000000000000000
使用imagecolorat()和imagecolorsforindex()你可以实现一个简单的函数,环槽的所有图像和和的像素/计算饱和度的平均值。如果图像的饱和度高于您定义的自定义阈值,则可以假定图像是徽标。
有一件你不应该忘记的是,具有更高分辨率的图像通常会有更多的饱和度(更多的像素进行求和),所以为了这个算法以及为了您的服务器性能,它会是明智地将所有图像调整为通用分辨率(比如100x100或50x50)来对它们进行分类,一旦分类,您可以使用原始(未调整大小)的图像。
我与你提供的图像一个简单的测试,这里是我使用的代码:
$images = array('./44199.jpg', './68614.jpg', './95205.jpg', './logo.png', './logo.gif');
foreach ($images as $image)
{
$sat = 0;
$image = ImageCreateFromString(file_get_contents($image));
for ($x = 0; $x < ImageSX($image); $x++)
{
for ($y = 0; $y < ImageSY($image); $y++)
{
$color = ImageColorsForIndex($image, ImageColorAt($image, $x, $y));
if (is_array($color) === true)
{
$sat += Saturation(dechex($color['red']) . dechex($color['green']) . dechex($color['blue']));
}
}
}
echo ($sat/(ImageSX($image) * ImageSY($image)));
echo '<hr />';
}
而且这里的结果:
green floor plant: 0.0151028053
black floor plant: 0.0000278867
black and white logo: 0.1245559912
stackoverflow logo: 0.0399864136
google logo: 0.1259357324
只使用这些例子中,我会形象地说是地板厂如果平均饱和度小于0.03或0.035,你可以调整通过添加额外的例子它远一点。
你可能会更适合在自由程序员的网站上寻找;这有点超出了单个问题的范围。 – Amber 2009-12-20 08:32:34
除非这些平面图文档易于表征,否则您不需要自由程序员,因为您需要一个充满博士学位的研发部门。没有人会在PHP中写出这样的想法。 – 2009-12-20 08:35:53
http://www.townsvillefloorplans.com.au/images/logo.jpg既是...... – 2009-12-20 11:59:44