Function iasat

Synopse

The iasat function is used to calculate from a given grayscale image, the summed area table (integral image).

  • g = iasat(f)
    • Output
      • g: ndarray with the summed area table.
    • Input
      • f: ndarray with a grayscale image.

Description

The Integral Image is used as a quick and effective way of calculating the sum of values (pixel values) in a given image or a rectangular subset of a grid (the given image). It can also, or is mainly, used for calculating the average intensity within a given image.

Function Code

1 def iasat(f):
2     return f.cumsum(1).cumsum(0)

Examples

  • Numerical example:
 1 from courseIA8981S2015.function_iasat_joaomarcos import iasat
 2 
 3 f = array( [[0,1,1,0,0,0,0,0,0],
 4             [1,0,0,0,0,0,0,1,0],
 5             [1,0,0,1,0,0,0,1,0],
 6             [0,0,0,0,0,1,1,0,0]], dtype=uint8)
 7 
 8 g = iasat(f)
 9 print 'f (input): '
10 print  f
11 print 'g (output): '
12 print  g
f (input): 
[[0 1 1 0 0 0 0 0 0]
 [1 0 0 0 0 0 0 1 0]
 [1 0 0 1 0 0 0 1 0]
 [0 0 0 0 0 1 1 0 0]]
g (output): 
[[0 1 2 2 2 2 2 2 2]
 [1 2 3 3 3 3 3 4 4]
 [2 3 4 5 5 5 5 7 7]
 [2 3 4 5 5 6 7 9 9]]
  • Image example
1 from courseIA8981S2015.function_iasat_joaomarcos import iasat
2 import ia636 as ia
3 im = adreadgray('lenina.pgm')[::2,::2]
4 adshow(im, 'Original Image')
5 adshow(ia.ianormalize(iasat(im)), 'Integral Image')

Original Image

Integral Image

  • Calculating a rectangle area with SAT (Summed Area Table)
 1 import ia636 as ia
 2 
 3 im = adreadgray('lenina.pgm')[::2,::2]
 4 f = iasat(im)
 5 a,b,c,d = 0,0,0,0
 6 
 7 #Calculate the pixel intensity in a 4x5 area
 8 r0 = 0
 9 c0 = 0
10 r1 = 3
11 c1 = 4
12 
13 if ((r0 - 1 >= 0) and (c0 - 1 >= 0)):
14     a = f[r0-1,c0-1]
15     #print 'a:',a
16 if (r0 - 1 >= 0):
17     b = f[r0-1,c1]
18     #print 'b:',b
19 if (c0 - 1 >= 0):
20     c = f[r1,c0-1]
21     #print 'c:',c
22 d = f[r1,c1]
23 #print 'd:',d
24 
25 area = a + d - c - b
26 
27 print 'Rectangle Area Value[0:4,0:5]: ', area
28 
29 dim = ia.ianshow(im[0:4,0:5])
30 
31 label = 'Original Image Pixels. Area:' + str(area)
32 
33 adshow(dim, label)
Rectangle Area Value[0:4,0:5]:  1041.0

Original Image Pixels. Area:1041.0

Equation

The summed area table is the sum of all the pixels above and to the left of (r, c), inclusive:

It can be computed with a single pass over the image in a raster order scanning:

To calculate the integral over a rectangle (r0,c0)-(r1,c1), you need to operate on just four points:

  • is the input image.
  • is the summed area table array.

See Also

  • iasatarea - Calculate the area of an image using its summed area table.

Contributions

  • João Marcos Gualtieri Beraquet, março de 2015