How to fill BLACK a region in an image?
Show older comments
I have an image (no matter gray or binary). I want to fill several regions (that are selected by the user through interface) in BLACK!
imfill and roifill cannot do this, because they fill in white!
(I think roifill is exactly what I need, but it fills them white not black!)
Does anybody know how I can resolve my problem?
Accepted Answer
More Answers (2)
1 Comment
Image Analyst
on 12 Dec 2013
That looks like a binary image. So why is imfill() not working?
filledImage = imfill(binaryImage, 'holes');
Walter Roberson
on 13 Dec 2013
0 votes
Why not just assign 0 to the roi regions? If they are defined as polygons, then poly2mask() to get the bitmap.
8 Comments
Steven
on 13 Dec 2013
Walter Roberson
on 13 Dec 2013
BW = poly2mask(x, y, m, n) computes a binary region of interest (ROI) mask, BW, from an ROI polygon, represented by the vectors x and y. The size of BW is m-by-n. poly2mask sets pixels in BW that are inside the polygon (X,Y) to 1 and sets pixels outside the polygon to 0.
You had implied that you already had the ROIs, but you did not mention what form they were in, so I gave some information for the polygon case, under the assumption that if they were already in bitmask form, you would have already just set the area to 0.
Steven
on 13 Dec 2013
Image Analyst
on 13 Dec 2013
I'm really puzzled why my suggestion of using imfill() is not working for you. Why are you heading down this more complicated path?
Image Analyst
on 14 Dec 2013
I thought you wanted to "fill several regions (that are selected by the user through interface) in BLACK!" In other words, take the black areas ( or possibly just some of them that are selected by the user) and fill them in - with the surrounding color, which is white. If that's not what you meant, then please explain in a lot more detail. Because the only thing I see that can be "filled in" are the black holes in the big white blob on the left.
Image Analyst
on 14 Dec 2013
Like this???
% Find the binary image
binaryImage = grayImage > thresholdValue; % say 200 or something.
% Make those pixels black.
grayImage(binaryImage) = 0;
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!