Arbitrary filtering

OpenCV supports the application of arbitrary filters on images by using the filter2D function. This function is capable of creating the result of many algorithms we already learned, but it requires a kernel matrix to be provided. This function simply convolves the whole image with the given kernel matrix. Here's an example of applying an arbitrary filter on an image:

int ddepth = -1; 
Mat kernel{+1, -1, +1, 
           -1, +2, -1, 
           +1, -1, +1}; 
Point anchor(-1, -1); 
double delta = 0.0; 
BorderTypes borderType = BORDER_DEFAULT; 
filter2D(image, 
         result, 
         ddepth, 
         kernel, 
         anchor, 
         delta, 
         borderType); 

Here is the result of this arbitrary filter. You can see the original image on the left, and the result of the filtering operation on the right-hand side:

There is absolutely no limit to the number of possible filters you can create and use using the filter2D function. Make sure you try different kernel matrices and experiment with the filter2D function. You can also search online for popular filter kernel matrices and apply them using the filter2D function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.71.115