How to fill BLACK a region in an image?

17 ビュー (過去 30 日間)
Steven
Steven 2013 年 12 月 12 日
編集済み: Steven 2016 年 4 月 26 日
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?

採用された回答

Image Analyst
Image Analyst 2013 年 12 月 12 日
It does matter if they're grayscale or binary. You will probably have to use morphology. For example you might need to erode or dilate your binary image so that you don't fill with white. Or you might be able to use logical indexing. Can you post your image so I can recommend a method?

その他の回答 (2 件)

Steven
Steven 2013 年 12 月 12 日
編集済み: Steven 2013 年 12 月 18 日
Hi. Thanks for your reply. Actually by "no matter binary or gray", I meant I may do the filtering (or whatever is needed) in either format. I have attached my picture here. For example, I want to convert the white areas at the left (inside the curve) to black (while the white part at the right side of the whole picture shall be remain white). I hope I can make it clear!
Then, what shall I do? I was thinking of letting the user choose polygons inside the region (left) to make it black, but it is time consuming and we do not know how many times user has to do it. So is it possible for MATLAB to do it automatically?
Thanks so much. Steven
  1 件のコメント
Image Analyst
Image Analyst 2013 年 12 月 12 日
That looks like a binary image. So why is imfill() not working?
filledImage = imfill(binaryImage, 'holes');

サインインしてコメントする。


Walter Roberson
Walter Roberson 2013 年 12 月 13 日
Why not just assign 0 to the roi regions? If they are defined as polygons, then poly2mask() to get the bitmap.
  8 件のコメント
Steven
Steven 2013 年 12 月 14 日
編集済み: Steven 2013 年 12 月 14 日
Hi. Thanks again.
Sure. Actually what I want is exactly the opposite! I want to make "these white holes in the black blob on the left" BLACK! Let me put it this way:
I have an image in which there are some places (some interferences) that are wrongly white (because of photographing errors) and I want to make them black. It is something like the image attached here (it is a part of the original image).
1.How may I do so? Can MATLAB automatically detect them and black them?
2.Also what about the small white point at the right? how can I detect it and black it?
Thanks so much for your time. Steven
Image Analyst
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;

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by