These functions provide standard mathematical morphology operations, which can be applied to array data with any number of dimensions. Binary and greyscale morphology is supported.

erode(x, kernel)

dilate(x, kernel)

opening(x, kernel)

closing(x, kernel)

Arguments

x

An object that can be coerced to an array, or for which a morph method exists.

kernel

An array representing the kernel to be used. See shapeKernel for functions to generate a suitable kernel.

Value

A morphed array with the same dimensions as the original array.

Details

The erode function uses the kernel as an eraser, centring it on each zero-valued pixel, which has the effect of eroding the extent of nonzero areas. Dilation has the opposite effect, extending the nonzero regions in the array. Opening is an erosion followed by a dilation, and closing is a dilation followed by an erosion, using the same kernel in both cases.

If the kernel has only one unique nonzero value, it is described as ``flat''. For a flat kernel, the erosion is the minimum value of x within the nonzero region of kernel. For a nonflat kernel, this becomes the minimum value of x - kernel. Dilation is the opposite operation, taking the maximum within the kernel.

See also

morph for the function underlying all of these operations, kernels for kernel-generating functions, binarise for binarising an array, and gaussianSmooth for smoothing. The EBImage Bioconductor package also supplies functions to perform these operations, and may be slightly faster, but only works in two dimensions.

Author

Jon Clayden <code@clayden.org>

Examples

x <- c(0,0,1,0,0,0,1,1,1,0,0)
k <- c(1,1,1)
erode(x,k)
#>  [1] 0 0 0 0 0 0 0 1 0 0 0
dilate(x,k)
#>  [1] 0 1 1 1 0 1 1 1 1 1 0