The filter that we will use here is called the Sobel filter. It is said to be a directional filter, because it only affects the vertical or the horizontal image frequencies depending on which kernel of the filter is used. OpenCV has a function that applies the Sobel operator on an image. The following steps will help us to apply the filters as follows:
- To apply a Sobel operator in the horizontal direction, we have to use the following function and parameters:
cv::Sobel(image, // input sobelX, // output CV_8U, // image type 1, 0, // kernel specification 3, // size of the square kernel 0.4, 128); // scale and offset
- Vertical filtering is achieved by the following call (which is very similar to the horizontal filter):