bwareaopen
Remove small objects from binary image
Description
Examples
Remove Objects in Image Containing Fewer Than 50 Pixels
Read binary image.
BW = imread('text.png');
Remove objects containing fewer than 50 pixels using bwareaopen
function.
BW2 = bwareaopen(BW, 50);
Display original image next to morphologically opened image.
imshowpair(BW,BW2,'montage')
Input Arguments
BW
— Binary image
logical array | numeric array
Binary image, specified as a logical or numeric array of any dimension.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
P
— Maximum number of pixels in objects
nonnegative integer
Maximum number of pixels in objects, specified as a nonnegative integer.
Example: 50
Data Types: double
conn
— Pixel connectivity
4
| 8
| 6
| 18
| 26
| 3-by-3-by- ... -by-3 matrix of 0
s and
1
s
Pixel connectivity, specified as one of the values in this table. The
default connectivity is 8
for 2-D images, and
26
for 3-D images.
Value | Meaning | |
---|---|---|
Two-Dimensional Connectivities | ||
| 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. |
| 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. |
Three-Dimensional Connectivities | ||
| Pixels are connected if their faces touch. Two adjoining pixels are part of the same object if they are both on and are connected in:
|
Current pixel is center of cube. |
| Pixels are connected if their faces or edges touch. Two adjoining pixels are part of the same object if they are both on and are connected in:
|
Current pixel is center of cube. |
| Pixels are connected if their faces, edges, or corners touch. Two adjoining pixels are part of the same object if they are both on and are connected in:
|
Current pixel is center of cube. |
For higher dimensions, bwareaopen
uses the default
value
.conndef
(ndims(BW),'maximal')
Connectivity can also be
defined in a more general way for any dimension by specifying a 3-by-3-by- ... -by-3 matrix of
0
s and 1
s. The 1
-valued elements
define neighborhood locations relative to the center element of conn
. Note
that conn
must be symmetric about its center element. See Specifying Custom Connectivities for more information.
Data Types: double
| logical
Output Arguments
BW2
— Area-opened image
logical array
Area-opened image, returned as a logical array of the same size as
BW
.
Algorithms
The basic steps are
Determine the connected components:
CC = bwconncomp(BW, conn);
Compute the area of each component:
S = regionprops(CC, 'Area');
Remove small objects:
L = labelmatrix(CC); BW2 = ismember(L, find([S.Area] >= P));
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
bwareaopen
supports the generation of C code (requires MATLAB® Coder™). For more information, see Code Generation for Image Processing.BW
must be a 2-D binary image. N-D arrays are not supported.conn
can only one of the two-dimensional connectivities (4 or 8) or a 3-by-3 matrix. The 3-D connectivities (6, 18, and 26) are not supported. Matrices of size 3-by-3-by-...-by-3 are not supported.conn
must be a compile-time constant.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
BW
must be a 2-D binary image. N-D arrays are not supported.conn
must be one of the two-dimensional connectivities (4 or 8) or a 3-by-3 matrix. The 3-D connectivities (6, 18, and 26) are not supported. Matrices of size 3-by-3-by-...-by-3 are not supported.conn
must be a compile-time constant.
Version History
Introduced before R2006a
See Also
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)