Learn R Programming

mmand (version 1.2.0)

morph: Morph an array with a kernel

Description

The morph function applies a kernel 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, operator = c("+", "-", "*", "i", "1", "0"), merge = c("sum", "min", "max", "mean", "median"), value = NULL, valueNot = NULL, nNeighbours = NULL, nNeighboursNot = NULL, ...)

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
operator
The operator applied elementwise within the kernel, as a function of the original image value and the kernel value. Arithmetic operators are as usual; "i" is the identity operator, where every value within the kernel will be included as-is; a
merge
The operator applied to combine the elements into a final value for the centre pixel. All have their usual meanings.
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 morphology 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.