Remove small objects from binary image
BW2 = bwareaopen(BW, P)
BW2 = bwareaopen(BW, P, conn)
BW2 = bwareaopen(BW, P) removes
from a binary image all connected components (objects) that have fewer
P pixels, producing another binary image,
This operation is known as an area opening. The default connectivity
is 8 for two dimensions, 26 for three dimensions, and
'maximal') for higher dimensions.
BW2 = bwareaopen(BW, P, conn) specifies
the desired connectivity.
conn can have any of
the following scalar values.
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
define neighborhood locations relative to the central element of
conn must be symmetric about its central
BW can be a logical or numeric array of any
dimension, and it must be nonsparse. The return value
Remove all objects in the image
fewer than 50 pixels:
BW = imread('text.png'); BW2 = bwareaopen(BW, 50); imshow(BW);