morph | R Documentation |
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.
morph(x, kernel, ...) ## Default S3 method: morph(x, kernel, operator = c("+", "-", "*", "i", "1", "0", "=="), merge = c("sum", "min", "max", "mean", "median", "all", "any"), value = NULL, valueNot = NULL, nNeighbours = NULL, nNeighboursNot = NULL, renormalise = TRUE, ...)
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, |
... |
Additional arguments to methods. |
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; |
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 |
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 |
An optional numeric vector giving nonallowable numbers of nonzero neighbours (including diagonal neighbours) for array elements where the kernel will be applied. |
renormalise |
If |
A morphed array with the same dimensions as the original array.
Jon Clayden <code@clayden.org>
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.