Products & Services Solutions Academia Support User Community Company

Learn more about Image Processing Toolbox   

bwareaopen - Morphologically open binary image (remove small objects)

Syntax

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

Description

BW2 = bwareaopen(BW, P) removes from a binary image all connected components (objects) that have fewer than P pixels, 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.

BW2 = bwareaopen(BW, P, conn) specifies the desired connectivity. conn can have any of the following scalar values.

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 be defined in a more general way for any dimension by using for conn 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.

Class Support

BW can be a logical or numeric array of any dimension, and it must be nonsparse. The return value BW2 is of class logical.

Algorithm

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:

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

Examples

Remove all objects in the image text.png containing fewer than 50 pixels:

    BW = imread('text.png');
    BW2 = bwareaopen(BW, 50);
    imshow(BW);

figure, imshow(BW2)

See Also

bwconncomp, conndef

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS