Sign in to follow this  
51mon

gaussian blur

Recommended Posts

When doing a 7x7 kernel, two-pass gaussian blur, what weights should I use? It is based on the standard normal distribution, right? f(z) = 1 / (2*pi) * e^(-z^2/2), in my case would that mean that z has the domain [-3, 3]? Should I account the fact that the function has unlimited range? [Edited by - 51mon on May 2, 2007 12:25:27 PM]

Share this post


Link to post
Share on other sites
I'm trying to implement a Gaussian blur myself, any chance someone can go into a little more depth with regard on how the technique works? Figure this thread is a good place to ask instead of starting a new one.

From what I've read it seems you take the nearest neighbors to a pixel and use certain weights to blend each pixel (which I assume is what "1/64, 6/64, 15/64, 20/64, 15/64, 6/64, 1/64" is, approximate weight values).

I'm not sure how you would separate it into a vertical pass and a horizontal pass thought.

Share this post


Link to post
Share on other sites
Here's a pretty good article on how convolution works
http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip-Convolut-2.html

A gaussian blur is convolution with a gaussian (aka normal-) distribution kernel.

A nice example of how you can separate the convolution into a horizontal and vertical pass can be found here:

http://www.ogre3d.org/wiki/index.php/Faking_HDR

Share this post


Link to post
Share on other sites
Quote:
Original post by Harry Hunt
Here's a pretty good article on how convolution works
http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip-Convolut-2.html

A gaussian blur is convolution with a gaussian (aka normal-) distribution kernel.

A nice example of how you can separate the convolution into a horizontal and vertical pass can be found here:

http://www.ogre3d.org/wiki/index.php/Faking_HDR


First, Thanks to you and TheAdmiral for the reply.

Now, is it just me or is there absolutely no difference between the Horizontal and vertical passes they show on that site?

I think where I'm having trouble is how I should go about laying this out in my pixel shader. Obviously I have some array of values that represent weights, and I assume the logic is something like

sum = pixel[x-1][y] * weight[0] + pixel[x][y] * weight[1] + pixel[x+1][y] * weight[2] ...

pixel[x][y] = sum/TotalBlended

Do I have the correct idea?

EDIT: I see the difference between the two passes now, they just added the yxzw swizzle.

Share this post


Link to post
Share on other sites
Yes, that's the idea, but you don't need to to divide by the total number of samples (in fact, you shouldn't). The kernel takes care of weighting the pixels - all you need to do is multiply the pixels by the weights and sum the results, kind of like an n-dimensional dot-product.

Admiral

Share this post


Link to post
Share on other sites
In general you need to divide by the sum of the weights of your kernel within the footprint - sometimes the EE people call this the volume of the kernel. However the since the weights used by TheAdmiral sums to 1 you can avoid the divide. You are right about it being an approximation since Gaussian kernel has infinite support. But it should work for you. The two-pass separable transform save many texture fetches and instructions. Instead of order k^2 it is order k.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this