Skip to content

Morphological Transform

The Morphological Transform command applies a structural element to reshape regions in an image. It is typically used after thresholding to clean up binary masks before object extraction.

Operations

OperationEffect
ErosionShrinks bright regions; removes thin protrusions and isolated noise pixels
DilationExpands bright regions; fills small holes and gaps
OpeningErosion followed by dilation — removes small bright objects while preserving large ones
ClosingDilation followed by erosion — fills small dark holes while preserving overall shape

Parameters

ParameterDescription
OperationErosion, Dilation, Opening, or Closing
Kernel sizeSide length of the structuring element (pixels)
Kernel shapeBox (square), Cross (plus), or Ellipse (circle/oval)
IterationsNumber of times the operation is repeated (default: 1)
Use greyscaleApply the operation to the greyscale image instead of the binary mask

Kernel shapes

ShapeDescription
BoxAll pixels in a square neighbourhood are included
CrossOnly horizontal and vertical neighbours (plus pattern)
EllipsePixels inside an elliptical boundary; creates circular structuring elements when width = height

Iterations

Running an operation multiple times is equivalent to using a larger effective kernel but can be more efficient. For example, 3 iterations of a 3×3 dilation roughly approximates one pass with a 7×7 structuring element.

When to use

  • Erosion — separate objects that are barely touching; remove single-pixel noise.
  • Dilation — connect small gaps in a detected contour.
  • Opening — remove debris / small artefacts from a binary mask without changing the size of larger objects significantly.
  • Closing — fill small holes inside detected objects.