Python OpenCV Image Filtering

In this Python OpenCV lesson we are going to learn about Python OpenCV Image Filtering, you can do image filtering using low pass filter (LPF) and high pass filters (HPF). for example if you want to  remove the noises of the image you can use LPF filter or if you want to blur an image you can use  LPF. and using HPF filter you can find the edges in the image. in opencv there is a function
cv2.filter2D() that is used for filtering.

 

 

This is the complete code for this lesson.

 

 

 

In here we are going to create Kernel, and in this example we are going to use a 5 by 5 averaging filter kernel.

 

 

 

And now we are going to use cv2.filter() method from OpenCV for filtering. we need to give some arguments, the first one is the image source, the second one is the ddepth and the third one is the kernel that we have already created.

 

 

 

Because we are going to show our images in Matplotlib, so Matplotlib uses RGB (Red, Green, Blue) color system, and OpenCV uses BGR (Blue, Green, Red) color system, we need to convert the BGR color to RGB. if we don’t do this there will be messed up in the colors.

 

 

 

Run the complete code and this is the result.

Python OpenCV Image Filtering
Python OpenCV Image Filtering

 

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.