Gabor filter on an image
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Gabor filter on an image

  1. #1
    Join Date
    Aug 2011
    Posts
    16

    Gabor filter on an image

    Hi guys,

    I am currently trying to code gabor filter, and to apply it to an image. My firsts results are really strange (so they're wrong I think), because all outputs values are close to zero (around 10^(-100)). I'm using the opencv lib for c# : emgu.

    here is my code :


    private double[,] Gabor(Bitmap image, int h, int w, double[,] freq, double[,] resOrientation)
    {
    double[,] gaborVal = new double[h,w];
    int filterSize = 11;
    double gaborFiltre;

    for (int i = filterSize / 2; i < h - filterSize / 2; i++)
    {
    for (int j = filterSize / 2; j < w - filterSize / 2; j++)
    {
    if (freq[i, j] > 0)
    {
    gaborFiltre = calculGabor(i, j, resOrientation[i, j], freq[i, j]);

    gaborVal[i, j] = GaborSum(image, i, j, filterSize, gaborFiltre);
    }

    }
    }
    return gaborVal;
    }

    private double calculGabor(int x, int y, double Orientation, double Frequency)
    {
    double xtheta = Math.Pow(x * Math.Cos(Orientation) + y * Math.Sin(Orientation), 2);
    double ytheta = Math.Pow(-x * Math.Sin(Orientation) + y * Math.Cos(Orientation), 2);
    int deltax = (int)Math.Pow(2,2);
    int deltay = (int)Math.Pow(2,2);

    double valueGabor = (1/(deltax*deltay*2*Math.PI)) * Math.Exp(-0.5*(xtheta / deltax + ytheta / deltay)) * Math.Cos(2 * Math.PI * Frequency * Math.Pow(xtheta, 0.5));

    return valueGabor;
    }

    private double GaborSum(Bitmap image, int x, int y, int filterSize, double filtre)
    {
    double resGaborSum = 0;

    for (int u = -filterSize / 2; u < filterSize / 2; u++)
    {
    for (int v = -filterSize / 2; v < filterSize / 2; v++)
    {
    resGaborSum += filtre * (255 - image.GetPixel(y-u,x-u).R);
    }
    }
    return resGaborSum;
    }


    freq and resOrientation arrays are arrays that contain frequency values and orientation values for each pixel of the image. they are good (I've completed lots of tests to check them).

    Can anyone tells me if having this very, very little output values is normal ? and is yes, what does these values represent ??
    If no, what's wrong in my code ? (im aware that it's not the nicest code ever, but maybe 'im missing something important)

    thanks !!

  2. #2
    Join Date
    Aug 2011
    Posts
    16

    Re: Gabor filter on an image

    I am using .net 3.5 !

    I just noticed that I was calculating my 'valueGabor' at the wrong place. it's now in the gaborSum method, inside the double for loop. My result seems to be better, but stilll wrong (values approximately between -1000 and 1000).

    Can anyone tells me why this kind of result, and/or what should I do to have a correct output image ?

    Thanks

  3. #3
    Join Date
    Aug 2011
    Posts
    16

    Re: Gabor filter on an image

    someone..??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center