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.morph(x, kernel, ...)## S3 method for class 'default':
morph(x, kernel, brush = TRUE, eraser = FALSE, value = NULL,
valueNot = NULL, nNeighbours = NULL, nNeighboursNot = NULL, \dots)
x
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 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
.valueNot
if both are specified.nNeighboursNot
if both are specified.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.