2015-04-28 218 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

那也不錯 –