Sharpening an image is a very basic method of image processing. In principle, image sharpening consists
of adding to the original image a signal that is proportional to a high-pass filtered version of the original image
Use the package manager pip to install cv2 and numpy.
pip install cv2
pip install numpy
Use import keyword to import modules.
import cv2
import numpy as np
img = cv2.imread("cat.png")
Image sharpening refers to any enhancement technique that highlights edges and,
fine details in an image.
Image sharpening is widely used in printing and photographic industries for increasing
the local contrast and sharpening the images.
kernel_sharpening = np.array([[-1,-1,-1],
[-1, 9,-1],
[-1,-1,-1]])
Above we are adding a kernel enabled with an array of values used to normalize the pixel values.
You can play with the values we have entered to change the amount of sharpening.
sharpened = cv2.filter2D(img,-1,kernel_sharpening)
Here we used cv2.filter2D( ) function in order to produce our sharpen image. Here the kernel and
input image are filtered.
This function takes 3 args input image , Desired depth & kernel values.
print('Image Sharpened.')
cv2.imshow('ORIGINAL',img)
cv2.imshow('SHARPEN',sharpened)
cv2.waitKey(0)
cv2.destroyAllWindows()