2012-10-10 43 views
5

我想要僅用葡萄和三個圓圈(紅色,綠色,藍色)來獲取圖像。 [我需要刪除所有的塗片]。 我該如何改進我的代碼?去除二進制圖像中的噪點

這是我的代碼:

RGB = imread('img_3235.jpg'); 
GRAY = rgb2gray(RGB); 

threshold = graythresh(GRAY); 
originalImage = im2bw(GRAY, threshold); 

originalImage = bwareaopen(originalImage,250); 

imshow(originalImage); 

CC = bwconncomp(originalImage); %Ibw is my binary image 
stats = regionprops(CC,'pixellist'); 

這是我的形象(img_3235.jpg)。 enter image description here

,這是我的代碼的結果: enter image description here

回答

11

您可以執行使用IMCLOSE一個morpholical閉幕。

se = strel('disk', 10); %# structuring element 
closeBW = imclose(originalImage,se); 
figure, imshow(closeBW); 

A的箭頭B的closing由A的箭頭B的擴張由B.

Result

+0

它的工作原理!謝謝! 我正在更新我的主題與另一個問題:/謝謝! –

+1

@AlonShmiel我很高興它的工作:D – Yamaneko

+0

我成功了,沒關係..非常感謝你! –

7

的備選解決方案獲得的,由所得到的結構的侵蝕,隨後是與中值濾波器適當的窗口尺寸,被應用的閾值只是後:

... 
originalImage = im2bw(GRAY, threshold); 
originalImage = medfilt2(originalImage,[37 37],'symmetric'); 
originalImage = bwareaopen(originalImage,250); 
figure, imshow(originalImage); 

enter image description here

+0

謝謝!我會檢查哪個選項對我來說更重要。非常感謝你!! :] –