Ask Your Question
0

How to use Gabor Filter

asked 2017-02-08 05:41:02 -0600

ginister gravatar image

Hi everyone, I'd like to be able to use the gabor filter on my image to extract features to put into a classifier. I've been told Gabor is the most effective for my program (detecting certain hand positions). Can anyone comment on how to use it correctly? I have the following currently, but my output is just a white image.

  Mat gaborOut, outAsFloat, gaborImage;
  cvtColor(outImg, outAsFloat, CV_32F);
  Mat gaborKernel = getGaborKernel(cv::Size(30,30), 1, 0, 1, 0.02);
  filter2D(outAsFloat, gaborOut, 1, gaborKernel);
  gaborOut.convertTo(gaborImage, CV_8U, 1.0/255.0);

Currently the kernel variables are just ones I've found from other examples, maybe this is the source of the problem? outImg is a Mat of contours e.g.image description

Thanks for your help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-08 11:20:18 -0600

LBerger gravatar image

updated 2017-02-08 11:28:01 -0600

There are some problems with cvtColor and convertTo.

  1. You cannot use CV_32F with cvtColor CV_32F cosntant is equal to COLOR_BGRA2RGBA. I don't think that is what you want.
  2. normalisation constant in convertTo are wrong. You have to find min and max before convertTo

you should try like this :

    Mat outImg =imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
    Mat gaborOut, outAsFloat, gaborImage;
    outImg.convertTo( outAsFloat, CV_32F);
    Mat gaborKernel = getGaborKernel(cv::Size(30, 30), 1, 0, 1, 0.02);
    filter2D(outAsFloat, gaborOut, CV_32F, gaborKernel);
    double xmin[4],xmax[4];
    minMaxIdx(gaborOut,xmin,xmax);
    gaborOut.convertTo(gaborImage, CV_8U, 1.0 / 255.0);
    imshow("1-problem", gaborImage);
    gaborOut.convertTo(gaborImage, CV_8U, 255.0/(xmax[0]-xmin[0]),-255*xmin[0] /(xmax[0] -xmin[0]));
    imshow("2-CV_8U", gaborImage);
    waitKey(0);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-02-08 05:41:02 -0600

Seen: 2,698 times

Last updated: Feb 08 '17