BW2 = bwareafilt(BW,range)
extracts all connected components (objects) from the binary image
BW, where the area of the objects is in the specified
range, producing another binary image
BW2. bwareafilt returns a binary image
BW2 containing only those objects that meet the
criteria.
Number of objects to include when filtering image objects by size,
specified as a numeric scalar.
Data Types: double
keep — Size of objects to include "largest" (default) | "smallest"
Size of objects to include in the output image, specified as
"largest" or "smallest". In the
event of a tie for n-th place,
bwareafilt includes only the first
n objects.
Data Types: char | string
conn — Pixel connectivity 8 (default) | 4 | 3-by-3 matrix of 0s and 1s
Pixel connectivity, specified as one of these values.
Value
Meaning
Two-Dimensional Connectivities
4
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.
Current pixel is shown in gray.
8
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.
Current pixel is shown in gray.
Connectivity can also be defined in a more general way by
specifying a 3-by-3 matrix of 0s and
1s. The 1-valued elements define
neighborhood locations relative to the center element of
conn. The matrix must be symmetric about its center
element.
Filtered image, returned as a binary image of the same size and class as the input image
BW.
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
bwareafilt supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic MATLAB Host Computer
target platform, bwareafilt generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Types of Code Generation Support in Image Processing Toolbox.
The keep argument must be a compile-time
constant.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.