Binary morphology🔗

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


  • 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.

  • maskSize: 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.

  • maskShape: 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.


  • image: A binary image.

enum Operation🔗

Binary morphology operation types.


enumerator Erode🔗

Erosion. Shrinks blobs and completely removes small ones.

enumerator Dilate🔗

Dilation. Enlarges blobs.

enumerator Open🔗

Erosion followed by dilation.

Removes small blobs and juts, and breaks thin connections between blobs.

enumerator Close🔗

Dilation followed by erosion.

Closes holes in blobs and gaps between blobs.

enumerator TopHat🔗

Original minus opened.

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

enumerator BottomHat🔗

Closed minus original.

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

enum MaskShape🔗

Shapes of morphology masks.


enumerator RectangularMask🔗

The whole mask is filled with ones.

Large masks produce jagged output.

enumerator EllipticalMask🔗

Circle or ellipse, depending on the size of the mask.

Produces smooth, round output.

enumerator DiamondMask🔗

A diamond. A compromise between the others.