Binary Morphology

Applies morphological operations to binary images. Typically used for noise reduction and shape enhancement in thresholded images.

Inputs

image
A binary image. All non-zero pixels in the input image are regarded as foreground.
operation
The morphological operation to apply to the input.
The size of the morphological mask (a.k.a the structuring element) in world coordinates. If the mask is bigger than the input image, the output image will be filled with zeros.
The shape of the structuring element.
expandBorders
A flag that indicates whether foreground objects on image borders are assumed to expand beyond the edge. Setting this property to true makes the algorithm slower.

Outputs

image
A binary image.
Enumerator

The whole mask is filled with ones. Large masks produce jagged output.

Circle or ellipse, depending on the size of the mask. Produces smooth, round output.

A diamond. A compromise between the others.

Enumerator
Erode

Erosion. Shrinks blobs and completely removes small ones.

Dilate

Dilation. Enlarges blobs.

Open

Erosion followed by dilation. Removes small blobs and juts, and breaks thin connections between blobs.

Close

Dilation followed by erosion. Closes holes in blobs and gaps between blobs.

TopHat

Original minus opened. Leaves only the small elements removed by opening. Also known as the white top-hat transformation.

BottomHat

Closed minus original. Leaves the small elements added by closing. Also known as the black top-hat transformation.