High-pass filtering in OpenCV

image-processing, opencv

Solution

There are number of different high-pass filters implemented in opencv. The one you have set for your example is Laplacian:

0  1  0
1 -4  1
0  1  0

You can use the `Laplacian` function of opencv which has the `ksize` parameter. You must be able to apply larger Laplacian kernels by manipulating that parameter.

If you're interested in other high-pass filters, opencv has Canny, Sobel, etc.

Problem

To make a 3x3 high-pass filter kernel in OpenCV, I use the following code (for Android): ``` Mat kernel = new Mat(3, 3, CvType.CV_32FC1); float[] data = {0, -1, 0, -1, 4, -1, 0, -1, 0}; kernel.put(0, 0, data); ``` I then filter using the kernel: ``` Imgproc.filter2D(image, image, -1, kernel); ``` Is there a way to automatically generate larger high-pass kernels in OpenCV?

Original source