3

I want to use OpenCV in C++ to achieve gradual image blur effect, such as the one in this picture:

But i don't know how to do this. I used cvSmooth() function in OpenCV, but can't implement the gradual blur effect I want.

What should I do?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
  • Can you explain a bit more? – Dieter Meemken Jan 12 '17 at 09:47
  • I guess you're talking about GaussianBlur(), unless you're using a (pretty) old verstion of OpenCV. As Dieter says, what's the problem ? – Soltius Jan 12 '17 at 10:23
  • 3
    AFAIK, there is no direct function you can use in Opencv. You will have to write your own. This shouldn't be too hard, just apply a blur on a small set of rows of the image, and incrementally increase the parameter until you reach the bottom of image. – kebs Jan 12 '17 at 11:00
  • you could use gaussian blur with a per-pixel dependend filter-size. But I guess there won't be an efficient implementation for this. – Micka Jan 12 '17 at 13:38

1 Answers1

2

You could use GaussianBlur(). Assuming that you set values of SigmaX and SigmaY parameters to 0, the size of the filter kernel corresponds to the level of smoothing - larger kernel implies smoother image.

Now, you should divide your image into groups of rows (containing 1 or more rows), treat them as separate images and apply GaussianBlur() to each of them, decreasing its kernel size with each consecutive row or a group of rows.
Depending on the result you want to achieve, you have to tune up the parameters such as the initial and final kernel size, how fast the size decreases, number of rows in each group and whether each group of rows is of the same size (e.g. if the kernel at certain iteration is of size NxN, you could apply it to the group of N rows - then the group size would be variable and the top group would contain the highest number of rows). Also, remember to consider image boundaries as special cases.

Note: if you want to apply an NxN filter to an image strip consisting of N rows, you should take a ROI whose size is (2N-1)xN in order to include boundary pixels.

KjMag
  • 2,650
  • 16
  • 16