Mathematical morphology (source code)

= Mathematical morphology

<Mathematical morphology> studies shape-transforming operations defined through a chosen <structuring element>. For foreground <pixels> represented as a set $A$ and a finite <structuring element>[footprint] $B$, <morphological dilation> is
$$
A\oplus B=\{a+b:a\in A,\ b\in B\},
$$
while <morphological erosion> is $A\ominus B=\{x:x+B\subseteq A\}$. <morphological dilation>[Dilation] adds <structuring element>[footprint] translates around the foreground; <morphological erosion>[erosion] retains placements whose entire <structuring element>[footprint] fits.

For a one-dimensional example, $A=\{0,1,2\}$ and $B=\{0,1\}$ give <morphological dilation>[dilation] $\{0,1,2,3\}$ and <morphological erosion>[erosion] $\{0,1\}$. <Morphological opening>, <morphological erosion>[erosion] followed by <morphological dilation>[dilation] with the same <structuring element>[footprint], removes an isolated set $\{0,2\}$ for that <structuring element>[footprint] because neither placement contains two consecutive points. <grayscale> variants use local minima and maxima rather than binary membership. The <structuring element>[footprint] and boundary conventions determine the exact operation.<Morphological Filtering in the scikit-image documentation>[Erosion, Dilation and Opening]{ref}