The Sobel operator (for more information on Sobel operator visit 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. Because 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 Soderberg.
In this section, we will learn how to apply the Sobel filter to detect edges in the Lena image.
Apply the Sobel filter in the x direction.
To apply the Sobel filter in the x direction, we need to set the
axis
parameter to0
:sobelx = scipy.ndimage.sobel(lena, axis=0, mode='constant')
Apply the Sobel filter in the y direction.
To apply the Sobel filter in the y direction, we need to set the
axis
parameter to1
:sobely = scipy.ndimage.sobel(lena, axis=1, mode='constant')
Apply the default Sobel filter.
The default...