Filling the region within objects with white
조회 수: 4 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Image Analyst
2017년 7월 8일
편집: Image Analyst
2017년 7월 8일
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)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!