2017-03-03 237 views

回答

1

檢查以下解決方案:

我打了填充圖像和填充負像,直到解決它。

這裏是我的代碼:

I = imread('https://i.imgur.com/Ap2PX2E.png'); 
I = im2bw(I); 

J1 = imfill(I, 'holes'); 
J2 = imfill(I, [1, 1]); 
J3 = imfill(~J2, [1, 1]); 
J4 = imfill(~J3, 'holes'); 
J5 = J1 & (~J4); 

figure;imshow(J5) 

結果:
enter image description here

2

這裏是比Rotem提供了更簡單和可靠的方法:

I = imread('https://i.imgur.com/Ap2PX2E.png'); 
I = im2bw(I); 

I2 = imfill(I,'holes');   % Create filled image 
I3 = I & imerode(I2, ones(3)); % Create enclosed hole boundaries 
I4 = I2 & ~imfill(I3, 'holes'); % Subtract enclosed holes 

figure; 
imshow(I4) 

Result