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

我想得到这个输出:
有人可以用这个代码帮我吗?它不会将黑色椭圆变为白色.非常感谢 :]]
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)
如果您的图像都是黑白的,并且您有图像处理工具包,那么这看起来就像您所需要的: http ://www.mathworks.co.uk/help/toolbox/images/ref/imfill.html
就像是:
imfill(image, [startX, startY])
Run Code Online (Sandbox Code Playgroud)
其中 startX、startY 是要填充的区域中的像素。