Hi all,
I'm tring to implement a sobel filter using PIL library with few success.

Now I never used this library before so any help is appreciate.
I wrote the following code that essential is a standard implementation
of the sobel filter:

input img, output dimg:
dx = [-1,  0,  1, -2, 0, 2, -1, 0, 1]
dy = [-1, -2, -1,  0, 0, 0,  1, 2, 1]

ximg = img.filter(ImageFilter.Kernel((3,3), dx, None, 0)) #apply the
kernel in x e y
yimg = img.filter(ImageFilter.Kernel((3,3), dy, None, 0))

dimg = img.copy()
dest = dimg.load()
xdata = ximg.load() #retrieve the x e y data
ydata = yimg.load()

for y in range ( img.size[1]):                  # calcolo il gradiente per ogni 
punto
        for x in range( img.size[0]):
#            dest[x, y] = sqrt( xdata[x, y] * xdata[x, y] + ydata[x, y] * 
ydata[x, y])
             dest[x, y] = abs( xdata[x, y] ) + abs (ydata[x, y])

The result is not what I expected, so I misunderstood some function usage?
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to