Learn R Programming

mmand (version 0.1.2)

morph: Morph an array with a kernel

Description

The morph function applies a kernel, literally or multiplicatively, to a target array. Optionally, applying the kernel to a particular array element can be made conditional on its value, or the number of nonzero immediate neighbours that it has. The morph function is (S3) generic.

Usage

morph(x, kernel, ...)

## S3 method for class 'default': morph(x, kernel, brush = TRUE, eraser = FALSE, value = NULL, valueNot = NULL, nNeighbours = NULL, nNeighboursNot = NULL, \dots)

Arguments

x
Any object. For the default method, this must be coercible to an array.
kernel
An object representing the kernel to be applied, which must be coercible to an array. It must have odd width in all dimensions, but does not have to be isotropic in size. The kernel's dimensionality may be less than that of the target array, x
brush
If TRUE, the kernel is placed into the morphed array literally, centred at each point that meets the specified criteria (unless it is an eraser: see below). If FALSE, the value of the final morphed array at each point is the sum
eraser
If TRUE, the kernel is used as an eraser, so that all nonzero values in the kernel are used to indicate that the corresponding array elements should be set to zero in the morphed array. Ignored if brush is FALSE.
value
An optional vector of values in the target array for which to apply the kernel. Takes priority over valueNot if both are specified.
valueNot
An optional vector of values in the target array for which not to apply the kernel.
nNeighbours
An optional numeric vector giving allowable numbers of nonzero neighbours (including diagonal neighbours) for array elements where the kernel will be applied. Takes priority over nNeighboursNot if both are specified.
nNeighboursNot
An optional numeric vector giving nonallowable numbers of nonzero neighbours (including diagonal neighbours) for array elements where the kernel will be applied.
...
Additional arguments to methods.

Value

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

See Also

kernels for kernel-generating functions, and erode for more specific mathematical morphology functions. gameOfLife shows how this function can be used for non-morphological purposes, in that case to power a cellular automaton. See also the kernel and kernapply functions in the stats package, particularly if you want to smooth time series.