How to fill BLACK a region in an image?
古いコメントを表示
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?
採用された回答
その他の回答 (2 件)
1 件のコメント
Image Analyst
2013 年 12 月 12 日
That looks like a binary image. So why is imfill() not working?
filledImage = imfill(binaryImage, 'holes');
Walter Roberson
2013 年 12 月 13 日
0 投票
Why not just assign 0 to the roi regions? If they are defined as polygons, then poly2mask() to get the bitmap.
8 件のコメント
Steven
2013 年 12 月 13 日
Walter Roberson
2013 年 12 月 13 日
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
2013 年 12 月 13 日
Image Analyst
2013 年 12 月 13 日
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
2013 年 12 月 14 日
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
2013 年 12 月 14 日
Like this???
% Find the binary image
binaryImage = grayImage > thresholdValue; % say 200 or something.
% Make those pixels black.
grayImage(binaryImage) = 0;
カテゴリ
ヘルプ センター および File Exchange で Images についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
