Main Content

integralFilter

Filter using integral image

    Description

    example

    J = integralFilter(intI,H) filters an image given its integral image, intI, and a box filter, H.

    Examples

    collapse all

    Read and display the input image.

       I = imread('pout.tif');
       imshow(I);

    Figure contains an axes object. The axes object contains an object of type image.

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

    Figure contains an axes object. The axes object contains an object of type image.

    Construct Haar-like wavelet filters to find vertical and horizontal edges in an image.

    Read the input image and compute the integral image.

    I = imread('pout.tif');
    intImage = integralImage(I);

    Construct Haar-like wavelet filters. Use the dot notation to find the vertical filter from the horizontal filter.

    horiH = integralKernel([1 1 4 3; 1 4 4 3],[-1, 1]);
    vertH = horiH.'
    vertH = 
      integralKernel with properties:
    
        BoundingBoxes: [2x4 double]
              Weights: [-1 1]
         Coefficients: [4x6 double]
               Center: [2 3]
                 Size: [4 6]
          Orientation: 'upright'
    
    

    Display the horizontal filter.

    imtool(horiH.Coefficients, 'InitialMagnification','fit');

    Figure Image Tool 1 - (MATLAB Expression) contains an axes object and other objects of type uimenu, uitoolbar, uipanel. The axes object contains an object of type image.

    Compute the filter responses.

    horiResponse = integralFilter(intImage,horiH);
    vertResponse = integralFilter(intImage,vertH);

    Display the results.

    figure; 
    imshow(horiResponse,[]); 
    title('Horizontal edge responses');

    Figure contains an axes object. The axes object with title Horizontal edge responses contains an object of type image.

    figure; 
    imshow(vertResponse,[]); 
    title('Vertical edge responses');

    Figure contains an axes object. The axes object with title Vertical edge responses contains an object of type image.

    Read the input image.

    I = imread('pout.tif');

    Compute 45 degree edge responses of the image.

    intImage = integralImage(I,'rotated');
    figure;
    imshow(I);
    title('Original Image');

    Figure contains an axes object. The axes object with title Original Image contains an object of type image.

    Construct 45 degree rotated Haar-like wavelet filters.

    rotH = integralKernel([2 1 2 2;4 3 2 2],[1 -1],'rotated');
    rotHTrans = rotH.';

    Visualize the filter rotH.

    figure;
    imshow(rotH.Coefficients, [],'InitialMagnification','fit');

    Figure contains an axes object. The axes object contains an object of type image.

    Compute filter responses.

    rotHResponse = integralFilter(intImage,rotH);
    rotHTransResponse = integralFilter(intImage,rotHTrans);

    Display results.

    figure;
    imshow(rotHResponse, []);
    title('Response for SouthWest-NorthEast edges');

    Figure contains an axes object. The axes object with title Response for SouthWest-NorthEast edges contains an object of type image.

    figure;
    imshow(rotHTransResponse, []);
    title('Response for NorthWest-SouthEast edges');

    Figure contains an axes object. The axes object with title Response for NorthWest-SouthEast edges contains an object of type image.

    Input Arguments

    collapse all

    Integral image, specified as a numeric array. You can obtain the integral image, intI, using the integralImage function.

    Data Types: single | double

    Box filter, specified as an integralKernel object.

    Output Arguments

    collapse all

    Filtered image, returned as a numeric array. The filtered image, J, returns only the parts of correlation that are computed without padding. This results in size(J) = size(intI) – H.Size for an upright filter, and size(J) = size(intI) – H.Size – [0 1] for a rotated filter.

    Tips

    • The filter size does not affect the speed of the filtering operation. Thus, the integralFilter function is ideally suited to use for fast analysis of images at different scales, as demonstrated by the Viola-Jones algorithm [1].

    • The integralFilter function uses correlation for filtering. Therefore, the filter is not rotated before calculating the result.

    References

    [1] 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, 2001. Volume: 1, pp.511–518.

    Version History

    Introduced in R2012a