I want to use unsharp mask
on a 16 Bit Image.
The Image has 640 x 480 Pixels
and is saved in a NumPy array.
I have done the following:
Gaussian filter
(three different methods)WightFaktor
to the original ImageBut it doesn´t really work.
Here is the Python code:
Gaussian1 = ndimage.filters.gaussian_filter(Image,sigma=10.0)
Gaussian2 = filters.gaussian_filter(Image,sigma=10.0)
Gaussian3 = cv2.GaussianBlur(Image,(9,9),sigmaX=10.0)
Mask1 = Image - Gaussian1
UnsharpImage = Image + (WightFaktor*Mask1)
The Unsharp Mask increases the image contrast along the edges of objects in a photo. The effect doesn't actually detect edges, but it can identify pixel values that differ from their neighboring pixels by a certain amount.
The Sharpening Tool is like using a hammer to sharpen. There is no fine control. The Unsharp Mask Tool give fine control. It finds the edges of the different tones and increases contrast to make the image appear sharper.
When k= 1 this is known as Unsharp masking. For k>1 we call this as high-boost filtering because we are boosting the high-frequency components by giving more weight to the masked (edge) image. We can also write the above two equations into one as the weighted average of the original and the blurred image.
To get an unsharp image using OpenCV
you need to use the addWeighted function as follows:
import cv2
image = cv2.imread("example.jpg")
gaussian_3 = cv2.GaussianBlur(image, (0, 0), 2.0)
unsharp_image = cv2.addWeighted(image, 2.0, gaussian_3, -1.0, 0)
cv2.imwrite("example_unsharp.jpg", unsharp_image)
Giving the following kind of result:
addWeighted()
is used here as follows:
dst = cv2.addWeighted(src1, alpha, src2, beta, gamma)
Giving you the following transformation:
dst = src1*alpha + src2*beta + gamma
The strength of the effect can be altered by adjusting the alpha
and beta
weightings, for example: 1.5
and -0.5
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With