Matlab用白色填充形状

Matlab用白色填充形状

本文介绍了Matlab用白色填充形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所见,我具有形状及其白色边界.我想用白色填充形状.

As you see, I have shapes and their white boundaries. I want to fill the shapes in white color.

输入为:

我想得到以下输出:

I would like to get this output:

有人可以帮助我使用此代码吗?它不会将黑色椭圆更改为白色.非常感谢:]]

Can anybody help me please with this code? it doesn't change the black ellipses to white.Thanks alot :]]

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);

推荐答案

如果您的图像都是黑白的,并且您拥有图像处理工具包,那么您将需要以下内容: http://www.mathworks.co.uk/help/toolbox /images/ref/imfill.html

If your images are all black&white, and you have the image processing toolkit, then this looks like what you need:http://www.mathworks.co.uk/help/toolbox/images/ref/imfill.html

类似的东西:

imfill(image, [startX, startY])

其中startX,startY是您要填充的区域中的像素.

where startX, startY is a pixel in the area that you want to fill.

这篇关于Matlab用白色填充形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:42