Matlab fills shapes with white

As you can see, I have forms and their white borders. I want to fill in the white shapes.

Input: enter image description here

I would like to get this output: http://s12.postimage.org/z3txnlb3f/untitled33.png

Can someone help me with this code? he does not change black ellipses to white. Many thanks:]]

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);
+5
source share
2 answers

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

Sort of:

imfill(image, [startX, startY])

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

+1
source

. -, Ibw BWCONNCOMP 4- . -, , , . , . ( - ):

I = imread('untitled4.bmp');
Ibw = im2bw(I);

CC = bwconncomp(~Ibw, 4);
[~, sortIndex] = sort(cellfun('prodofsize', CC.PixelIdxList));

Ifilled = Ibw;
Ifilled(vertcat(CC.PixelIdxList{sortIndex(1:end-2)})) = true;
imshow(Ifilled);

:

enter image description here

+3

All Articles