Classical Computer Vision: Edge Detection II - The Canny Edge Detector

    This edge detection technique is much newer and more complex than the previous image edge detectors.

    Initially, Canny postulated 3 principles for an "ideal" edge detection:

    1. Low error rate: an ideal edge detector shouldn't neither miss an edge nor detect anything else as an edge that is not an edge.

    2. Location: the distance between the edge pixels should be the lowest possible

    3. Response: the detector shouldn't identify multiple edge pixels when there's only one.

    To try to achieve this, Canny used the following process

  1. Apply Gaussian filter to smooth the image in order to remove the noise
  2. Find the intensity gradients of the image
  3. Apply gradient magnitude thresholding or lower bound cut-off suppression to get rid of spurious response to edge detection
  4. Apply double threshold to determine potential edges
  5. Track edge by hysteresis: Finalize the detection of edges by suppressing all the other edges that are weak and not connected to strong edges.
    For more information, please refer to the wiki
   
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage as ndi
from skimage.util import random_noise
from skimage import feature
from skimage.data import camera

# Generate noisy image of a square
image = camera()

# Compute the Canny filter for two values of sigma
edges1 = feature.canny(image)
edges2 = feature.canny(image, sigma=3)

# display results
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(8, 3))

ax[0].imshow(image, cmap='gray')
ax[0].set_title('noisy image', fontsize=20)

ax[1].imshow(edges1, cmap='gray')
ax[1].set_title(r'Canny filter, $\sigma=1$', fontsize=20)

ax[2].imshow(edges2, cmap='gray')
ax[2].set_title(r'Canny filter, $\sigma=3$', fontsize=20)

for a in ax:
a.axis('off')

fig.tight_layout()
plt.show()



Comentários