Remove unwanted small and connected regions in the image
49 次查看(过去 30 天)
显示 更早的评论
Hi everybody,
I need to extract small connected regions in the image . Is there a solution to this problem?
0 个评论
回答(2 个)
Image Analyst
2023-11-21
I know you accepted the other answer but I don't think it's right. It assumes you want to "count connected components in a binary image" however what you actually said is that you want to "Remove unwanted small and connected regions".
To remove small regions, bwconncomp actually won't do the job as the answer suggested. It does not remove blobs, it just labels them. To actually remove them you'd want bwareaopen. You could also use bwareafilt if you want to specify a range of sizes to accept or reject, or specify a number of blobs to keep. Below are some examples:
mask = bwareaopen(mask, 10); % Keep only blobs with an area of 10 pixels or more.
mask = bwareafilt(mask, [10, 500]); % Keep only blobs with an area of 10 pixels to 500 pixels.
mask = bwareafilt(mask, 3); % Keep the 3 largest blobs ONLY.
3 个评论
Image Analyst
2023-11-22
% finding connected components in binary image
output_struc = bwconncomp(image)
do that? It doesn't. It doesn't remove anything, much less the blobs you wanted to remove. But whatever, I guess since you accepted it you somehow figured it out.
To find out how to extract regions based on multiple measurements, see my Image Segmentation Tutorial
For example you might want to remove blobs based on both the aspect ratio and the area to get rid of roundish blobs but leave stick-like blobs.
By the way, the complicated code you gave in your last comment could be done more simply as
largestBlob = bwareafilt(Image, 1); % Extract largest blob only.
imshow(largestBlob);
Yash
2023-11-21
Hey Mary,
Since you have provided a binary image in the problem, I understand you want a workaround to find and count connected components in a binary image. For this you can try using the 'bwconncomp' function from the Image Processing Toolbox in MATLAB.
% finding connected components in binary image
output_struc = bwconncomp(image)
The function bwconncomp(image) identifies and counts the connected components in the binary image given the input 'image'. The output from this function includes the total number of connected components, which are essentially regions of interest (ROIs), and the pixel indices associated with each component.
To know more about this function, you can refer to its documentation here: https://in.mathworks.com/help/images/ref/bwconncomp.html
Hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!