How to find the pixels of certain regions in a binary image
Show older comments
I have created a binary image which contains the edges of an image. I want to keep only the pixels of the regions that have an area bigger than 250 pixels. How can I do that?
Accepted Answer
More Answers (1)
Image Analyst
on 16 Jan 2017
Don't use bwselect(), use bwareaopen. It does exactly what you asked for. From the help:
BW2 = bwareaopen(BW,P) removes all connected components (objects) that have fewer than P pixels from the binary image BW, producing another binary image, BW2.
Here is what you'd do:
% Extract only those blobs with 251 pixels or more.
% Blobs 250 and smaller will be removed.
binaryImage = bwareaopen(binaryImage, 251);
You might also be interested in bwareafilt() which extracts the N largest or smallest blobs, or blobs within a specified range of areas. It can also do what you want.
binaryImage = bwareafilt(binaryImage, [251, inf]);
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!