This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

integralKernel class

Define filter for use with integral images


This object describes box filters for use with integral images.



intKernel = integralKernel(bbox,weights) defines an upright box filter using an M-by-4 matrix of bounding boxes and their corresponding weights.


intKernel = integralKernel(bbox,weights,orientation) the specified orientation.

Input Arguments

expand all

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 bbox. The bounding boxes can overlap. See Define an 11-by-11 Average Filter for an example of how to specify a box filter.

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

can be specified as

boxH = integralKernel([1 1 4 2; 1 3 4 2], [1, -1])

Filter orientation, specified as the character vector 'upright' or 'rotated'. When you set the orientation to 'rotated', the (x,y) components refer to the location of the top-left corner of the bounding box. The (width,height) components refer to a 45-degree line from the top-left corner of the bounding box.


expand all

These properties are read-only.

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.

Filter coefficients, stored as a numeric value.

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 version.

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:

Filter orientation, stored as the character vector 'upright' or 'rotated'.


rot45Rotates upright kernel clockwise by 45 degrees
transposeTranspose filter


expand all

 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 =

     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*');

Read and display the input image.

   I = imread('pout.tif');

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);

More About

 Computing an Integral Image and Using it for Filtering with Box Filters


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.

Introduced in R2012a

Was this topic helpful?