Learn R Programming

mmand (version 0.1.2)

kernels: Kernel-generating functions

Description

These functions can be used to generate kernels for morphological or smoothing operations.

Usage

shapeKernel(width, dim = length(width), type = c("box","disc","diamond"),
      brush = TRUE, binary = TRUE, normalised = FALSE)

gaussianKernel(sigma, dim = length(sigma), size = 4*sigma, normalised = TRUE)

Arguments

width
A numeric vector giving the width of the shape in each dimension, in array elements. Does not need to be integer-valued, or equal for all dimensions. Will be recycled to length dim if that parameter is also specified.
sigma
A numeric vector giving the standard deviation of the underlying Gaussian distribution in each dimension, in array elements. Does not need to be equal for all dimensions. Will be recycled to length dim if that parameter is also specified.
dim
An integer value giving the dimensionality of the kernel. Defaults to the length of width or sigma.
size
A numeric vector giving the width of the kernel in each dimension, which will be rounded up to the nearest odd integer. Defaults to four times the corresponding sigma value.
type
A string giving the type of shape to produce. In one dimension, these shapes are all equivalent.
brush
If TRUE, elements of the kernel which are outside the shape will be set to NA, otherwise they will have zero value. This is to ensure appropriate behaviour in morph.
binary
If FALSE, the value of the kernel at each point represents the proportion of the array element within the shape. If TRUE, these values are binarised to be 1 if at least half of the element is within the shape, and 0 otherwise.
normalised
If TRUE, the sum of non-missing elements of the kernel will be unity. Note that this is the default for gaussianKernel, but not for shapeKernel.

Value

  • An array of the requested dimensionality, which can be used as a kernel with morph and related functions.

See Also

morph for general application of kernels to data, erode for mathematical morphology functions, and gaussianSmooth for applying smoothing to data.

Examples

Run this code
shapeKernel(c(3,5), type="diamond")
gaussianKernel(c(0.3,0.3))

Run the code above in your browser using DataLab