图像分类 - 检测楼层平面图 [英] Image Classification - Detecting Floor Plans

查看:299
本文介绍了图像分类 - 检测楼层平面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个房地产网站,我想编写一个程序,如果图像是平面图或公司徽标,
可以计算出(分类)。

I am working on a real estate website and i would like to write a program that can figure out(classify) if an image is a floor plan or a company logo.

由于我在php中编写,我更喜欢php解决方案,但任何c ++或opencv解决方案都可以。

Since i am writing in php i will prefer a php solution but any c++ or opencv solution will be fine as well.

平面图样本:

alt http://www.rentingtime.com/uploads/listing/l0050/0000050930/68614.jpg

alt text http://www.rentingtime.com/uploads/listing/l0031/0000031701/44199.jpg

徽标样本:

替代文字http://www.rentingtime.com/uploads/listing/l0091/0000091285/95205.jpg

解决方案

一如既往,有一个内置PHP函数。只是在开玩笑。 =)

As always, there is a built-in PHP function for this. Just joking. =)

我见过的所有楼层平面图都非常单色,我想你可以玩颜色和颜色饱和度来猜测它是个不错的选择图像是徽标或平面图。

All the floor plans I've seen they are pretty monochromatic, I think you can play with the number of colors and color saturation to have a pretty good guess is the image is a logo or a floor plan.

例如:图像的平面图少于2或3种颜色。

例如:如果饱和度的总和/平均值小于X则是平面图。

黑白(以及平面图中使用的其他类似颜色)的饱和度为零或非常接近于零,而徽标往往是更具视觉吸引力,因此使用更饱和的颜色。

Black and white (and other similar colors that are used in floor plans) have a saturation that is zero, or very close to zero, while logos tend to be more visually attractive, hence use more saturated colors.

这是一个计算Hex RGB颜色饱和度的简单函数:

Here is a simple function to compute the saturation of a Hex RGB color:

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()你可以实现一个简单的函数,它循环通过图像的所有像素并求和/计算饱和度的平均值。如果图像的饱和度高于自定义阈值,则可以假定图像是徽标。

Using imagecolorat() and imagecolorsforindex() you can implement a simple function that loops trough all the pixels of the image and sums / computes the average of the saturation. If the image has a saturation level above of a custom threshold you define you can assume that the image is a logo.

有一点你不应该忘记的是有更高的分辨率通常会有更多的饱和度(更多的像素总和),所以为了这个算法,也为了你的服务器性能,将所有图像调整为一个普通的分辨率(比如100x100或50x50)是明智的)对它们进行分类,一旦分类,你可以使用原始(未调整大小)的图像。

One thing you shouldn't forget is that images that have a higher resolution will normally have more saturation (more pixels to sum), so for the sake of this algorithm and also for the sake of your server performance it would be wise to resize all the images to a common resolution (say 100x100 or 50x50) to classify them and once classified you could use the original (non-resized) images.

我用你提供的图像做了一个简单的测试,这里是代码我已使用:

I made a simple test with the images you provided, here is the code I used:

$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,您可以通过添加额外的示例进一步调整它。

这篇关于图像分类 - 检测楼层平面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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