Canny edge detector: Difference between revisions
Content added Content deleted
m (added whitespace and split some long lines (with equations) into multiple lines.) |
m (added whitespace between numbered bullet points.) |
||
Line 3: | Line 3: | ||
;Task: |
;Task: |
||
Write a program that performs so-called [[wp:Canny edge detector|canny edge detection]] on an image. |
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: |
A possible algorithm consists of the following steps: |
||
# '''Noise reduction.''' May be performed by [[wp:Gaussian blur|Gaussian filter]]. |
# '''Noise reduction.''' May be performed by [[wp:Gaussian blur|Gaussian filter]]. <br> |
||
# Compute '''intensity gradient''' (matrices <math>G_x</math> and <math>G_y</math>) and its '''magnitude''' <math>G</math>:<br> <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]]. |
# Compute '''intensity gradient''' (matrices <math>G_x</math> and <math>G_y</math>) and its '''magnitude''' <math>G</math>:<br> <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]]. <br> |
||
# '''Non-maximum suppression.''' <br>For each pixel compute the orientation of intensity gradient vector: <math>\theta = {\rm atan2}\left(G_y, \, G_x\right)</math>. <br>Transform angle <math>\theta</math> to one of four directions: 0, 45, 90, 135 degrees. <br>Compute new array <math>N</math>: if <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, <br>then <math>N(p) = G(p)</math>, otherwise <math>N(p) = 0</math>. <br>Nonzero pixels in resulting array correspond to local maxima of <math>G</math> in direction <math>\theta(p)</math>. |
# '''Non-maximum suppression.''' <br>For each pixel compute the orientation of intensity gradient vector: <math>\theta = {\rm atan2}\left(G_y, \, G_x\right)</math>. <br>Transform angle <math>\theta</math> to one of four directions: 0, 45, 90, 135 degrees. <br>Compute new array <math>N</math>: if <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, <br>then <math>N(p) = G(p)</math>, otherwise <math>N(p) = 0</math>. <br>Nonzero pixels in resulting array correspond to local maxima of <math>G</math> in direction <math>\theta(p)</math>. <br> |
||
# '''Tracing edges with hysteresis.''' <br>At this stage two thresholds for the values of <math>G</math> are introduced: <math>T_{min}</math> and <math>T_{max}</math>. <br>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. |
# '''Tracing edges with hysteresis.''' <br>At this stage two thresholds for the values of <math>G</math> are introduced: <math>T_{min}</math> and <math>T_{max}</math>. <br>Starting from pixels with <math>N(p) \geqslant T_{max}</math>, <br>find all paths of pixels with <math>N(p) \geqslant T_{min}</math> and put them to the resulting image. |
||
<br><br> |
<br><br> |
||