Documentation

integralKernel class

Integral image filter

Description

This object describes box filters for use with integral images.

Construction

example

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

example

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

Input Arguments

collapse all

bbox — Bounding boxes4-element vector | M-by-4 matrix

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 — WeightsM-length vector

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

orientation — Filter orientation'upright' | 'rotated'

Filter orientation, specified as the string '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.

Properties

collapse all

These properties are read-only.

BoundingBoxesBounding boxes4-element vector | M-by-4 matrix

Bounding boxes, stored as either a 4-element [x,y,width, height] vector or an M-by-4 matrix of individual bounding boxes.

WeightsWeightsvector

Weights, stored as a vector containing a weight for each bounding box. The weights are used to define the coefficients of the filter.

CoefficientsFilter coefficientsnumeric

Filter coefficients, stored as a numeric value.

CenterFilter center[x,y] coordinates

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.

SizeFilter size2-element vector

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:

OrientationFilter orientation'upright' (default) | 'rotated'

Filter orientation, stored as the string 'upright' or 'rotated'.

Methods

rot45Rotates upright kernel clockwise by 45 degrees
transposeTranspose filter

Examples

collapse all

Define an 11-by-11 Average Filter

 avgH = integralKernel([1 1 11 11], 1/11^2);

Define a Filter to Approximate a Gaussian Second Order Partial Derivative in Y Direction

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.

ydH.Coefficients
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 a Haar-like Wavelet to Detect 45-Degree Edges

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;

Blur an Image Using an Average Filter

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

Related Examples

References

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.

More About

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

Introduced in R2012a

Was this topic helpful?