convn
N-dimensional convolution of two arrays.
Category: Mathematics > Fourier Analysis and Filtering
Syntax
C = convn(A, B)
Returns the full N-D convolution.
C = convn(A, B, shape)
Returns the 'full', 'same' or 'valid' part.
Description
convn generalizes conv and conv2 to arrays with any number of dimensions, such as volumes or videos. Missing trailing dimensions count as size 1, so a matrix and a vector can be combined.
The cost grows with the product of the two array sizes, so large kernels on large volumes are slow; use fftn for big problems.
Input arguments
A, B- Numeric arrays of any number of dimensions.
shape- Selects the part of the result to keep, as in
conv2.
Output arguments
C- Convolution array. For
'full'its size issize(A)+size(B)-1in every dimension.
Example
3-D box and a smoothing row
C = convn(ones(2,2,2), ones(2,2,2));
size(C)
C(:,:,2)
convn([1 2; 3 4], [1 1], 'same')
Output
ans = 1×3
3 3 3
ans = 3×3
2 4 2
4 8 4
2 4 2
ans = 2×2
3 2
7 4