Define filter for use with integral images
This object describes box filters for use with integral images.
bbox— Bounding boxes
Bounding boxes, specified as either a 4-element [x,y,width, height] vector or an M-by-4 matrix of individual bounding boxes. The bounding box defines the filter. The (x,y) coordinates represent the top-most corner of the kernel. The (width, height) elements represent the width and height accordingly. Specifying the bounding boxes as an M-by-4 matrix is particularly useful for constructing Haar-like features composed of multiple rectangles.
Sums are computed over regions defined by
The bounding boxes can overlap. See Define an 11-by-11 Average Filter for an example of how to specify a box
Weights, specified as an M-length vector of weights corresponding to the bounding boxes.
For example, a conventional filter with the coefficients:
and two regions:
|region 1: x=1, y=1, width = 4, height = 2|
|region 2: x=1, y=3, width = 4, height = 2|
boxH = integralKernel([1 1 4 2; 1 3 4 2], [1, -1])
orientation— Filter orientation
Filter orientation, specified as either
'rotated'. When you set the orientation to
(x,y) components refer to the
location of the top-left corner of the bounding box. The
refer to a 45-degree line from the top-left corner of the bounding
These properties are read-only.
BoundingBoxes— Bounding boxes
Bounding boxes, stored as either a 4-element [x,y,width, height] vector or an M-by-4 matrix of individual bounding boxes.
Weights, stored as a vector containing a weight for each bounding box. The weights are used to define the coefficients of the filter.
Coefficients— Filter coefficients
Filter coefficients, stored as a numeric value.
Center— Filter center
Filter center, stored as [x,y] coordinates. The filter center represents the center of the bounding rectangle. It is calculated by halving the dimensions of the rectangle. For even dimensional rectangles, the center is placed at subpixel locations. Hence, it is rounded up to the next integer.
For example, for this filter, the center is at [3,3].
These coordinates are in the kernel space, where the
top-left corner is (1,1). To place the center in a different location,
provide the appropriate bounding box specification. For this filter, the
best workflow would be to construct the upright kernel and then call the
rot45 method to provide the rotated
Size— Filter size
Filter size, stored as a 2-element vector. The size of the kernel is computed to be the dimensions of the rectangle that bounds the kernel. For a single bounding box vector [x,y,width, height], the kernel is bounded within a rectangle of dimensions [(width+height) (width+height)-1].
For cascaded rectangles, the lowest corner of the bottom-most rectangle defines the size. For example, a filter with a bounding box specification of [3 1 3 3], with weights set to 1, produces a 6-by-5 filter with this kernel:
Orientation— Filter orientation
Filter orientation, stored as either
avgH = integralKernel([1 1 11 11], 1/11^2);
ydH = integralKernel([1,1,5,9;1,4,5,3], [1, -3]);
You can also define this filter as
integralKernel([1,1,5,3;1,4,5,3;1,7,5,3], [1, -2, 1]);|. This filter definition is less efficient because it requires three bounding boxes.
Visualize the filter.
ans = 9×5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Create the filter.
K = integralKernel([3,1,3,3;6 4 3 3], [1 -1], 'rotated');
Visualize the filter and mark the center.
imshow(K.Coefficients, , 'InitialMagnification', 'fit'); hold on; plot(K.Center(2),K.Center(1), 'r*'); impixelregion;
Read and display the input image.
I = imread('pout.tif'); imshow(I);
Compute the integral image.
intImage = integralImage(I);
Apply a 7-by-7 average filter.
avgH = integralKernel([1 1 7 7], 1/49); J = integralFilter(intImage, avgH);
Cast the result back to the same class as the input image.
J = uint8(J); figure imshow(J);
Viola, Paul, and Michael J. Jones. “Rapid Object Detection using a Boosted Cascade of Simple Features”. Proceedings of the 2001 IEEE Computer Society Conference on Computer Vision and Pattern Recognition. Vol. 1, 2001, pp. 511–518.