Eroding and dilating images using morphological filters
Erosion and dilation are the most fundamental morphological operators. Therefore, we will present them in this first recipe. The fundamental component in mathematical morphology is the structuring element. A structuring element can be simply defined as a configuration of pixels (the square shape in the following figure) on which an origin is defined (also called an anchor point). Applying a morphological filter consists of probing each pixel of the image using this structuring element. When the origin of the structuring element is aligned with a given pixel, its intersection with the image defines a set of pixels on which a particular morphological operation is applied (the nine shaded pixels in the following figure). In principle, the structuring element can be of any shape, but most often, a simple shape such as a square, circle, or diamond with the origin at the center is used. Custom structuring elements can be useful to emphasize...