Function iasobel

Synopse

Sobel edge detection.

  • mag,theta = iasobel(f)
    • mag,theta: Image.
    • f: Image. input image
01. def iasobel(f):
02.     import numpy as np
03.     from ia636 import iaimginfo, iapconv
04. 
05.     wx = np.array([[1.,2.,1.],
06.                    [0.,0.,0.],
07.                    [-1.,-2.,-1.]])
08.     wy = np.array([[1.,0.,-1.],
09.                    [2.,0.,-2.],
10.                    [1.,0.,-1.]])
11.     gx = iapconv(f, wx)
12.     gy = iapconv(f, wy)
13.     mag = np.abs(gx + gy*1j)
14.     theta = np.arctan2(gy,gx)
15.     return mag,theta

Description

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

Examples

Numerical Example

1. from ia636 import iasobel
2. 
3. f = array([[0,0,0,0],
4.            [0,1,0,0],
5.            [0,0,0,0]],dtype=uint8)
6. m,t = iasobel(f)
7. print 'm=',m
8. print 't=',t
m= [[ 1.41421356  2.          1.41421356  0.        ]
 [ 2.          0.          2.          0.        ]
 [ 1.41421356  2.          1.41421356  0.        ]]
t= [[ 0.78539816  0.         -0.78539816  0.        ]
 [ 1.57079633  0.         -1.57079633  0.        ]
 [ 2.35619449  3.14159265 -2.35619449  0.        ]]

Example 1

1. from ia636 import iasobel, ianormalize
2. 
3. f = adreadgray('cameraman.pgm')
4. (g,a) = iasobel(f)
5. adshow(ianormalize(g),title='sobel')
6. adshow(ianormalize(log(g+1)),title='log of sobel')

sobel

log of sobel

Example 2

Display angle.

1. from ia636 import iacircle
2. 
3. f = iacircle([200,300], 90, [100,150])
4. m,t = iasobel(f)
5. adshow(ianormalize(m), title='magnitude of Sobel filtering')
6. dt = select( [m > 2], [t])
7. adshow(ianormalize(dt), title='angle of edges with magnitude above 2')

magnitude of Sobel filtering

angle of edges with magnitude above 2

Equation

See Also