CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    16

    Question 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

    oh sorry i just realized I was in the wrong part of the forum ... I work with c# ^^

    Anyway, if you have an answer, anything in c++, i would deeply appreciate your help !

  3. #3
    Join Date
    Jan 2013
    Posts
    2

    Thumbs up Re: Gabor filter on an image

    Hi DidAus,

    i m working on the same project in C#.i.e. applying gabor filtering for image enhancement.i followed this link

    http://stackoverflow.com/questions/1...cording-to-the

    and now visited this forum.
    i have removed gaussian noise, contrast streched the image, created its histogram and generated a histogram equalized image yet.now my next step is to apply Gabor filter.

    i m not getting the concept that how to create a 2D array of pixels' orientations and pixels' frequency.In your post you have claimed that you have successfully tested the orientation and frequency.Kindly guide me how and if there is some code available it will be preferable..u can catch me at aroojnazir33@gmail.com

  4. #4
    Join Date
    Jan 2013
    Posts
    2

    Re: Gabor filter on an image

    i am confused about this that angle is 1 value for the x and y coordinates of pixel i.e one orientation for one pixel. why is this 2D array needed for frequency and orientation and how to calculate these two parameters in C#.its urgent.. i 'll wait for the response.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured