Filling the region within objects with white

4 views (last 30 days)
I am trying to do background subtraction and the result of one image is displayed here. There are lot of unfilled region in the region of interest.I have used Imfill command in my code. Can someone suggest me how to fill the black region in the region of Interests.
Kindly suggest me some solutions. Thanks in advance.

Accepted Answer

Image Analyst
Image Analyst on 8 Jul 2017
Edited: Image Analyst on 8 Jul 2017
I don't know exactly what "fill the black region in the region of Interests" means. If you want to fill the black regions with black, thus making the white "islands" or "holes" black also (essentially making them disappear), then use bwareafilt() and specify the smallest white blob that you're willing to accept. For example, if you want to remove all blobs smaller than 1000 pixels, do this:
binaryImage = bwareafilt(binaryImage, [1000, inf]);
You could also use bwareaopen().
binaryImage = bwareaopen(binaryImage, 1000);
On the other hand, if you want to remove black holes in white regions, simply use imfill:
binaryImage = imfill(binaryImage, 'holes');
I also don't know what the "region of interest" is in that image. Can you indicate it, perhaps by outlining it in red? If the ROI is only part of the whole image, then you'll need to make a mask somehow, perhaps with poly2mask() or some other method depending on how ROI is defined, then use the mask to erase the non-ROI parts of the image.
binaryImage(~ROIMask) = false; % Erase outside of ROI region(s)
  1 Comment
jeffin
jeffin on 10 Jul 2017
The Small white regions present at the top should be eliminated, while the large region present at the bottom should be filled.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!