Matlab用白色填充形状

Alo*_*iel 5 matlab fill

如你所见,我有形状和白色边界.我想填充白色的形状.

输入是: 在此输入图像描述

我想得到这个输出: http://s12.postimage.org/z3txnlb3f/untitled33.png

有人可以用这个代码帮我吗?它不会将黑色椭圆变为白色.非常感谢 :]]

I = imread('untitled4.bmp');
Ibw = im2bw(I);
CC = bwconncomp(Ibw); %Ibw is my binary image
stats = regionprops(CC,'pixellist');

% pass all over the stats
for i=1:length(stats),
size = length(stats(i).PixelList);
% check only the relevant stats (the black ellipses)
if size >150 && size < 600 
    % fill the black pixel by white    
    x = round(mean(stats(i).PixelList(:,2)));
    y = round(mean(stats(i).PixelList(:,1)));
    Ibw = imfill(Ibw, [x, y]);
end;
end;

imshow(Ibw);
Run Code Online (Sandbox Code Playgroud)

Ric*_*nte 1

如果您的图像都是黑白的,并且您有图像处理工具包,那么这看起来就像您所需要的: http ://www.mathworks.co.uk/help/toolbox/images/ref/imfill.html

就像是:

imfill(image, [startX, startY])
Run Code Online (Sandbox Code Playgroud)

其中 startX、startY 是要填充的区域中的像素。