The Sobel operator (http://en.wikipedia.org/wiki/Sobel_operator) can be used for edge detection in images. The edge detection is based on performing a discrete differentiation on the image intensity. Since an image is two-dimensional, the gradient also has two components, unless we limit ourselves to one dimension, of course. We will apply the Sobel filter to the picture of Lena Söderberg.
In this section, you will learn how to apply the Sobel filter to detect edges in the Lena image:
To apply the Sobel filter in the x direction, set the axis parameter to
0
:sobelx = scipy.ndimage.sobel(lena, axis=0, mode='constant')
To apply the Sobel filter in the y direction, set the axis parameter to
1
:sobely = scipy.ndimage.sobel(lena, axis=1, mode='constant')
The default Sobel filter only requires the input array:
default = scipy.ndimage.sobel(lena)
Here are the original and resulting image plots, showing edge detection with the Sobel filter: