[iapconv] [Up] [iavarfilter] Image Filtering

iasobel
Sobel edge detection.

Synopsis

mag theta = iasobel( f )

Implemented in Python.

Input

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

input image

Output

mag theta Image. Accepts any image data type.

Description

Computes the edge detection by Sobel. Compute magnitude and angle.

Examples

>>> import Numeric

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

              
>>> (g,a) = iasobel(f)

              
>>> iashow(g)
(256, 256) Min= 0.0 Max= 1067.79024157 Mean=98.274 Std=179.78
>>> iashow(Numeric.log(g+1))
(256, 256) Min= 0.0 Max= 6.97428267248 Mean=3.443 Std=1.49
g Numeric.log(g+1)
>>> iashow(g > 150)
(256, 256) Min= 0 Max= 1 Mean=0.171 Std=0.38
>>> i = Numeric.nonzero(Numeric.ravel(g > 150))

              
>>> z = Numeric.zeros(a.shape)

              
>>> Numeric.put(Numeric.ravel(z), i, Numeric.take(Numeric.ravel(a), i))

              
>>> iashow(z)
(256, 256) Min= -3 Max= 3 Mean=0.000 Std=0.57
g > 150 z

Equation

Source Code

def iasobel(f):
    from Numeric import array, reshape, ravel, arctan2
    from MLab import rot90
    def test_arctan2(x,y):
        from Numeric import arctan2
        try:
            return (arctan2(x,y))
        except:
            return 0
    wx = array([[1,2,1],[0,0,0],[-1,-2,-1]])
    wy = rot90(wx)
    gx = iapconv(f, wx)
    gy = iapconv(f, wy)
    mag = abs(gx + gy*1j)
    theta = reshape(map(test_arctan2, ravel(gy), ravel(gx)), f.shape)
    return mag, theta
    
[iapconv] [Up] [iavarfilter] http://www.python.org