morph: Morph an array with a kernel

morphR Documentation

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, ...)

## 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, ...)

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. See kernels for kernel-generating functions.

...

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; "i" is the identity operator, where every value within the kernel will be included as-is; "1" and "0" include a 1 or 0 for each element within the kernel's nonzero region; "==" produces a 1 where the image matches the kernel, and 0 elsewhere.

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.

renormalise

If TRUE, the default, and merge is "sum", the sum will be renormalised relative to the sum over the visited part of the kernel. This avoids low-intensity bands around the edges of a morphed image.

Value

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

Author(s)

Jon Clayden <code@clayden.org>

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.


mmand documentation built on Feb. 16, 2023, 9:22 p.m.