Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

data science
communitycreator
unsharp masking

What is unsharp masking?

Eman Kashif

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

widget

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.

widget

Adding the subtracted image to the original image sharpens it by reducing the blur.

widget

Code example

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 libraries
from PIL import Image
import numpy as np
import cv2
import math
#read image
img = cv2.imread('__ed_input.png')
#blur the image using gaussian blur
gaussian = cv2.GaussianBlur(img, (7, 7),0)
#store images as arrays
img=np.asarray(img)
gaussian=np.asarray(gaussian)
#subtract blurred image from original, then add to original
img_unsharp=img+(img-gaussian)
#output unsharp image
cv2.imwrite('output/saved_img.png', img_unsharp)
#convert array to image
img_unsharp=Image.fromarray(img_unsharp)
img_unsharp

RELATED TAGS

data science
communitycreator
unsharp masking

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring