How to do it...

Perform the following steps:

  1. Import the packages:
import math
import cv2
import numpy as np
import matplotlib.pyplot as plt
  1. Read the test image:
image = cv2.imread('../data/Lena.png')
  1. Create an 11x11 sharpening kernel:
KSIZE = 11
ALPHA = 2

kernel = cv2.getGaussianKernel(KSIZE, 0)
kernel = -ALPHA * kernel @ kernel.T
kernel[KSIZE//2, KSIZE//2] += 1 + ALPHA
  1. Filter the image using the kernel we just created:
filtered = cv2.filter2D(image, -1, kernel)
  1. Visualize the results:
plt.figure(figsize=(8,4))
plt.subplot(121)
plt.axis('off')
plt.title('image')
plt.imshow(image[:, :, [2, 1, 0]])
plt.subplot(122)
plt.axis('off')
plt.title('filtered')
plt.imshow(filtered[:, :, [2, 1, 0]])
plt.tight_layout(True)
plt.show()