# Lesson iavarfilter

Autor: marianapbento 11/05/2011

Computes the variance on the neighborhood of the pixel. The neighborhood is given by the set marked by the kernel elements.

# Read the input image and kernel

```1 from numpy import *
2 from ia636 import iapconv, ianormalize, iavarfilter
3
5 f = asarray(f).astype(float64)
6 f = f + 1e-320*(f == 0) # change zero by a very small number (prevent 'math range error')
8 h = [[0,1,0],[1,1,1],[0,1,0]]
```

# Compute the mean on the neighborhood of the pixel

```1 # calculate the normalization factor n
2 n = sum(ravel(h))
3 print 'Normalization factor:',n
4 # calculate the periodic convolution between f and h
5 fm = iapconv(f, h) / n
6 adshow(fm,'periodic convolution between f and h')
```
```Normalization factor: 5
```

# Compute the square mean on the neighborhood of the pixel

```1 # shows f*f result
3 # calculate the periodic convolution between f*f and h
4 f2m = iapconv(f*f, h) / n
5 adshow(ianormalize(f2m),'Periodic convolution between f*f and h')
```

# Compute and visualize the variance on the neighborhood of the pixel

```1 var = f2m - (fm*fm)