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’sbinary_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’sbinary_erosionwithborder_value=0).iterationsrepeats the operation;0repeats 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’sbinary_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_erosionwith a flat footprint; the default mode there isReflect). - 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.