'''Task:''' Write a program that performs so-called [[wp:Canny edge detector|canny edge detection]] on an image. A possible algorithm consists of the following steps: # '''Noise reduction.''' May be performed by [[wp:Gaussian blur|Gaussian filter]]. # Compute '''intensity gradient''' (matrices G_x and G_y) and its '''magnitude''' G.
   G=\sqrt{G_x^2+G_y^2}
May be performed by [[image convolution|convolution of an image]] with [[wp:Sobel operator|Sobel operators]]. # '''Non-maximum suppression.''' For each pixel compute the orientation of intensity gradient vector: \theta = {\rm atan2}\left(G_y, \, G_x\right). Transform angle \theta to one of four directions: 0, 45, 90, 135 degrees. Compute new array N: if
   G\left(p_a\right)
where p is the current pixel, p_a and p_b are the two neighbour pixels in the direction of gradient, then N(p) = G(p), otherwise N(p) = 0. Nonzero pixels in resulting array correspond to local maxima of G in direction \theta(p). # '''Tracing edges with hysteresis.''' At this stage two thresholds for the values of G are introduced: T_{min} and T_{max}. Starting from pixels with N(p) \geqslant T_{max} find all paths of pixels with N(p) \geqslant T_{min} and put them to the resulting image.