Skip to main content

Module morphology

Module morphology 

Source
Expand description

Mathematical morphology: erosion, dilation, opening, closing and hole filling for binary and greyscale images, following scipy.ndimage.

Morphology probes an image with a small shape, the structuring element. Erosion keeps a pixel only if the element, centred there, fits inside the foreground; dilation turns a pixel on if the element touches the foreground. Combinations of the two remove small objects (opening), fill small gaps (closing), and extract outlines and peaks (gradients and top-hats). For greyscale images, “fits inside” becomes a minimum and “touches” a maximum over the element.

See the book entry Morphology, distance transforms and labelling.

Functions§

binary_closing
Closing: dilation then erosion. Fills gaps and holes smaller than the element.
binary_dilation
Binary dilation: a pixel turns on if the reflected structure, centred on it, touches the foreground (SciPy’s binary_dilation).
binary_erosion
Binary erosion: a pixel stays on only if every element of structure, centred on it, lies on the foreground. Pixels beyond the image count as background, so objects touching the edge are eroded from it (SciPy’s binary_erosion with border_value=0). iterations repeats the operation; 0 repeats until the image stops changing.
binary_fill_holes
Fills the holes of a binary image: background regions that cannot be reached from outside the image by steps allowed by structure (the cross gives 4-connected steps, the square 8-connected). A breadth-first search from the background pixels next to the border marks the outside; everything else becomes foreground (SciPy’s binary_fill_holes).
binary_opening
Opening: erosion then dilation. Removes objects (and protrusions) smaller than the element, and leaves larger ones nearly unchanged.
black_tophat
The black top-hat, closing − image: the dark features smaller than the footprint.
cross
The 3 × 3 cross: the four edge neighbours and the centre (4-connectivity; SciPy’s default).
disk
A disc of the given radius, (2r + 1) × (2r + 1).
grey_closing
Greyscale closing (dilation then erosion): removes dark features smaller than the footprint.
grey_dilation
Greyscale dilation: the maximum over the reflected footprint (SciPy’s grey_dilation).
grey_erosion
Greyscale erosion: the minimum over the footprint centred on each pixel (SciPy’s grey_erosion with a flat footprint; the default mode there is Reflect).
grey_opening
Greyscale opening (erosion then dilation): removes bright features smaller than the footprint.
morphological_gradient
The morphological gradient, dilation − erosion: large on edges, zero in flat regions.
square
The full 3 × 3 square (8-connectivity).
white_tophat
The white top-hat, image − opening: the bright features smaller than the footprint, with the background removed.