Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Can anybody convert gabor formula to code in C#
the following Page explain the formula:
Gabor filter
Posted
Updated 5-Sep-11 11:11am
v2
Comments
Dr.Walt Fair, PE 5-Sep-11 17:11pm    
Fixed format and link.
Dr.Walt Fair, PE 5-Sep-11 17:13pm    
There is a Matlab implementation on the page you linked to. Why don't you just translate it to C#?
X-ahmad 5-Sep-11 17:16pm    
becuse i don't understand matlab
i can emplement code of the formula
but do not now each parameter should have what number
X-ahmad 5-Sep-11 17:17pm    
can U convert turbo C++ to C#.net???
Sergey Alexandrovich Kryukov 5-Sep-11 21:13pm    
Please don't re-post. I gave you the reference to the code you're trying to use, assuming you can translate it. OK, you can't. Don't create a new question, ask follow-up question and use "improve question" on your original page.
--SA

1 solution

I believe this is what you are after.

FAIR WARNING:

- i haven't run thus code
- i had never even heard of MATLAB before reading this question

C#
public IDictionary<Point, double> gaborFn(double sigma, double theta, double lambda, double psi, double gamma)
{
    IDictionary<Point,double> result = new Dictionary<Point,double> ();

    double sigma_x = sigma;
    double sigma_y = sigma/gamma;

    //Bounding box
    int nstds = 3;
    double xmax = Math.Max(Math.Abs(nstds*sigma_x*Math.Cos(theta)),Math.Abs(nstds*sigma_y*Math.Sin(theta)));
    xmax = Math.Ceiling(Math.Max(1,xmax));
    double ymax = Math.Max(Math.Abs(nstds*sigma_x*Math.Sin(theta)),Math.Abs(nstds*sigma_y*Math.Cos(theta)));
    ymax = Math.Ceiling(Math.Max(1,ymax));
    double xmin = -xmax;
    double ymin = -ymax;

    for (int x = (int)xmin; x <=xmax;x++)
    {
        for (int y = (int)ymin; x <= ymax; x++)
        {

            // Rotation
            double x_theta = x * Math.Cos(theta) + y * Math.Sin(theta);
            double y_theta = -x * Math.Sin(theta) + y * Math.Cos(theta);

            double gb = 1 / (2 * Math.PI * sigma_x * sigma_y) * Math.Exp(-.5 * (Math.Pow(x_theta, 2) / Math.Pow(sigma_x, 2) + Math.Pow(y_theta, 2) / Math.Pow(sigma_y, 2))) * Math.Cos(2 * Math.PI / lambda * x_theta + psi);

            result.Add(new Point(x, y), gb);

        }
    }



    return result;
}
 
Share this answer
 
Comments
Mohibur Rashid 5-Sep-11 20:59pm    
huh, even if it work as a program it wont work for the op
GParkings 6-Sep-11 5:01am    
I'm not sure i understand your comment. The above code is the C# equivalent of the MATLAB code in the link provided by the OP. It compiles and, to the best of my knowledge, does what the MATLAB code does.
X-ahmad 6-Sep-11 6:36am    
special Thank For All Freind send Comment To this Topic
Each Person Have Another thought???
Matlab Is SCIENTIFIC language used in MARTIAL Craft.
GParkings 6-Sep-11 6:45am    
I think you might need to elaborate on your question. The above code will generate a dictionary of derived values keyed by point location. If that is not what you need then please explain, clearly, what it is you are after.
X-ahmad 6-Sep-11 13:03pm    
Hi GParkings;i use this algorithm to enhance fingerprint image ridge,
in before use some Formula to calculate exactly teta and lambda From 8 neihangbore of pixel's then Use gabor Filter
if U have a better algorithm Or Offer i Reception it
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900