2015-04-28 219 views
2

我有一张图像,在该图像中检测到所有红色物体。如何检测图像中只有红色物体的边缘

下面是具有两个图像的示例:

http://img.weiku.com/waterpicture/2011/10/30/18/road_Traffic_signs_634577283637977297_4.jpg

但是,当我继续进行该图像的边缘检测方法我得到的输出作为唯一的黑色。但是,我想检测那个红色物体的边缘。

r=im(:,:,1); g=im(:,:,2); b=im(:,:,3); 
diff=imsubtract(r,rgb2gray(im)); 
bw=im2bw(diff,0.18); 
area=bwareaopen(bw,300); 
rm=immultiply(area,r); gm=g.*0; bm=b.*0; 
image=cat(3,rm,gm,bm); 
axes(handles.Image); 
imshow(image); 

I=image; 
Thresholding=im2bw(I); 

axes(handles.Image); 
imshow(Thresholding) 

fontSize=20; 
edgeimage=Thresholding; 
BW = edge(edgeimage,'canny'); 
axes(handles.Image); 
imshow(BW); 
+1

请告诉我们原始的,未经修改的图像。也不要使用'image'作为内建函数的变量名称。谢谢! –

+0

http://img.weiku.com/waterpicture/2011/10/30/18/road_Traffic_signs_634577283637977297_4.jpg –

+0

这些都是一些示例图片。我主要关注招牌。 –

回答

8

当你申请im2bw你想只使用I红色通道(即第1路)。因此,使用这个命令:

Thresholding =im2bw(I(:,:,1)); 

例如产生的输出:

enter image description here

+2

哈哈这么简单。我正要对那个坏男孩运用一些严肃的形态。 +1。 – rayryeng

+0

im2是什么规定? –

+0

对不起,我改变了变量名称以适合你:) –

0

仅供参考其他任何人管理在这里跌倒。 HSV色彩空间更适合检测RGB色彩空间上的色彩。 gnovice的answer就是一个很好的例子。这样做的主要原因是有些颜色可以包含完整的255个红色值,但实际上并不是红色(黄色可以由(255,255,0),白色从(255,255,255),品红从(255,0,255)等等)。

我修改了他的代码下面你的目的:

cdata = imread('roadsign.jpg'); 

hsvImage = rgb2hsv(cdata);   %# Convert the image to HSV space 
hPlane = 360.*hsvImage(:,:,1);  %# Get the hue plane scaled from 0 to 360 
sPlane = hsvImage(:,:,2);   %# Get the saturation plane 
bPlane = hsvImage(:,:,3);   %# Get the brightness plane 

% Must get colors with high brightness and saturation of the red color 
redIndex = ((hPlane <= 20) | (hPlane >= 340)) & sPlane >= 0.7 & bPlane >= 0.7; 

% Show edges 
imshow(edge(redIndex)); 

输出: enter image description here

+0

那也不错 –