/Sharpening-Effect

Sharpening image with python

Primary LanguagePython

Sharpening-Effect

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

Tools and Languages:

OpenCV

VS Code

pip

Python


Installation

Use the package manager pip to install cv2 and numpy.

pip install cv2
pip install numpy

Import

Use import keyword to import modules.

import cv2
import numpy as np

Reading image from file

img = cv2.imread("cat.png")

Adding Sharpening effect

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.

Completion message

print('Image Sharpened.')

comparing original vs resized

cv2.imshow('ORIGINAL',img)
cv2.imshow('SHARPEN',sharpened)
cv2.waitKey(0)
cv2.destroyAllWindows()

Images

Original png Sharpened

Developed by

Ashish ku. Behera