conv2 function

2-D convolution

2-D convolution

Compute the two-dimensional convolution of two matrices.

conv2(a, b, shape = c("full", "same", "valid"))

Arguments

  • a, b: Input matrices, coerced to numeric.

  • shape: Subsection of convolution, partially matched to:

    • "full": Return the full convolution (default)
    • "same": Return the central part of the convolution with the same size as A. The central part of the convolution begins at the indices floor(c(nrow(b), ncol(b)) / 2 + 1)
    • "valid": Return only the parts which do not include zero-padded edges. The size of the result is max(nrow(a) - nrow(a) + 1, 0) by max(ncol(A) - ncol(B) + 1, 0)

Returns

Convolution of input matrices, returned as a matrix.

Examples

a <- matrix(1:16, 4, 4) b <- matrix(1:9, 3,3) cnv <- conv2(a, b) cnv <- conv2(a, b, "same") cnv <- conv2(a, b, "valid")

See Also

conv, convolve

Author(s)

Geert van Boxtel, G.J.M.vanBoxtel@gmail.com .

  • Maintainer: Geert van Boxtel
  • License: GPL-3
  • Last published: 2024-09-11