Você está na página 1de 5

Integral Images for computing Mean and Variance

Pi19404
January 17, 2014

Contents

Contents
Integral Images for computing Mean and Variance
0.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2|5

Integral Images for computing Mean and Variance

Integral Images for computing Mean and Variance


0.1 Introduction

   

The Integral Image is used as a quick and effective way of calculating the sum of values (pixel values) in a given image AS or a rectangular subset of a grid (the given image). In this article we will assume that concepts of integral image is known and then proceed to see how it can be used to compute the mean and variance of a image patch. Given a integral representation of an image,the sum of value of pixels in the rectangular region R with vertices A,B,C,D is given by

S (A) + S (D) S (B ) S (C )

Dividing this quantity by the number of pixels gives us the mean value of pixels in the region.

=

I N

 

Let us also consider the squared integral image.To obtain this all the pixel values in the image are squared then integral image is computed. consider the variance about a rectangulation regions

v=

X x  v Xx Xx 
(
i

2
i

+

v=

Xx 
2
i i

The summation x2 can obtained by the square integral image and i  can be obtained by integral image computation.

 

This enables us to compute the variance of rectangular patch of image. A similar method can be employed to compute the denominator variance term normalize cross correlation formula.

3|5

Integral Images for computing Mean and Variance

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

nclude "integralImage.h" ass IntegralImage blic: t _integral; t _sq_integral; t _image; tegralImage(); //integral image //sq integral image //original image

function too compute integral image id compute(Mat image); function to compute mean value of a patch oat calcMean(Rect r); function to compute variance of a patch oat calcVariance(Rect r); tegralImage::IntegralImage()

id IntegralImage::compute(Mat image) age.copyTo(_image); ::integral(_image,_integral,_sq_integral); oat IntegralImage::calcMean(Rect r) int width=_integral.cols; int height=_integral.rows; unsigned int *ii1 =(unsigned int *)_integral.data; int a=r.x+(r.y*width); int b=(r.x+r.width)+(r.y*width); int c=r.x+((r.y+r.height)*width); int d=(r.x+r.width)+(r.y+r.height)*width; float mx=ii1[a]+ii1[d]-ii1[b]-ii1[c]; mx=mx/(r.width*r.height); return mx;

oat IntegralImage::calcVariance(Rect r)

4|5

Integral Images for computing Mean and Variance


45 46 47 48 49 50 51 52 53 54 55 56 57 58

int width=_integral.cols; int height=_integral.rows; int a=r.x+(r.y*width); int b=(r.x+r.width)+(r.y*width); int c=r.x+((r.y+r.height)*width); int d=(r.x+r.width)+(r.y+r.height)*width; float mx=calcMean(r); double *ii2 = (double *)_sq_integral.data; float mx2=ii2[a]+ii2[d]-ii2[b]-ii2[c]; mx2=mx2/(r.width*r.height); mx2=mx2-(mx*mx); return mx2;
the above code can be found in git repo https://github.com/ pi19404/OpenVision/tree/master/ ImgFeatures/integralImage.cpp and ImgFeatures/integralImage.hpp files.

5|5