AD ALTA
JOURNAL OF INTERDISCIPLINARY RESEARCH
AUTOMATIC HYSTERESIS OF CANNY EDGE DETECTOR FOR LINES DETECTION
a
LUBOS JURANEK
Mendel University in Brno,
Zemědělská 1, Brno, Czech Republic
email:
a
xjuranek@node.mendelu.cz
Abstract: The Canny edge detector is a very popular multi-stage algorithm for image
edge detection and its output is frequently used as an input for the Hough transform
algorithm for identification of lines. Its crucial step is the edge tracking by hysteresis,
which selects the final edges by using two thresholds. The assessment of those two
values in an unsupervised way is a difficult task, that is usually solved by application
of statistical functions to the values of intensity of the input image converted to
grayscale. This paper’s objective is to experimentally prove, that it is more convenient
not to use the input image, but instead the gradient image, which is the output of the
Sobel gradient operator. The paper also revealed that with using the 2:1 ratio between
the upper and lower threshold and the upper threshold to be set around 55 % of the
maximum value of gradient image, the line detection reaches much better results.
Keywords: Canny, Hough, Hysteresis.
1 Introduction
The Canny edge detector is a very popular multi-stage algorithm
for image edge detection, which has uses in many applications of
computer vision, mainly in image data preprocessing. Its
popularity is also indicated by the fact that, unless we don’t
count the simple gradient operators, it is the only implemented
edge detector in the currently most used computer vision and
image processing library – OpenCV.
The Canny edge detector algorithm consists of four steps:
removing the noise with Gaussian filter, finding the intensity
gradient with the Sobel gradient operator, non-maximum
suppression and edge tracking by hysteresis (Canny, 1986). The
last step, the edge tracking by hysteresis, is crucial, since selects
the final edges by using two thresholds. The assessment of those
two values in an unsupervised way is a difficult task that is yet to
be solved in a satisfactory manner. Therefore, these values are
usually set manually based on experiments (Medina-Carnicer et
al., 2010).
The hysteresis divides all pixels of an image into three groups
according to the three intervals set by the thresholds. If a pixel
has a value higher than the upper threshold, it is considered an
edge. Should its value be below the lower threshold, it is
considered an inconsequential edge and it is discarded. And
lastly, should the pixel’s value be between both thresholds, the
pixel is considered an edge only if it lay next to another pixel
already considered an edge.
The Canny edge detector output, a binary image, is frequently
used as an input for the Hough transform algorithm for
identification of miscellaneous geometric shapes in the original
image, most frequently lines. This papers’s subject is the
problematic of automatic determining of the thresholds for
hysteresis used in the Canny edge detector. In contrast to the
majority of papers dealing with this subject, its focus is not the
detection of all the edges in an image, but the detection of those
edges which allow to correctly detect lines using the Hough
transform algorithm.
For this purpose, the determination of the thresholds, is usually
recommended to be based on the results of statistical functions,
such as the arithmetic mean or median, applied to the values of
intensity of the input image converted to grayscale. Another way
leading to the thresholds is to use the fractions of the output of
Otsu’s method algorithm for automatically performing
thresholding of graylevel image (Fang et al., 2009). This paper’s
objective is to experimentally prove, that it is more convenient
not to use the input image, but instead the map of the gradient at
each point, which is the output of the Sobel gradient operator,
thus pointing the direction for the ensuing research in this field.
2 Materials and Methods
All the programming for the purpose of this paper was done in
programming language Python 2.7.8 using the NumPy
fundamental package for scientific computing and the
aforementioned computer vision library OpenCV in version
3.1.0. This implies that also the implementation of the Canny
edge detector comes from the implementation used in this
library.
The Gaussian blur with square matrix of order 5 is used for the
image noise reduction. To find the gradient magnitudes we used
the Sobel gradient operator size 3x3 (1) as a convolution kernel,
namely twice, for horizontal (G
x
) and vertical (G
y
) first
derivative approximations.
(1)
The values of pixels G
x
and G
y
therefore may reach maximum
of 1020 and a minimum of -1020. We can also derive that, if a
pixel G
x
has its maximum value 1020, pixel G
y
highest value is
510 and vice versa, as shown in the examples of an image before
the convolution (2), where X is the currently processed pixel.
The highest possible sum of both values is therefore 1530.
(2)
For the calculation of the edge gradient in the Canny edge
detector from OpenCV in default settings, every pixel is
processed by a function (3) using absolute values. A more
correct and more accurate method would be to use an another
function (4), which is, however, slower because of the use of
powers and roots. With the first method, G values range between
0 and the highest possible sum of G
x
and G
y
, 1530; with the
second, which we will be using, G values range between 0 and
cca. 1140.395.
(3)
(4)
On this range, by testing all the options and subsequent
evaluation by sensory observation, whereas the ratio between the
upper and lower threshold will be tested in two variants: 3:1 and
2:1, we will be doing an experimental search for the best
thresholds for the hysteresis. Sensory observation will be
performed on the output of the Hough transform for line
detection, which will follow directly after the edge detection.
The Heath set of images (1997), which is still often used for the
comparison of methods of edge detection, will be used as test
images. The Hough transform will in all cases be statically set,
with the resolution of one pixel and one degree and a minimum
number of intersections equal to a hundred in Hough space to
line detection.
3 Results
Table 1 shows information about the test images ordered by
name in first column (Heath et al., 1997) and the results of the
experiments. In columns „maximum“, „mean“ and „median“ are
the results of the corresponding functions applied to gradient
values. Columns „3:1“ and „2:1“ contain the resulting intervals
of the best upper threshold values.
- 257 -