本文介绍了如何实现渐变高斯模糊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

家伙,我想实现渐变高斯模糊效果。按渐变,我的意思是与Photoshop相同的效果。以下面的图片为例:





图片的模糊度随着y坐标的增加而减小(以左上角为原点)。



我知道如何使用内核和FFT来实现正常的guassian模糊,但我不知道如何改变y坐标变化的模糊度。我试图将图像拆分成不同的线(在y轴方向),并应用不同的内核到这些块,但效果是相当恼人的这些线的联合部分。



我也尝试过逐个计算结果像素,并在运行时填充内核,效果相当不错,但算法太简单!!



那么我想知道如何实现一个快速渐变高斯模糊算法?



p>

解决方案

模糊是2D操作,很难在每行中处理具有不同模糊程度的行方式。在考虑高斯模糊之前,我建议探索一个盒子模糊的解决方案,在视觉上难以区分与高斯模糊。



一种方法是使用。自己创建它是一个很好的练习,它是非常简单:积分图像的大小与原始图像相同。内容是当前像素上方和左侧的所有像素强度的总和(我们分别讨论每个rgb通道)。构建一个Integral图像的简单迭代方法是使用以下公式:

  I(x,y)= Gray y)+ I(x-1,y)+ I(x,y-1)-I(x-1,y-1)

提示:如果你首先计算一个时间数组,你可以更快地做到这一点,每个元素只是在同一行的左边加上强度。



积分图像的优点是它们允许在固定时间内在任意大小的窗口中计算总和。事实上,这只需要4个操作:对于x1,y1,x2,y2和积分图像I(x,y)的窗口

  sum(x1,y1,x2,y2)= I(x2,y2)+ I(x1,y1)-I(x1,y2)-I(x2,y1)

因此你可以实现一个快速的模糊盒滤镜(你不会看到盒和高斯滤镜效果之间的区别视觉上)

$ b(x,y,sz)= I(x + sz,y + sz)+ I(x,y) sz,y)-I(x,y + sz)/ [sz * sz]



现在需要做的是将你的快速模糊操作应用到所有像素,改变sz作为y的函数。它只需要4 * w * h的操作;构建你的积分图像也是O(h * w)所以你实际上可以在线性时间做。为每个通道单独做它,并将它们组合在一个新的rgb。



最后,积分图像计算是哈尔框过滤器(而不是小波或Gabors)用于快速检测面部或对象,跟踪等的基础。他们的速度是允许现在实时查找面孔,所以他们值得学习。


guys, I want to implement the gradient gaussian blur effect. By gradient, I mean the same effect as Photoshop. Take the following image as an example:

The blurriness of the image reduces as the y coordinate increases (take the top-left point as origin).

I know how to use kernel and FFT to implement normal guassian blur, but I don't know how to change the degree on blurriness with the change of y coordinate. I've tried to split the image into different lines (in the direction of y-axis) and apply different kernel to these blocks, but the effect is quite annoying in the joint part of these lines.

I've also tried the calculate the result pixel one by one, and fill the kernel on the run, the effect is quite good, but the algorithm is simply too slow!!

So I wonder how to implement a fast gradient gaussian blur algorithm?

Big thanks!

解决方案

The blur is 2D operation and it is hard to handle row-wise with different degree of blur in each row. Before considering Gaussian blur I recommend to explore a box blur solution that is visually hardly distinguishable from the Gaussian one.

A way to go is to use an Integral image. Creating it yourself is a good exercise and it is really simple: the size of the integral image is the same as your original image. The content is a sum of all pixel intensities above and to the left of a current pixel (we talk about each rgb channel separately). A simple iterative way to build an Integral image is to use this formula:

I(x,y)= Gray(x, y) + I(x-1, y) + I(x, y-1) - I(x-1, y-1)

A tip: you can do it even quicker if you first calculate a temporal array where each element just sums intensities to the left of it in the same row.

The beauty of integral images is that they allow to calculate the sum in a window of arbitrary size in constant time. In fact, this just require 4 operations: for a window at x1, y1, x2, y2 and integral image I(x, y)

sum(x1, y1, x2, y2) = I(x2, y2)+I(x1, y1)-I(x1, y2)-I(x2, y1)

Thus you can implement a fast blur box filter (you won’t see the difference between box and Gaussian filter effects visually)

Iblur(x, y, sz) = I(x+sz, y+sz)+I(x, y)-I(x+sz, y)-I(x, y+sz)/[sz*sz]

All you need to do now is to apply your fast blur operation to all your pixels varying sz as a function of y. It will take only 4*w*h operations; building your integral image is also O(h*w) so you actually can do it in the linear time. Do it for each channel separately and combine them in a new rgb.

Finally, integral image calculation is the basis for Haar box filters (instead of wavelets or Gabors) for fast detection of faces or objects, tracking, etc. Their speed is what allows finding faces in real-time nowadays so they are worth studying.

这篇关于如何实现渐变高斯模糊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:13