-
April 30th, 2012, 06:41 AM
#1
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 !!
-
April 30th, 2012, 08:05 AM
#2
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
-
May 2nd, 2012, 06:20 AM
#3
Re: Gabor filter on an image
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|