Extract objects from binary image using properties
BW2 = bwpropfilt(BW,attrib,range)
BW2 = bwpropfilt(BW,attrib,n)
BW2 = bwpropfilt(BW,attrib,n,keep)
BW2 = bwpropfilt(BW,I,attrib,___)
BW2 = bwpropfilt(BW,___, conn)
extracts all connected components (objects) from a binary image
BW2 = bwpropfilt(
meet the criteria specified by
attrib is a string scalar or character vector that identifies a particular
property of the objects, such as their area.
range is a 1-by-2 row vector
that specifies the range of values (low and high) of the property.
returns a binary image
BW2 containing only those objects that meet the
Read image and display it.
BW = imread('text.png'); figure imshow(BW) title('Original Image')
Use filtering to create a second image that contains only those regions in the original image that do not have holes. For these regions, the Euler number property is equal to 1. Display filtered image.
BW2 = bwpropfilt(BW,'EulerNumber',[1 1]); figure imshow(BW2) title('Regions with Euler Number == 1')
BW = imread('text.png');
Find the ten objects in the image with the largest perimeters and display filtered image.
BW2 = bwpropfilt(BW,'perimeter',10); figure; imshow(BW2) title('Objects with the Largest Perimeters')
BW— Image to be filtered
Image to be filtered, specified as a binary image.
attrib— Name of attribute on which to filter
Name of attribute on which to filter, specified as one of the following values. For detailed
information about these attributes, see
If you specify a grayscale image,
have one of these additional values.
range— Minimum and maximum values of the property inclusive
Minimum and maximum values of the property inclusive, specified
as a 1-by-2 numeric vector of the form
conn— Connectivity of objects
Connectivity of objects in the image, specified as the scalar
8, or a 3-by-3 matrix
elements define neighborhood locations relative to the center element
conn, which must be symmetric about its center
n— Number of objects to return
Number of object to return, specified as a scalar
keep— Objects to retain
Objects to retain, specified as
I— Marker image
Marker image, specified as a grayscale image, the same size as the input binary image. Intensity values in the grayscale image define regions in the input binary image.
BW2— Filtered image
Filtered image, returned as a binary image the same size as BW.