cv.filter2D - MATLAB File Help
cv.filter2D

Convolves an image with the kernel

dst = cv.filter2D(src, kernel)
dst = cv.filter2D(src, kernel, 'OptionName',optionValue, ...)

Input

Output

Options

The 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.

See also