Documentation

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.

bwareaopen

Remove small objects from binary image

Syntax

BW2 = bwareaopen(BW,P)
BW2 = bwareaopen(BW,P,conn)

Description

example

BW2 = bwareaopen(BW,P) removes all connected components (objects) that have fewer than P pixels from the binary image BW, producing another binary image, BW2. The default connectivity is 8 for two dimensions, 26 for three dimensions, and conndef(ndims(BW), 'maximal') for higher dimensions. This operation is known as an area opening.

BW2 = bwareaopen(BW,P,conn) removes all connected components, where conn specifies the desired connectivity.

Examples

collapse all

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

collapse all

Binary image, specified as a nonsparse, logical or numeric array of any dimension.

Example: BW2 = bwareaopen(BW, 50);

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

Maximum number of pixels in objects, specified as a nonnegative, integer-valued, numeric scalar.

Example: BW2 = bwareaopen(BW, 50);

Data Types: double

Connectivity, specified as one of the following numeric scalars:

Value

Meaning

Two-dimensional connectivities

4

4-connected neighborhood

8

8-connected neighborhood

Three-dimensional connectivities

6

6-connected neighborhood

18

18-connected neighborhood

26

26-connected neighborhood

Connectivity can also be defined in a more general way for any dimension by specifying a 3-by-3-by-...-by-3 matrix of 0s and 1s. The 1-valued elements define neighborhood locations relative to the central element of conn. Note that conn must be symmetric about its central element.

Example: BW2 = bwareaopen(BW, 50, 4);

Data Types: double | logical

Output Arguments

collapse all

Image that has been morphologically opened, specified as a nonsparse, logical array the same size as BW.

Algorithms

The basic steps are

  1. Determine the connected components:

    CC = bwconncomp(BW, conn);
  2. Compute the area of each component:

    S = regionprops(CC, 'Area');
  3. Remove small objects:

    L = labelmatrix(CC);
    BW2 = ismember(L, find([S.Area] >= P));
    

Extended Capabilities

Introduced before R2006a

Was this topic helpful?