Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove blurriness from an image using opencv (python/c++)

I am using opencv to detect person in live video feed. I need to save the image of the person detected. But here the person is not standing and is keeps moving due to which when I am about to save the image, it is saved in very blurry format, just like below image:

As you can see the image is not very clear and has a lot of blurriness into it. Face is also not clear. Is there anyway we can remove the blurriness from image. Thanks

like image 653
S Andrew Avatar asked Oct 04 '19 07:10

S Andrew


People also ask

How do you Unblur an image in Python?

We use sharpen() function to sharpen an image.

How do you sharpen an image in OpenCV Python?

You use a Gaussian smoothing filter and subtract the smoothed version from the original image (in a weighted way so the values of a constant area remain constant). cv::GaussianBlur(frame, image, cv::Size(0, 0), 3); cv::addWeighted(frame, 1.5, image, -0.5, 0, image);

How do you smooth an image in Python?

To smoothen an image with a custom-made kernel we are going to use a function called filter2D() which basically helps us to convolve a custom-made kernel with an image to achieve different image filters like sharpening and blurring and more.


2 Answers

You can try sharpening the image using cv2.filter2D() and a generic sharpening kernel

Here are other sharpening kernels you can experiment with

import cv2
import numpy as np

image = cv2.imread('1.jpg')
sharpen_kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
sharpen = cv2.filter2D(image, -1, sharpen_kernel)

cv2.imshow('sharpen', sharpen)
cv2.waitKey()
like image 73
nathancy Avatar answered Oct 24 '22 11:10

nathancy


As suggested by @nathancy you can try with morhological based operations, this works in all the cases but it requires filter dimension tuning according to image shape, noise level and it also leads to drop in image quality.

Recently, Generative Adversarial Networks (GAN) has also got attention for regenrating the images and seems to be promising in image quality enhancement.

This article(https://medium.com/machine-learning-world/deblur-photos-using-generic-pix2pix-6f8774f9701e) has described a GAN based (based on pixtopix model) solution for image deblurring, this may work for your case too.

like image 26
flamelite Avatar answered Oct 24 '22 11:10

flamelite