How to find the pixels of certain regions in a binary image
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Vishal Neelagiri
2017년 1월 16일
You might want to use the 'bwselect' function to select objects in a binary image. You can use this with the 'bwarea' function which calculates the area of objects in a binary image. You might want to refer to the following documentation links:
https://www.mathworks.com/help/images/labeling-and-measuring-objects-in-a-binary-image.html
https://www.mathworks.com/help/images/ref/bwselect.html
https://www.mathworks.com/help/images/ref/bwarea.html
댓글 수: 0
추가 답변 (1개)
Image Analyst
2017년 1월 16일
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]);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!