'''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 <math>G_x</math> and <math>G_y</math>) and its '''magnitude''' <math>G</math>.<br>&nbsp;&nbsp;&nbsp;<math>G=\sqrt{G_x^2+G_y^2}</math><br> 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: <math>\theta = {\rm atan2}\left(G_y, \, G_x\right)</math>. Transform angle <math>\theta</math> to one of four directions: 0, 45, 90, 135 degrees. Compute new array <math>N</math>: if<br>&nbsp;&nbsp;&nbsp;<math>G\left(p_a\right)<G\left(p\right)<G\left(p_b\right)</math><br>where <math>p</math> is the current pixel, <math>p_a</math> and <math>p_b</math> are the two neighbour pixels in the direction of gradient, then <math>N(p) = G(p)</math>, otherwise <math>N(p) = 0</math>. Nonzero pixels in resulting array correspond to local maxima of <math>G</math> in direction <math>\theta(p)</math>.
# '''Tracing edges with hysteresis.''' At this stage two thresholds for the values of <math>G</math> are introduced: <math>T_{min}</math> and <math>T_{max}</math>. Starting from pixels with <math>N(p) \geqslant T_{max}</math> find all paths of pixels with <math>N(p) \geqslant T_{min}</math> and put them to the resulting image.
