# Summed area table

A summed area table is a data structure and algorithm for quickly and efficiently generating the sum of values in a rectangular subset of a grid. In the image processing domain, it is also known as an integral image. It was introduced to computer graphics in 1984 by Frank Crow for use with mipmaps. In computer vision it was popularized by Lewis[1] and then given the name "integral image" and prominently used within the Viola–Jones object detection framework in 2001. Historically, this principle is very well known in the study of multi-dimensional probability distribution functions, namely in computing 2D (or ND) probabilities (area under the probability distribution) from the respective cumulative distribution functions.[2]

## The algorithm

As the name suggests, the value at any point (xy) in the summed area table is just the sum of all the pixels above and to the left of (xy), inclusive:[3][4]

${\displaystyle I_{\sum }(x,y)=\sum _{\begin{smallmatrix}x'\leq x\\y'\leq y\end{smallmatrix}}i(x',y')}$

Moreover, the summed area table can be computed efficiently in a single pass over the image, using the fact that the value in the summed area table at (xy) is just:

${\displaystyle I(x,y)=i(x,y)+I(x-1,y)+I(x,y-1)-I(x-1,y-1)\,}$
A description of computing a sum in the Summed Area Table data structure/algorithm

Once the summed area table has been computed, the task of evaluating the intensities over any rectangular area requires only four array references. This allows for a constant calculation time that is independent of the size of the rectangular area. That is, using the notation in the figure at right, having A=(x0, y0), B=(x1, y0), C=(x0, y1) and D=(x1, y1), the sum of i(x,y) over the rectangle spanned by A, B,C and D is:

${\displaystyle \sum _{\begin{smallmatrix}x_{0}

## Extensions

• This method is naturally extended to continuous domains.[2]
• The method can be also extended to high-dimensional images.[5] If the corners of the rectangle are ${\displaystyle x^{p}}$ with ${\displaystyle p}$ in ${\displaystyle \{0,1\}^{d}}$, then the sum of image values contained in the rectangle are computed with the formula
${\displaystyle \sum _{p\in \{0,1\}^{d}}(-1)^{d-\|p\|_{1}}I(x^{p})\,}$

where ${\displaystyle I(x)}$ is the integral image at ${\displaystyle x}$ and ${\displaystyle d}$ the image dimension. The notation ${\displaystyle x^{p}}$ correspond in the example to ${\displaystyle d=2}$, ${\displaystyle A=x^{(0,0)}}$, ${\displaystyle B=x^{(1,0)}}$, ${\displaystyle C=x^{(1,1)}}$ and ${\displaystyle D=x^{(0,1)}}$. In neuroimaging, for example, the images have dimension ${\displaystyle d=3}$ or ${\displaystyle d=4}$, when using voxels or voxels with a time-stamp.

• This method has been extended to high-order integral image as in the work of Phan et al.[6] who provided two, three, or four integral images for quickly and efficiently calculating the standard deviation (variance), skewness, and kurtosis of local block in the image. This is detailed below:

To compute variance or standard deviation of a block, we need two integral images:

${\displaystyle I(x,y)=\sum _{\begin{smallmatrix}x'\leq x\\y'\leq y\end{smallmatrix}}i(x',y')}$
${\displaystyle I^{2}(x,y)=\sum _{\begin{smallmatrix}x'\leq x\\y'\leq y\end{smallmatrix}}i^{2}(x',y')}$

The variance is given by:

${\displaystyle \operatorname {Var} (X)={\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-\mu )^{2}.}$

Let ${\displaystyle S_{1}}$ and ${\displaystyle S_{2}}$ denote the summations of block ${\displaystyle ABCD}$ of ${\displaystyle I}$ and ${\displaystyle I^{2}}$, respectively. ${\displaystyle S_{1}}$ and ${\displaystyle S_{2}}$ are computed quickly by integral image. Now, we manipulate the variance equation as:

${\displaystyle \operatorname {Var} (X)={\frac {1}{n}}\sum _{i=1}^{n}(x_{i}^{2}-2\cdot \mu \cdot x_{i}+\mu ^{2})={\frac {1}{n}}(\sum _{i=1}^{n}(x_{i})^{2}-2\cdot \sum _{i=1}^{n}(\mu \cdot x_{i})+\sum _{i=1}^{n}(\mu ^{2}))={\frac {1}{n}}(\sum _{i=1}^{n}(x_{i})^{2}-2\cdot \sum _{i=1}^{n}(\mu \cdot x_{i})+n\cdot (\mu ^{2}))}$
${\displaystyle ={\frac {1}{n}}(\sum _{i=1}^{n}(x_{i})^{2}-2\cdot \mu \cdot \sum _{i=1}^{n}(x_{i})+n\cdot (\mu ^{2}))={\frac {1}{n}}(S_{2}-2\cdot S_{1}/n\cdot S_{1}+n\cdot ((S_{1}/n)^{2}))={\frac {1}{n}}(S_{2}-(S_{1})^{2}/n)}$

Where ${\displaystyle \mu =S_{1}/n}$ and ${\displaystyle S_{2}=\sum _{i=1}^{n}(x_{i}^{2})}$.

Similar to the estimation of the mean (${\displaystyle \mu }$) and variance (${\displaystyle Var}$), which requires the integral images of the first and second power of the image respectively (i.e. ${\displaystyle I,I^{2}}$); manipulations similar to the ones mentioned above can be made to the third and fourth powers of the images (i.e. ${\displaystyle I^{3}(x,y),I^{4}(x,y)}$.) for obtaining the skewness and kurtosis.[6] But one important implementation detail that must be kept in mind for the above methods, as mentioned by F Shafait et al.[7] is that of integer overflow occurring for the higher order integral images in case 32-bit integers are used.

## References

1. ^ Lewis, J.P. (1995). Fast template matching. Proc. Vision Interface. pp. 120–123.
2. ^ a b Finkelstein, Amir; neeratsharma (2010). "Double Integrals By Summing Values Of Cumulative Distribution Function". Wolfram Demonstration Project.
3. ^ Crow, Franklin (1984). "Summed-area tables for texture mapping" (PDF). SIGGRAPH '84: Proceedings of the 11th annual conference on Computer graphics and interactive techniques. pp. 207–212.
4. ^ Viola, Paul; Jones, Michael (2002). "Robust Real-time Object Detection" (PDF). International Journal of Computer Vision.
5. ^ Tapia, Ernesto (January 2011). "A note on the computation of high-dimensional integral images". Pattern Recognition Letters. 32 (2). doi:10.1016/j.patrec.2010.10.007.
6. ^ a b Phan, Thien; Sohoni, Sohum; Larson, Eric C.; Chandler, Damon M. (22 April 2012). "Performance-analysis-based acceleration of image quality assessment" (PDF). 2012 IEEE Southwest Symposium on Image Analysis and Interpretation: 83. doi:10.1109/SSIAI.2012.6202458.
7. ^ Shafait, Faisal; Keysers, Daniel; M. Breuel, Thomas (January 2008). "Efficient implementation of local adaptive thresholding techniques using integral images" (PDF). Electronic Imaging. doi:10.1117/12.767755.