2. Algorithms
This implementation is based on the classical Hough transformation on the
detection of circles not lines. An edge point on a possible circle is transformed
in 3-D (corresponding the center x, y and radius r of a circle) Hough space
into a series of 3-D circles (asuming that the Hough parameter space is quantized
with same quantum size) with different possible radii.
To successfully map between the two spaces, I divide one Hough circle (in
Hough space) into four parts by drawing two lines (across the center of the
circle) with + 45 and -45 degres: the upper, lower, left and right arcs. The
upper and lower are symetric to X-axis, and the left and right ones to Y-axis.
Thus time can be saved. For example, in the case of the upper and lower parts:
we only check the calculated Y's values corresponding to the limited range
of X-values, to check if the Y's are in the right range given a certain radius.
Therefore, we don't worry about the scenario in which, for a certain X-value,
there are two or more Y's values as in the case if the left and right parts.
Because we also check X's values (in the right and left parts ) for a certain
Y's value in the limited range of Y's values given the same radius. This
algorithm is implemented in the function
onePixelHough().
The overall pseudocode for the whole Hough transformation on detection of
circles can be shown as follows (with the function names in
Bold Italic
style font):
Read in an image;
To do edge detection via
sobel_image() or
canny_image();
Allocate memory according to the input parameters (quantum size...)
houghInitial();
For every possible radius
imageHough()
For every edget point
imageHough()
Do Hough transformation (as described
above)
onePixelHough();
Find the clusters of circles
siftCircles();
Draw the clusters of circles
drawCircles()
Do local maxima suppression on the clusters of circles
findLocalMaximaCircles();
Draw the found circles for the objects
drawCircles()
Print fitting errors
calculateFE().
3. Results
I also combined the original image, the edge image, the detected cluster
circles, and the chosen circles for the coins into
animated GIFs,
to illustrate the effect.
3.1. For image 0.17.pgm
Quantum size: 3
Canny detection.
Circles found:
Found Circle at (x, y): 121 97 radius = 33
The counting at that is: 219
Found Circle at (x, y): 181 175 radius = 39
The counting at that is: 212
Found Circle at (x, y): 184 49 radius = 33
The counting at that is: 205
Found Circle at (x, y): 247 109 radius = 30
The counting at that is: 146
Fitting errors:
circle 0's fitting error = 0.743979
circle 1's fitting error = 1.12208
circle 2's fitting error = 1.00431
circle 3's fitting error = 0.571544
3.2. For image 0.51.pgm
Quantum size: 3
Canny detection.
Circles found:
Found Circle at (x, y): 112 124 radius = 42
The counting at that is: 265
Found Circle at (x, y): 160 49 radius = 36
The counting at that is: 182
Found Circle at (x, y): 157 199 radius = 33
The counting at that is: 178
Found Circle at (x, y): 205 124 radius = 33
The counting at that is: 131
Found Circle at (x, y): 232 52 radius = 30
The counting at that is: 122
Fitting errors:
circle 0's fitting error = 0.800763
circle 1's fitting error = 0.931437
circle 2's fitting error = 0.8733
circle 8's fitting error = 0.794179
circle 15's fitting error = 0.427138
3.3. For image 0.55.pgm
Quantum size: 3
Canny detection.
Circles found:
Found Circle at (x, y): 85 91 radius = 36
The counting at that is: 237
Found Circle at (x, y): 226 169 radius = 42
The counting at that is: 201
Found Circle at (x, y): 166 55 radius = 30
The counting at that is: 159
Found Circle at (x, y): 253 64 radius = 39
The counting at that is: 137
Found Circle at (x, y): 136 160 radius = 30
The counting at that is: 114
Fitting errors:
circle 0's fitting error = 0.751669
circle 1's fitting error = 0.455776
circle 4's fitting error = 0.416067
circle 10's fitting error = 1.8783
circle 18's fitting error = 0.299396
3.4. For image 0.65.pgm
Quantum size: 3
Canny detection.
Circles found:
Found Circle at (x, y): 181 49 radius = 42
The counting at that is: 218
Found Circle at (x, y): 259 172 radius = 42
The counting at that is: 188
Found Circle at (x, y): 130 133 radius = 36
The counting at that is: 172
Found Circle at (x, y): 274 58 radius = 30
The counting at that is: 136
Fitting errors:
circle 0's fitting error = 1.20831
circle 1's fitting error = 0.533899
circle 3's fitting error = 0.292817
circle 15's fitting error = 0.206657
3.5. For image 1.30.pgm
Quantum size: 3
Canny detection.
Circles found:
Found Circle at (x, y): 136 64 radius = 42
The counting at that is: 188
Found Circle at (x, y): 244 73 radius = 45
The counting at that is: 183
Found Circle at (x, y): 148 160 radius = 39
The counting at that is: 151
Fitting errors:
circle 0's fitting error = 0.831777
circle 1's fitting error = 0.675452
circle 9's fitting error = 0.533545
3.6. For image 1.31.pgm
Quantum size: 3
Canny detection.
Circles found:
Found Circle at (x, y): 127 169 radius = 45
The counting at that is: 207
Found Circle at (x, y): 250 166 radius = 42
The counting at that is: 206
Found Circle at (x, y): 145 76 radius = 33
The counting at that is: 178
Found Circle at (x, y): 226 61 radius = 36
The counting at that is: 163
Fitting errors:
circle 0's fitting error = 0.421831
circle 1's fitting error = 0.478089
circle 4's fitting error = 1.17561
circle 6's fitting error = 0.892615
3.7. For image overlap4.pgm
Quantum size: 2
Canny detection.
Circles found:
Found Circle at (x, y): 149 75 radius = 44
The counting at that is: 198
Found Circle at (x, y): 149 135 radius = 40
The counting at that is: 174
Fitting errors:
circle 0's fitting error = 0.9896
circle 2's fitting error = 0.871773
3.8. For image overlap5.pgm
Quantum size: 2
Canny detection.
Circles found:
Found Circle at (x, y): 193 129 radius = 60
The counting at that is: 264
Found Circle at (x, y): 127 125 radius = 66
The counting at that is: 241
Fitting errors:
circle 0's fitting error = 0.998168
circle 1's fitting error = 0.443005
3.9. For image overlap6.pgm
Quantum size: 2
Canny detection.
Circles found (1058 4116 as low/high threshold).
Found Circle at (x, y): 125 123 radius = 34
The counting at that is: 150
Found Circle at (x, y): 171 117 radius = 30
The counting at that is: 121
Fitting errors:
circle 0's fitting error = 0.773281
circle 3's fitting error = 0.709851
4. Analysis
The pseudocode is in the above (section 2, algorithm) which also describes
the quantization of Hough parameter space. The quantum size is in pixels.
We have use 2 or 3 to obtain the above results.
4.1. Sensitivity to quantum size
Generally, the larger the quantum size, the less the accurary on the found
circles. We now do the Hough transformation on overlap6.pgm with same parameters
as in the case of above 3.9 but with different quantum size.
Following with same parameters but quantum size = 4: the fitting errors are
larger than that in 3.9.
Found Circle at (x, y): 122 122 radius = 32
The counting at that is: 192
Found Circle at (x, y): 174 118 radius = 32
The counting at that is: 191
circle 0's fitting error = 1.21912
circle 1's fitting error = 2.31457