# Examples with function iasat

Autor: joaomarcos 21/03/2015
• Examples using iasat. Template available here: iasat
``` 1 from courseIA8981S2015.function_iasat_joaomarcos import iasat
2 import ia636 as ia
3 import numpy as np
4
5 f1 = np.zeros((16,16))
6 h,w = f1.shape
7 f1[2,2] = 1
8 f1[4,4] = 1
9 f1[3,12] = 1
10
11 print 'f1:\n', f1
12
13
14 h1sat = iasat(f1)
15 #-------------------------
16 nrl = 4 #LEVEL
17 #-------------------------
18 h1 = np.ones((nrl,nrl))
19 hlA = h1sat[0:h-nrl, 0:w-nrl]
20 hlD = h1sat[nrl:h, nrl:w]
21 hlB = h1sat[nrl:h,0:w-nrl]
22 hlC = h1sat[0:h-nrl,nrl:w]
23 houtim = hlA + hlD - hlC - hlB
24 houtconv = ia.iaconv(f1,h1)
25 h,w = houtconv.shape
26 print 'iasat:'
27 print houtim
28 print 'iaconv (cropped):'
29 print ia.iaconv(f1,h1)[nrl:h-nrl+1,nrl:w-nrl+1]
```
```f1:
[[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  0.  0.]
[ 0.  0.  0.  0.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
iasat:
[[ 2.  2.  1.  1.  0.  0.  0.  0.  1.  1.  1.  1.]
[ 2.  2.  1.  1.  0.  0.  0.  0.  1.  1.  1.  1.]
[ 1.  1.  1.  1.  0.  0.  0.  0.  1.  1.  1.  1.]
[ 1.  1.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
iaconv (cropped):
[[ 2.  2.  1.  1.  0.  0.  0.  0.  1.  1.  1.  1.]
[ 2.  2.  1.  1.  0.  0.  0.  0.  1.  1.  1.  1.]
[ 1.  1.  1.  1.  0.  0.  0.  0.  1.  1.  1.  1.]
[ 1.  1.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
```
``` 1 from courseIA8981S2015.function_iasat_joaomarcos import iasat
2 import ia636 as ia
3 import numpy as np
5 adshow(img_original, 'Original Image')
6
7 t0i = time.time()
8 img_sat = iasat(img_original)
9 t0e = time.time()
10 print 'Time to generate Summed Area Table is {0:.2f} seconds.'.format(t0e - t0i)
11 h,w = img_original.shape
12 #-----------------------------
13 nrl = 19.0 #NOISE REDUCTION LEVEL
14 #-----------------------------
15 t1 = time.time()
16 lA = img_sat[0:h-nrl, 0:w-nrl]
17 lD = img_sat[nrl:h, nrl:w]
18 lC = img_sat[nrl:h,0:w-nrl]
19 lB = img_sat[0:h-nrl,nrl:w]
20 img_iasat = np.rint((lA + lD - lC - lB) / (nrl*nrl))
21 adshow(img_iasat, 'iasat average')
22 t2 = time.time()
23 print 'Time iasat is {0:.2f} seconds.'.format(t2 - t1)
24 #---------------------------------------------------------------------------
25 t3 = time.time()
26 kernel_img = np.ones((nrl,nrl)) / (nrl*nrl) #Matrix nrl*nrl of ones for mask
27 img_iaconv = ia.iaconv(img_original, kernel_img)
28 hc,wc = img_iaconv.shape
29 img_iaconv = np.rint(img_iaconv[nrl:hc-nrl+1,nrl:wc-nrl+1]) #---CROP-----------
30 adshow(img_iaconv, 'ia636 iaconv')
31 t4 = time.time()
32 #---------------------------------------------------------------------------
33 print 'Time iaconv is {0:.2f} seconds.'.format(t4 - t3)
34
35 print 'original  shape:', img_original.shape
36 print 'iasat  shape:', img_iasat.shape
37 print 'iaconv shape:', img_iaconv.shape
38 outfin = img_iasat-img_iaconv
39 print 'np.array_equal:', np.array_equal(img_iasat, img_iaconv)
40 print 'np.allclose:',np.allclose(img_iasat, img_iaconv)
41 adshow(outfin, 'iasat - iaconv')
```
```Time to generate Summed Area Table is 0.05 seconds.
Time iasat is 0.25 seconds.
Time iaconv is 3.48 seconds.
original  shape: (840, 840)
iasat  shape: (821, 821)
iaconv shape: (821, 821)
np.array_equal: True
np.allclose: True
```

# Interactive

• Please, to start the webapp, edit this document and save without any changes.
 Summed Area Table Moving Average 10 -*- Reset Stop App