3
votes

A basic Google search finds this SO question and what appears to be an excellent answer. When I try, however, it has absolutely no effect on sharpening my blurred image.

Could somebody clarify if I'm doing something completely wrong?

What I've done so far is implement the filter2D function on an image to remove random noise, it also blurs my periodic noise, which is excellent. Now that I've blurred out the noise, I want to sharpen the image to see a less-noisy image than the original image. Here's my code:-

   anchor = Point( -1, -1 );
   delta = 0;
   ddepth = -1;
   dst = frame;
   dst2 = image;

  filter2D(src, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT );

  cv::GaussianBlur(frame, image, cv::Size(0, 0), 11);
  cv::addWeighted(frame, 1.5, image, -0.5, 0, image);

The gaussianblur and addWeighted make NO difference to the image whatsoever. Also, to clarify, there are no code errors at all either.

3
May be problem is in other piece of code, where you overwrite changes, because part cv::GaussianBlur(frame, image, cv::Size(0, 0), 11); cv::addWeighted(frame, 1.5, image, -0.5, 0, image); works. Or your image is so blurred, that you cannot see the difference.old-ufo

3 Answers

12
votes

In order to make it work for a proper image you can check out both the following approches. I did the coding using OpenCV 3.0.0:

import cv2

x = 'Columbia river.jpg'
img = cv2.imread(x, 1)
cv2.imshow("Original",img)

enter image description here

#---Approach 1---
#---Sharpening filter----
kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
im = cv2.filter2D(img, -1, kernel)
cv2.imshow("Sharpening",im)

enter image description here

#---Approach 2---
aw = cv2.addWeighted(img, 4, cv2.blur(img, (30, 30)), -4, 128)
cv2.imshow("Add_weighted", aw)

enter image description here

4
votes

For future readers, the code does work it was just that my image was so blurry, the above code had no visible effect!

1
votes

I think fft deconvolution should be interesting for you: http://web.archive.org/web/20160420171504/http://www.nist.gov/lispix/imlab/FFT/deblur.html

But this algorithm userful if you know blur kernel. If not, then you should google for blind deconvolution algorithm.