Matlab颜色检测 [英] Matlab color detection

查看:609
本文介绍了Matlab颜色检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在同一场景的图像之间一致地检测到某种颜色。该想法是基于颜色配置文件来识别一组对象。所以,例如,如果我给一个场景中有一个绿色的球,我选择那个绿色作为我的调色板的一部分,我想要一个矩阵反映它检测球的函数。

I'm trying to consistently detect a certain color between images of the same scene. The idea is to recognize a set of object based on a color profile. So, for instance, if I'm given a scene with a green ball in it and I select that green as part of my color palette, I would like a function which has a matrix reflecting that it detects the ball.

任何人都可以推荐这个项目的一些matlab函数/插件/起点?理想地,颜色识别的功能将采用颜色值的数组并且在一定阈值内匹配它们。

Can anyone recommend some matlab functions/plugins/starting points for this project? ideally the function for color recognition will take an array of color values and will match them within a certain threshold.

Kinda像这样:
http://www.mathworks.com / matlabcentral / fileexchange / 18440-color-detection-using-hsv-color-space-training-and-testing

Kinda like this: http://www.mathworks.com/matlabcentral/fileexchange/18440-color-detection-using-hsv-color-space-training-and-testing

't)

更新:

这里是我选择不使用上述工具包的原因。

Here's why I chose not to use the above toolkit..

我从图片中选择一些感兴趣的颜色开始

I start by selecting some colors of interest in the picture

然后要求功能识别后面图像中的道路...

and then ask the function to recognize the road in later images...

绝对没有什么有用的被触发。所以,是的,除了我在下载和修复的代码中遇到的几个错误,这是一个踢球者。我没有尝试修复识别颜色的代码的主体,因为...好吧,我不知道如何,这就是为什么我来这里。

And absolutely nothing useful is triggered. So yeah, apart from the few bugs that I came across in the code on download and fixed, this was kind of the kicker. I didn't try to fix the body of the code that recognizes the colors because.. well, I don't know how, which is why I came here.

推荐答案

所以,让我刚开始说道路检测与颜色配置文件是一个病理问题。但如果道路的颜色是一致的,照明不会改变你想要识别的对象的颜色,那么你可能有一个镜头。 (这将是非常困难的,如果这是在外面,或与不同的相机,或者阴影发生,或它发生在任何类型的现实世界环境中)。

So, let me just start off by saying road detection with color profiles is a pathological problem. But if the color of the roads are consistent, and the lighting doesn't change the color of the object you are trying to recognize then you might have a shot. (this will be extremely difficult if this is taken outside, or with different cameras, or if shadows happen, or it taking place in any sort of real-world environment)

这里有几个可能有帮助的事情。

Here are a few things that might help.

请尝试先对图片进行平滑处理,您在第一张图片中得到不良结果的原因可能是因为道路中的像素变化很小。如果你可以模糊它们,或使用某种分水岭或局部平均,你可能会得到更一致的颜色的地区。

Try smoothing the image beforehand, the reason you get the bad results in the first images is probably because of small pixel variations in the road. If you can blur them, or use some sort of watershed or local averaging, you might get regions with more consistent color.

您也可以考虑使用LAB色彩空间,而不是HSV或RGB。

You might also consider using the LAB color space instead of HSV or RGB.

使用边缘检测(见matlab的canny边缘检测器)可能能够得到一些边界信息。如果你正在寻找一个光滑的对象,它将不会有很多边缘。

Using edge detection (see matlab's canny edge detector) might be able to get you some boundary information. If you are looking for a smooth object, there will not be very many edges in it.

编辑:我试图以最简单的方式坚持这个建议。下面是结果代码和一些示例。

I tried to adhere to this advice in the most simplistic way. Here are the resulting code and a few samples.

im=rgb2gray(im) %for most basic color capturing.. using another color space is better practice
%imshow(im)
RoadMask=roipoly(im)%create mask 
RoadMask=uint8(RoadMask);%cast to so you can elementwise multiply
im=im.*RoadMask;%apply mask
[x y]=size(im);
for i=1:x
    for j=1:y
        %disp('here')
        if (im(i,j)<160 || im(i,j)>180) %select your values based on your targets range
            im(i,j)=0;                  %replace everything outside of range with 0
            %disp(im(x,y))              %if you'd like to count pixels, turn all values
        end                             %within range to 1 and do a sum at end
    end
end

首先从RGB转换为灰阶

选择了一般与道路灰度相符的区域

注意道路的部分没有被捕获和块状边缘。如这个------------- ^

First converted from RGB to grayscale selected a region that generally matched the roads grayness Notice parts of the road are not captured and the blocky edges. such as this -------------^

这个实现很快又脏,但我想把它放在我忘记之前。我将尝试用实现平滑,采样和LAB颜色空间的代码更新。

This implementation was quicky and dirty, but I wanted to put it up before I forgot. I'll try to update with code that implements smoothing, sampling, and the LAB color space.

这篇关于Matlab颜色检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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