Canny edge detector: Difference between revisions

m
added whitespace and split some long lines (with equations) into multiple lines.
(Canny edge detector en Java)
m (added whitespace and split some long lines (with equations) into multiple lines.)
Line 1:
{{task|Image processing}}
{{task|Image processing}}'''Task:''' Write a program that performs so-called [[wp:Canny edge detector|canny edge detection]] on an image.
 
;Task:
{{task|Image processing}}'''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''' &nbsp; (matrices <math>G_x</math> and <math>G_y</math>) &nbsp; and its '''magnitude''' &nbsp; <math>G</math>.:<br> &nbsp; &nbsp; &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.''' &nbsp; <br>For each pixel compute the orientation of intensity gradient vector: &nbsp; <math>\theta = {\rm atan2}\left(G_y, \, G_x\right)</math>. &nbsp; &nbsp; <br>Transform &nbsp; angle <math>\theta</math> &nbsp; to one of four directions: &nbsp; 0, &nbsp;45, &nbsp;90, &nbsp;135 &nbsp;degrees. &nbsp; &nbsp; <br>Compute new array &nbsp; <math>N</math>: &nbsp; &nbsp; if<br> &nbsp; &nbsp; &nbsp; &nbsp; <math>G\left(p_a\right)<G\left(p\right)<G\left(p_b\right)</math><br>where &nbsp; <math>p</math> &nbsp; is the current pixel, &nbsp; <math>p_a</math> &nbsp; and &nbsp; <math>p_b</math> &nbsp; are the two neighbour pixels in the direction of gradient, &nbsp; <br>then &nbsp; &nbsp; <math>N(p) = G(p)</math>, &nbsp; &nbsp; &nbsp; otherwise &nbsp; <math>N(p) = 0</math>. &nbsp; <br>Nonzero pixels in resulting array correspond to local maxima of &nbsp; <math>G</math> &nbsp; in direction &nbsp; <math>\theta(p)</math>.
# '''Tracing edges with hysteresis.''' &nbsp; <br>At this stage two thresholds for the values of &nbsp; <math>G</math> &nbsp; are introduced: &nbsp; <math>T_{min}</math> &nbsp; and &nbsp; <math>T_{max}</math>. &nbsp; <br>Starting from pixels with &nbsp; <math>N(p) \geqslant T_{max}</math>, &nbsp; find all paths of pixels with &nbsp; <math>N(p) \geqslant T_{min}</math> &nbsp; and put them to the resulting image.
<br><br>
 
=={{header|C}}==