This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


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)



BW2 = bwpropfilt(BW,attrib,range) extracts all connected components (objects) from a binary image BW that meet the criteria specified by attrib and range. attrib is a string 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. bwpropfilt returns a binary image BW2 containing only those objects that meet the criteria.


BW2 = bwpropfilt(BW,attrib,n) sorts the objects based on the value of the specified property, attrib, returning a binary image that contains only the top n largest objects. In the event of a tie for n-th place, bwpropfilt keeps only the first n objects in BW2.

BW2 = bwpropfilt(BW,attrib,n,keep) sorts the objects based on attrib values, keeping the n largest values if keep is 'largest' (the default) and the n smallest if keep is 'smallest'.

BW2 = bwpropfilt(BW,I,attrib,___) sorts objects based on the intensity values in the grayscale image I and the property attrib.

BW2 = bwpropfilt(BW,___, conn) specifies the desired connectivity. Connectivity can be either 4, 8, or a 3-by-3 matrix of 0s and 1. The 1-valued elements define neighborhood locations relative to the center element of conn and conn must be symmetric about its center element.


collapse all

Read image and display it.

BW = imread('text.png');
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]);
title('Regions with Euler Number == 1')

Read image.

BW = imread('text.png');

Find the ten objects in the image with the largest perimeters and display filtered image.

BW2 = bwpropfilt(BW,'perimeter',10);
title('Objects with the Largest Perimeters')

Input Arguments

collapse all

Image to be filtered, specified as a binary image.

Data Types: logical

Name of attribute on which to filter, specified as one of the following strings or character vectors. For detailed information about these attributes, see regionprops.


If you specify a grayscale image, attrib can have one of these additional values.


Data Types: char | string

Minimum and maximum values of the property inclusive, specified as a 1-by-2 numeric vector of the form [low high].

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Connectivity of objects in the image, specified as the scalar values 4 or 8, or a 3-by-3 matrix of 0s and 1s. 1-valued elements define neighborhood locations relative to the center element of conn, which must be symmetric about its center element.

Data Types: double | logical

Number of object to return, specified as a scalar double.

Data Types: double

Objects to retain, specified as 'largest' or 'smallest'.

Data Types: char

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.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Filtered image, returned as a binary image the same size as BW.

Introduced in R2014b

Was this topic helpful?