Ask Your Question

Construct Gabor Filters and Filter Image

asked 2016-07-19 10:46:15 -0600

phillity gravatar image

updated 2016-07-19 11:05:20 -0600

Hi, I am trying to convert these lines of matlab code to java using OpenCV 3.1:

  • fb = construct_Gabor_filters_PhD(8,5,[a b]);
  • downScale = 40;
  • feature = filter_image_with_Gabor_bank_PhD(img,fb,downScale);

These PhD functions are from a face recognition toolbox with documentation found here.

Here are the function prototypes:

  • construct_Gabor_filters_PhD(norie, nscale, size, fmax, ni, gamma, separation)
  • feature vector = filter image with Gabor bank PhD(image, filter bank,down sampling factor)

construct_Gabor_filters_PhD(8,5,[a b]) is returning a filter bank struct four fields: 5x8 cell spatial, 5x8 cell freq, scales which is a double of value 5, orient which is a double of value 8

filter_image_with_Gabor_bank_PhD(img,fb,downScale) is returning a 38400x1 matrix

Do these functions have corresponding OpenCV functions? Can I mimic what they are doing using OpenCV?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-07-19 11:17:58 -0600

berak gravatar image

you can construct a single gabor filter with getGaborKernel

and apply it using filter2D

edit flag offensive delete link more


Thank you,

For Imgproc.getGaborKernel(ksize, sigma, theta, lambd, gamma), would setting theta to 8 and lambda 5 give me a kernel with 8 orientations and 5 scales?

For Imgproc.filter2D(src, dst, ddepth, kernel), is ddepth the down sampling factor or something else?

phillity gravatar imagephillity ( 2016-07-19 11:59:18 -0600 )edit
  • no, each getGaborKernel returns a single filter, also, each filter2D call returns a single image of the original size, so i think, you have to construct 8x5=40 filters(with varying values for theta & lambda), and resize your images to 30x32. then push_back() the filter2D results to a single Mat (starting with an empty one), and apply reshape(1,1) to that, to get a 38400x1 output matrix
  • ddepth is the resulting image type (preferably CV_32F). but imho, you should convert your input images to float, before applying the filter, so you would leave it at -1

(disclaimer: no, i did not read that paper !)

((sidenote: "manual" feature engeneering like this seems to be a thing of the past. the dnn folks have won that race 2 or 3 years ago))

berak gravatar imageberak ( 2016-07-19 12:15:56 -0600 )edit

@berak, even if dnn folks won the accuracy race, for day to day setups, dnn's are overkill. Not only do they require heaps of data, they take ages to train and run terribly slow on any decent resolution. Therefore hand crafted features for the win!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-20 07:05:30 -0600 )edit

JEEJ for this link!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-22 05:34:08 -0600 )edit

Question Tools

1 follower


Asked: 2016-07-19 10:46:15 -0600

Seen: 1,669 times

Last updated: Jul 19 '16