O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Edge detection with the Sobel filter

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.

How to do it...

In this section, you will learn how to apply the Sobel filter to detect edges in the Lena image:

  1. To apply the Sobel filter in the x direction, set the axis parameter to 0:
    sobelx = scipy.ndimage.sobel(lena, axis=0, mode='constant')
  2. To apply the Sobel filter in the y direction, set the axis parameter to 1:
    sobely ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required