[iapconv] [Up] [iavarfilter] | Image Filtering |
Computes the edge detection by Sobel. Compute magnitude and angle.
>>> 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) |
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] | |