views:

323

answers:

3

I am doing some image processing code in C#, but I cant use any libraries or GNU like code.

The UnsharpMask function depends on Gaussian blur which in turn depends on Fourier Transforms. I wrote code for all this and things are working, but to make a long story short, I need to remove the FFT functions. Is there any way to perform unsharp mask in another way that perhaps does not need FFT?

+3  A: 

The Fourier transform part of a Gaussian blur is just an efficient way of doing the convolution with a Gaussian kernel. You can do it using straight forward convolution with a Gaussian kernel of the appropriate standard deviation and size (an odd size kernel around 5-6 times the standard deviation is about right).

See Convolution on Wikipedia.

Adam Bowen
Good answer. You are exchanging a O(n ln n) algorithm for a O (n*n) algorithm (direct convolution)- so smoothing 2D images with direct convolution will be significantly slower. You could copy the FFT algorithm from Numerical Recipes pretty easily if speed becomes an issue.
Paul
I believe the NR code isn't free for commercial use (although the op doesn't specify I guess if GNU code is a problem the NR licence might be as well).
Adam Bowen
A: 

I believe that even if you can't use any libraries or GNU thingy, you can look at their implementation and try to reproduce similar code for your requirements ?

openCV function list. check out the function details here and then the implementation details in the header files. http://opencv.willowgarage.com/documentation/genindex.html

Also if you are interested in C# based implementation I would suggest the following http://aforgenet.com/framework/

Egon
openCV may work. Aforge is LGPL which I cant use. Also, I noticed that the Gauss blur in The Gimp does not appear to be using FFT:http://git.gnome.org/browse/gimp/tree/plug-ins/common/blur-gauss.c
Jono
+1  A: 

I found a solution to fit my needs.

I tried several quick and dirty blurring algorithms and found both Box Blur and Stack Blur to be sufficient. Stack Blur has a cleaner blur then Box Blur and is several times faster then Gaussian. So I can use either one in place of Gaussian.

So now I can get rid of all the FFT code mess and replace it with something much more manageable. This solution might not be for everyone, but since UnsharpMask is based on blurring, I did not feel that it was too exact of a science.

By the way Gimp's Gaussian blur seems to be avoiding FFTs as well.

Jono
I've often used box blur twice or even thrice to get a fast rough form of blurring when I needed to unsharp large numbers of images automatically.
DarenW