I define a Haar-like feature filter H by the IntegralKernel class in Matlab.
H = integralKernel(integralKernel([1,1,im_width,im_height;...
2, 2, w, h;...
2+w, 2, w, h;],...
[0,1,-1]);
im_width and im_height are width and height of the image; w and h are width and height of the bounding box of the filter. The returned filte H is a Matlab struct type variable, which contains the fields like:
BoundingBoxes
Weights
Coefficients - Conventional filter coefficients.
Center
Size
In Matlab document, it uses the function integralFilter(IntegralImage, H), when computing the feature from the given integral image. The code is like:
HaarFeature = integralFilter(integralImage(I), H)
But this takes a long time if the number of images are large (e.g., 10,000 images), because I need to use a for-loop to compute every image. However, I found that is much quicker if I just compute the sum of the given original image I and the coefficients in the filer H. The code is like:
HaarFeature = sum(sum(I .* H.Coefficients));
Both I and H.Coefficients are double type in Matlab.
My question is that if these two ways to compute the Haar Features are equivalent? Thanks!
Do you have to filter each image with multiple kernels? In that case you should only call
integralImage(I)
once for each image, and store and re-use the result. Computing the integral image takes some time. However, once you have it, applying an integral kernel to the resulting integral image should be very fast.