Extract objects from binary image using properties
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, then
attrib can have one of these
range— Minimum and maximum property values
Minimum and maximum property values, specified as a 2-by-1 numeric vector
of the form
n— Number of objects to return
Number of object to return, specified as a positive integer.
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.
conn— Pixel connectivity
4| 3-by-3 matrix of
Pixel connectivity, specified as one of these values.
Pixels are connected if their edges touch. Two adjoining pixels are part of the same object if they are both on and are connected along the horizontal or vertical direction.
Pixels are connected if their edges or corners touch. Two adjoining pixels are part of the same object if they are both on and are connected along the horizontal, vertical, or diagonal direction.
Connectivity can also be defined in a more general way by
specifying a 3-by-3 matrix of
1-valued elements define
neighborhood locations relative to the center element of
conn. The matrix must be symmetric about its center
BW2— Filtered image
Filtered image, returned as a binary image the same size as BW.