[iasobel] [Up] [iaotsu] Image Filtering

iavarfilter
Variance filter.

Synopsis

g = iavarfilter( f, h )

Implemented in Python.

Input

f Image. Gray-scale (uint8 or uint16) or binary image (logical).

input image.

h Image. Gray-scale (uint8 or uint16) or binary image (logical).

scaling factor.

Output

g Image. Accepts any image data type.

Description

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

Examples

>>> f = iaread('cameraman.pgm')

              
>>> iashow(f)
(256, 256) Min= 0 Max= 251 Mean=137.066 Std=87.20
>>> g = iavarfilter(f, [[0,1,0],[1,1,1],[0,1,0]])

              
>>> iashow(g)
(256, 256) Min= 0.0 Max= 1.92393146638 Mean=0.157 Std=0.26
f g

Source Code

def iavarfilter(f, h):
    from Numeric import asarray, Float64, sum, ravel, sqrt
    f = asarray(f).astype(Float64)
    f = f + 1e-320*(f == 0) # change zero by a very small number (prevent 'math range error') 
    n = sum(ravel(h))
    fm = iapconv(f, h) / n
    f2m = iapconv(f*f, h) / n
    g = sqrt(f2m - (fm*fm)) / fm
    return g
    
[iasobel] [Up] [iaotsu] http://www.python.org