Jump to content

What Gaussian blur algorithm is used in Adobe Photoshop?


Recommended Posts

I'm doing some graphics programming here for fun, so I wrote an

implementation of gaussian blur algorithm. The thing is, no matter

what I do I can't make it run faster than N^2 w.r.t. the length of

convolution vector. The larger the radius the longer the vector, and

with a large radius (say, 5) it takes up to 15 times longer for my

code to blur a 6MP image than the same thing done in Photoshop - 15

seconds instead of one second.

 

One thing I've also noticed about Photoshop is that the speed of its

blur algorithm doesn't depend on the length of convolution vector

all that much. My algorithm is straight convolution, I do dozens of

integer multiplications for each pixel.

 

So the question is, where can I find a description of a faster

algorithm?

Link to comment
Share on other sites

The question is a bit incorrect. I know of at least one algorithm that should give me "Photoshop speed" - it uses FFT, and as such is a huge pain in the butt to write. What I really want to know is if there are any clever simple and fast algorithms for one-dimensional convolution.
Link to comment
Share on other sites

I can't specifically answer your question, but Paint Shop Pro used to have a slow algorithm (Version 7 and earlier), while Version 8 has a fast algorithm. Most likely someone spent a while programming this (I don't think they will give you the code).
Link to comment
Share on other sites

The first thing you should know about the Gaussian Blur is that it is separable and is this means it can be computed in O(n) time rather than in O(n^2) time. In general 2-D symmetric convolution kernels are not separable. To do this you compute the 1-D Gaussian blur in the x dirextion and then do it in the y direction. This is the big secret. The next big speedup is likely to involve redesiging this algorithm based upon memory and optimal assembly language implementation. I remember reading that MMX made for a speadup in the Gaussian blur.

 

But it is the separable part that gets you into linear time.

 

my $0.02,

 

Sean

Link to comment
Share on other sites

I've already been doing two separate 1D convolutions, the numbers I've provided above are for this method.

 

After a bit of googling, I've found two algorithms that can do the trick. One of them is just a simple recursive digital filter. Another is based on finite-state machines (resembles filtering, too).

 

I'm going to try the recursive digital filter as it seems to be the fastest approach yielding pretty decent accuracy.

Link to comment
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
×
×
  • Create New...