Sub-pixel edge detection - emsys - Hogeschool voor Wetenschap ...
Sub-pixel edge detection - emsys - Hogeschool voor Wetenschap ...
Sub-pixel edge detection - emsys - Hogeschool voor Wetenschap ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
DE NAYER Instituut<br />
Onderzoeksgroep Digitale Technieken<br />
J. De Nayerlaan 5<br />
B-2860 Sint-Katelijne-Waver<br />
Tel. (015) 31 69 44<br />
Fax. (015) 31 74 53<br />
Email: ppe@denayer.wenk.be<br />
gvd@denayer.wenk.be<br />
bvd@denayer.wenk.be<br />
Website: http://<strong>emsys</strong>.denayer.wenk.be<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong><br />
Version: 1.2<br />
HOBU-fund research project 030106<br />
Title : Multifunctional embedded digital camera system<br />
Project manager : ing. Patrick Pelgrims<br />
Project engineers :<br />
ing. Gerrit Van de Velde<br />
ing. Björn Van de Vondel<br />
Copyright (c)2004 by Patrick Pelgrims, Björn Van de Vondel and Gerrit Van de Velde.<br />
This material may be distributed only subject to the terms and conditions set forth in<br />
the Open Publication License, v1.0 or later (the latest version is presently available at<br />
http://www.opencontent.org/openpub/).<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0
Abstract.<br />
The recent evolution in digital electronics enables the execution of different, highperformance<br />
tasks on compact embedded systems.<br />
For some applications it is necessary to perform very precise measurements,<br />
based on a photographic image. The application mentioned here is part of a<br />
laser-scanning device. An object is scanned by means of a laser and the reflected<br />
beam is captured by an image sensor. It is very important to locate the <strong>edge</strong>s of<br />
the object as exact as possible. The algorithm described below will produce a list<br />
of accurate coordinates of the position of this <strong>edge</strong>.<br />
1. Introduction<br />
From September 1, 2003 until august 31, 2005 researchers from the <strong>Hogeschool</strong><br />
<strong>voor</strong> <strong>Wetenschap</strong> & Kunst, campus De Nayer are conducting an IWT/HOBU-fund<br />
research project about embedded camera systems and applications for such<br />
systems. The main reason for this research is that a large amount of the image<br />
processing tasks are done on a PC, which implies a substantial amount of data to<br />
be transferred from the camera to the image processing unit and vice versa. The<br />
researchers are convinced that, thanks to the recent evolution in embedded<br />
electronics, it has become possible to perform a certain amount of image<br />
processing in the camera itself. The application as described below serves as an<br />
example.<br />
2. Problem definition<br />
When performing a laser<br />
scan of a certain object, the<br />
reflected laser beam is<br />
captured by a CMOS or<br />
CCD imaging sensor. This<br />
produces a very dark image<br />
(nearly black) with a very<br />
bright white line, drawing the<br />
contours of the scanned<br />
object (Fig. 1). Due to<br />
refraction and the limited<br />
number of samples, the line<br />
is not represented with<br />
sharp <strong>edge</strong>s, but becomes<br />
rather blurred.<br />
The challenge for this<br />
algorithm is to determine the<br />
Fig. 1. image after object scanning<br />
exact position of the <strong>edge</strong>s of the object, by performing a sub-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong><br />
procedure on the given image.<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0
3. <strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong><br />
When a bright line on a black background is viewed on sample-level, column by<br />
column, theoretically the pattern obtained is an ideal step-shaped waveform. In<br />
real-life, this waveform is not that ideal, but the line will be a bit more blurred. On<br />
sample-level, the blurring will result into a Gaussian curve. (Fig. 2). This will make<br />
the <strong>detection</strong> of the positive and negative <strong>edge</strong>s even more complex.<br />
The first problem to look at is how to find an<br />
<strong>edge</strong> Let’s get back to the ideal<br />
representation. When calculating a point-topoint<br />
derivative, a ‘peaked’ signal is<br />
obtained. The maximum and minimum of<br />
this differential signal are the positions of<br />
the both <strong>edge</strong>s (positive and negative). So,<br />
the solution to the first problem is quite<br />
simple: calculate the first order derivative<br />
and locate maximum and minimum. (Fig. 3 )<br />
What changes when conditions are not<br />
ideal The effect of non-ideal <strong>edge</strong>s is the<br />
fading of the sharp <strong>edge</strong>s in the<br />
Fig. 3.: the first derivate function to locate<br />
the <strong>edge</strong>s<br />
Fig. 2.: ideal and realistic sample-view of<br />
a line<br />
derivative signal. It might be more<br />
difficult to locate maximum and<br />
minimum, but results can be found.<br />
The challenge starts to occur when a<br />
certain degree of precision is needed.<br />
Theoretically the boundary for the<br />
precision lies with the Nyquistboundary.<br />
Changes at higher<br />
frequencies than the sample rate<br />
divided by two cannot be detected.<br />
Theoretically that is, because in<br />
practice the sub-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> can be used to achieve higher precision.<br />
The algorithm consists of three main parts:<br />
• Part 1: As in the theoretical case, the point-to-point derivate function is<br />
calculated. This function has only valid values on the sample moments of<br />
the original values.<br />
• Part 2: Calculate the second order derivative.<br />
• Part 3: The cubic interpolation technique is used to create a continuous<br />
function out of the sample values obtained in step 2.<br />
• Part 4: To know the exact position of the positive and negative <strong>edge</strong>, the<br />
zero-crossing position for the function from part 3 has to be determined.<br />
The complete sub-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> procedure is illustrated in Fig. 4.<br />
In the following paragraphs the algorithm will be explained more in detail. For<br />
further information on the algorithm or its performance, contact the authors.<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0
The adjacent figure (fig. 4) shows<br />
the different phases of the sub<strong>pixel</strong><br />
<strong>edge</strong> <strong>detection</strong> algorithm. The<br />
first figure (blue sample points),<br />
show the sample-view of the cross<br />
section of an arbitrary line. The<br />
goal of this procedure is to<br />
determine the exact position of the<br />
<strong>edge</strong>s of this line.<br />
The first step to take is to calculate<br />
the first order derivative of this<br />
function. This is shown in the<br />
second part of the figure (red<br />
sample points). The location of the<br />
<strong>edge</strong>s is on the maximum and<br />
minimum of this derivate function.<br />
To determine these positions, the<br />
second order derivative is<br />
calculated (green sample points).<br />
The <strong>edge</strong>s are now located on the<br />
zero-crossings of this function. To<br />
determine these positions very<br />
accurately, this function is<br />
interpolated, as shown in the fourth<br />
part of the drawing. Finally the blue<br />
arrows, point out the exact<br />
positions of the positive (=rising)<br />
and negative (=falling) <strong>edge</strong>s.<br />
Let us go on to the more detailed<br />
explanation of this procedure.<br />
Fig. 4.: Different steps in the sub-<strong>pixel</strong> <strong>edge</strong><br />
<strong>detection</strong><br />
4. First and second order derivatives<br />
The problem of finding the exact position of the <strong>edge</strong> of a sampled line is treated<br />
like a classical extremum problem. This means that, as explained above, the<br />
derivative functions have to be calculated.<br />
Any handbook on mathematics will state that the definition of a derivative function<br />
is as follows:<br />
dy<br />
d(<br />
f ( x))<br />
=<br />
dx<br />
Figure 5 provides some more information.<br />
y2<br />
− y1<br />
=<br />
x2<br />
− x1<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0
In this implementation we respect this definition. For every sample S n , we define<br />
the derivative for that samples as<br />
S n+1 – S n-1 . To completely respect<br />
Y<br />
the mathematical definition we<br />
ought to divide this result by two,<br />
y2<br />
but since we are only interested in<br />
the maximum, we can omit this<br />
constant coefficient. For the second<br />
dy<br />
order derivative, the way to go is<br />
the same as for the first order<br />
y1<br />
derivative. Again, the ½ is omitted<br />
in the result.<br />
To limit the interval in which we<br />
x1<br />
x2<br />
X<br />
have to search for the zero-<br />
dx<br />
crossing of the second order<br />
derivative, the procedure is to find<br />
Fig. 5.: The derivative<br />
and log the maximum and<br />
minimum values of the first order derivative. These values are then used in the<br />
last part of the algorithm.<br />
5. Cubic interpolation<br />
To get a high precision determination of the <strong>edge</strong>s of a line, an interpolation is<br />
implemented. For this purpose the cubic interpolation was chosen. The first thing<br />
to do is to define the number of subsamples to calculate. The algorithm will take<br />
up to four real samples into account (two samples on the left, y 0 and y 1 , and two<br />
samples on the right, y 2 and y 3 ) and calculates a number of subsamples in<br />
between those real sample values.<br />
The heart of this interpolation technique is trying to fit a third order polynomial<br />
onto the discrete function. The formula used is:<br />
3<br />
2<br />
y ( n)<br />
= a * t + a * t + a t + a<br />
0 1<br />
2<br />
*<br />
with the following definitions:<br />
n = the index of the current subsample (n ∈[1..numb_of_subsamp])<br />
y = the interpolated value<br />
n<br />
t =<br />
N<br />
a = y<br />
a<br />
a<br />
a<br />
0<br />
1<br />
2<br />
3<br />
= y<br />
3<br />
0<br />
= y<br />
= y<br />
2<br />
1<br />
− y<br />
− y<br />
2<br />
1<br />
− y<br />
0<br />
− y<br />
− a<br />
0<br />
0<br />
+ y<br />
1<br />
After this interpolation, the results are used in the last step of the algorithm, where<br />
the zero-crossing is determined as accurately as possible.<br />
3<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0
6. Determination of the zero-crossing<br />
Remember that we determined the maximum and minimum values of the first<br />
order derivative. Here, we use those results to narrow down our scope of search<br />
for the zero-crossing. The interval where the search will be conducted, starts at<br />
minimum (or maximum) – numb_of_samples and ends at minimum (or maximum)<br />
+ numb_of_samples.<br />
The procedure will be<br />
Y<br />
Zero-crossing to the left<br />
Index--<br />
Determine value (V) of f”<br />
at MAX_f’<br />
Y<br />
V>0 <br />
N<br />
Zero-crossing to the right<br />
Index++<br />
V>0 V 0<br />
<br />
Zero-crossing to the left<br />
Y<br />
explained for the positive<br />
<strong>edge</strong>, the procedure for<br />
the negative <strong>edge</strong> is very<br />
similar. The algorithm is<br />
shown in figure 6.<br />
The first thing to do is to<br />
determine the value of<br />
the second order<br />
derivative at the point<br />
where the maximum of<br />
the first order derivative<br />
was found. By checking if<br />
this value is less than<br />
zero, the location of the<br />
zero-crossing can be<br />
predicted to be either on<br />
the left or on the right of<br />
the current value (Fig. 7).<br />
After this check, the<br />
algorithm graduately<br />
MAX<br />
V < 0<br />
<br />
Zero-crossing to the right<br />
Fig. 7.: prediction of zero-crossing point<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0
7. Results<br />
When this algorithm is applied to the picture shown in figure 1, figure 8 is<br />
produced. Note that this is just to give some feedback on the algorithm, because it<br />
is impossible to show the results with the same accuracy as they were calculated.<br />
For the more accurate results, a list is also provided with the exact coordinates of<br />
the positive and negative <strong>edge</strong>s.<br />
Fig. 8.: resulting image<br />
column 14: positive <strong>edge</strong> 0.110 past row 62 and negative <strong>edge</strong> 0.980 past row 64.<br />
column 15: positive <strong>edge</strong> 0.040 past row 62 and negative <strong>edge</strong> 0.910 past row 64.<br />
column 16: positive <strong>edge</strong> 0.000 past row 62 and negative <strong>edge</strong> 0.860 past row 64.<br />
column 17: positive <strong>edge</strong> 0.980 past row 61 and negative <strong>edge</strong> 0.900 past row 64.<br />
column 18: positive <strong>edge</strong> 0.050 past row 62 and negative <strong>edge</strong> 0.000 past row 65.<br />
column 19: positive <strong>edge</strong> 0.200 past row 62 and negative <strong>edge</strong> 0.070 past row 65.<br />
column 20: positive <strong>edge</strong> 0.160 past row 68 and negative <strong>edge</strong> 0.900 past row 70.<br />
column 21: positive <strong>edge</strong> 0.220 past row 68 and negative <strong>edge</strong> 0.020 past row 71.<br />
column 22: positive <strong>edge</strong> 0.490 past row 68 and negative <strong>edge</strong> 0.360 past row 71.<br />
column 23: positive <strong>edge</strong> 0.860 past row 68 and negative <strong>edge</strong> 0.840 past row 71.<br />
column 24: positive <strong>edge</strong> 0.140 past row 69 and negative <strong>edge</strong> 0.110 past row 72.<br />
column 25: positive <strong>edge</strong> 0.640 past row 69 and negative <strong>edge</strong> 0.560 past row 72.<br />
…<br />
Fig. 9.: List of exact coordinates<br />
8. Bibliography<br />
• R. A. D. Zanardini, Piecewise Cubic Hermite Interpolation, 2003<br />
• C. Steger, Evaluation of sub<strong>pixel</strong> line and <strong>edge</strong> <strong>detection</strong> precision and<br />
accuracy<br />
<strong>Sub</strong>-<strong>pixel</strong> <strong>edge</strong> <strong>detection</strong> October 2004<br />
ing. Björn Van de Vondel<br />
ing. Gerrit Van de Velde<br />
© OPL v 1.0