In this section, we are going to tackle how to blur and sharpen images, applying both several filters and custom-made kernels. Additionally, we will look at some common kernels that we can use to perform other image-processing functionalities.
Image filtering
Applying arbitrary kernels
OpenCV provides the cv2.filter2D() function in order to apply an arbitrary kernel to an image, convolving the image with the provided kernel. In order to see how this function works, we should first build the kernel that we will use later. In this case, a 5 x 5 kernel will be used, as shown in the following code:
kernel_averaging_5_5 = np.array([[0.04, 0.04, 0.04, 0.04, 0.04], [0.04, 0.04, 0.04, 0.04, 0.04], [0.04, 0.04, 0.04, 0.04, 0.04],...