Border Padding for Morphology
Morphological functions position the origin of the structuring element, its center element, over the pixel of interest in the input image. For pixels at the edge of an image, parts of the neighborhood defined by the structuring element can extend past the border of the image.
To process border pixels, the morphological functions assign a value to these undefined pixels, as if the functions had padded the image with additional rows and columns. The value of these padding pixels varies for dilation and erosion operations. The table describes the padding rules for dilation and erosion for both binary and grayscale images.
Rules for Padding Images
Pixels beyond the image border are assigned the minimum value afforded by the data type.
For binary images, these
pixels are assumed to be set to 0. For grayscale images, the minimum
Pixels beyond the image border are assigned the maximum value afforded by the data type.
For binary images, these pixels are assumed to be
By using the minimum value for dilation operations and the maximum value for erosion operations, the toolbox avoids border effects, where regions near the borders of the output image do not appear to be homogeneous with the rest of the image. For example, if erosion padded with a minimum value, eroding an image would result in a black border around the edge of the output image.