Digital image processing is a significant aspect of data science. It is used in image modification and enhancement to lead to a greater understanding of data.
One aspect of image enhancement is the reduction of image blur, which is how we distinguish between different objects in the image more clearly. The following is a blurry image.
In unsharp masking, a blurred image is subtracted from the original image to get its edges only, and the result is added to the original image to get an enhanced version. For example, subtracting the Gaussian blurred version of the image from the original image gives the following output.
Adding the subtracted image to the original image sharpens it by reducing the blur.
In the example below, you will be prompted to upload an image file to the code widget, which the program will then output as a transformed image.
#import librariesfrom PIL import Imageimport numpy as npimport cv2import math#read imageimg = cv2.imread('__ed_input.png')#blur the image using gaussian blurgaussian = cv2.GaussianBlur(img, (7, 7),0)#store images as arraysimg=np.asarray(img)gaussian=np.asarray(gaussian)#subtract blurred image from original, then add to originalimg_unsharp=img+(img-gaussian)#output unsharp imagecv2.imwrite('output/saved_img.png', img_unsharp)#convert array to imageimg_unsharp=Image.fromarray(img_unsharp)img_unsharp