Exercise

Detect edges (2)

Edge detection can be performed along multiple axes, then combined into a single edge value. For 2D images, the horizontal and vertical "edge maps" can be combined using the Pythagorean theorem:

$$z = \sqrt{x^2 + y^2}$$

One popular edge detector is the Sobel filter. The Sobel filter provides extra weight to the center pixels of the detector:

weights = [[ 1,  2,  1], 
           [ 0,  0,  0],
           [-1, -2, -1]]

For this exercise, improve upon your previous detection effort by merging the results of two Sobel-filtered images into a composite edge map.

Instructions

100 XP
  • Apply ndi.sobel() to im along the first and second axes.
  • Calculate the overall edge magnitude using the Pythagorean theorem. Use np.sqrt() and np.square().
  • Display the magnitude image. Use a grayscale colormap and set vmax to 75.