cv.filter2D - MATLAB File Help |
Convolves an image with the kernel
dst = cv.filter2D(src, kernel)
dst = cv.filter2D(src, kernel, 'OptionName',optionValue, ...)
src
.DDepth=-1
, the output image will have the same depth as the source.
The following combinations are supported:
SDepth = uint8 --> DDepth = -1, int16, single, double
SDepth = uint16, int16 --> DDepth = -1, single, double
SDepth = single --> DDepth = -1, single, double
SDepth = double --> DDepth = -1, double
dst
. Default 0The function applies an arbitrary linear filter to an image. When the aperture is partially outside the image, the function interpolates outlier pixel values according to the specified border mode.
The function does actually compute correlation, not the convolution:
dst(x,y) = sum_{0 <= xp <= size(kernel,2), 0 <= yp <= size(kernel,1)}
kernel(xp,yp) * src(x + xp - anchor(1), y + yp - anchor(2))
That is, the kernel is not mirrored around the anchor point. If you need a
real convolution, flip the kernel using cv.flip and set the new anchor to
(size(kernel,2) - anchor(1) - 1, size(kernel,1) - anchor(2) - 1)
.
The function uses the DFT-based algorithm in case of sufficiently large
kernels (~11x11
or larger) and the direct algorithm for small kernels.