1 Introduction

The importance of automatic circle detection becomes evident considering the variety of computer vision applications for which circle extraction is a key element. For example, some biometric authentication systems rely largely on an accurate iris segmentation [1, 2]. In robotics, on the other hand, circular markers have been used for visual-based localization purposes [3, 4]. Similar applications seize on man-made objects such as traffic signs [5] for autonomous navigation tasks. Regarding industrial and manufacturing applications, circle extraction has been used for autonomous inspection [6, 7], and remote sensing processing used for oil circular depots detection [8, 9]. Given the relevance to this problem, different methods for circle detection have been investigated in order to offer a solution.

The methods based on the Hough transform (HT) have been extensively used due to their effectiveness. The classical Circular HT (CHT) performs an exhaustive exploration of the search space by mapping every point in the input image into a parametric space, replacing the difficult pattern detection in the image space into a local peak searching in the parameter space. This approach makes the CHT robust to noise, yet computationally inefficient. Consequently, some new approaches based on the CHT principles have been proposed to improve both storage and computational requirements. For instance, some methods modify the architecture of the traditional CHT in order to propose a multi-threaded implementation [10], or a FPGA implementation of the CHT [11]. Other approaches exploit the CHT principles in combination with gradient information and curvature analysis. For instance, the Curvature Aided Hough transform for Circle Detection (CACD) algorithm estimates the circle center and radius by adaptively estimating curvature radius [12]. The CACD approach estimates the curvature on the edge-only image to perform a one-to-one vote using accumulator arrays of different radius ranges. Similarly, the work in [13] uses first-order and second-order derivatives to compute a one-to-one dense CHT; however, the method does not performs edge extraction as a preprocessing step.

There are some other recent approaches that also exploit gradient information along with other geometrical properties of circles to perform circle detection. For instance, some work use the fact that the center of a circle lies along the normal direction of edgels, and that the intersection of these normal lines is the center of the circle [14, 15]. In the work of [16], on the other hand, an inverted gradient hash map is used to detect circles by using the fact that pairs of edgels on a circumference differ in orientation by 180 degrees. Another method implements an isosceles triangles sampling to estimate centers and radius [17]. The method performs a refinement process using chords and a linear compensation based on gradient information of edgels.

Other approaches rely on a sampling procedure to reduce the computational time for the circle detection task. An example is a recent method called GRCD-R (Gradient-based Randomized Circle Detection with Refinement) [18]. This method randomly selects four non-collinear edgels. Then, gradient orientation is used to test if the gradient vectors point to the center of a candidate circle. After that validation, three edgels are used to compute a circle, and the last one determines whether the candidate circle is a possible circle in function of its distance to the candidate circumference. Finally, a voting procedure is performed to decide whether possible circles are to be upgraded to detected circles. The work in [19] adds further constraints based on the curvature of the isophotes. Isophotes are curves connecting pixels in the image with equal intensity, whose properties make them particularly suitable for object detection.

Other methods use arc segments instead of edgels to find circles and ellipses in binary images [20, 21]. EDCircles [22], for instance, uses edges extracted by an edge segment extractor named EDPF (Edge Drawing Parameter Free). The edges are then converted into lines, and lines into circular arcs, which are joined together using heuristic algorithms to fit circles and ellipses. To eliminate false detections, EDCircles uses a contrario validation step based on the Helmholtz principle. Their idea is to compute the level line orientation field (which is orthogonal to the gradient orientation field) of a given image, and look for a contiguous set of pixels having similar level line orientation.

The methods described above are efficient, but sometimes they produce false and missing detections. Thence, evolutionary and swarm-based algorithms have been studied as a meta-heuristic manner to perform circle extraction. For example, circle detectors have been proposed using the Differential Evolution approach [23], the Electromagnetism-like optimization (EMO) algorithm [24], the Artificial Bee Colony (ABC) method [25], the Collective Animal Behavoir (CAB) approach [26], the Harmony Search (HS) algorithm [27], and the Clonal Selection Algorithm (CSA) [28]. Unfortunately, despite the fact that many meta-heuristics have been used for the circle detection task, to our knowledge, less effort has been done into exploring the use of gradient information within the search process. In particular, the pattern present in circular shapes within the gradient orientation field has not been used to better guide the search with the objective function.

If the objective function is improperly defined, it can lead to non-acceptable solutions whatever meta-heuristic is used. Most of the reported work evaluates the fitness of an individual by essentially counting the number of pixels in the target edge map that coincide with the perimeter of candidate circles. The fitness value is given by the ratio of candidate to target pixels. They also punish points not exactly on the perimeter of a candidate circle using a displacement factor. A drawback of this approach becomes evident while avoiding small false positive circles and working in noisy conditions. The reason is that this approach tends to favor smaller circles since fewer pixels are required to define a high ratio.

Another drawback of circle detectors based on meta-heuristics is that they need the tuning of several parameters. For these methods, a set of algorithm-specific parameters must be tuned appropriately to accomplish good accuracy and high detection rate when dealing with different image conditions, such as variations in illumination and blurring boundaries. For instance, the DE approach requires the tunning of the differential weight, and the crossover probability. The EMO algorithm, on its part, needs the tunning of the step length. ABC requires tuning of the number of bees (employed, scout, and onlookers), limit, and others. CAB, on its part, requires the probability of attraction, the probability of random movement, and the elite size. Similarly, HS requires tunning of the harmony memory and pitch adjusting rates, and the number of improvisations. In the case of CSA, the mutation rate is to be tuned, along with the clonal size, the length of the antibody and others.

To overcome the aforementioned issues, in this paper we propose, differently from previous meta-heuristic-based circle detectors, the utilization of gradient information to better customize the search space, and to improve the search guidance provided by the objective function. Additionally, in the interest of reducing the number of parameters to tune, we use another natural phenomena inspired optimizer, namely, the Teaching Learning Based Optimization (TLBO) algorithm [29]. The TLBO algorithm does not require the tuning of many parameters in comparison with other meta-heuristics, since only the number of iterations and the size of the population are needed, and no other algorithm-specific parameters need to be tuned.

The rest of the paper is organized as follows. Section 2 describes the TLBO algorithm as used in this work. Section 3 presents the use of the TLBO algorithm for circle detection. Section 4 shows the performance of the algorithm through some tests and comparisons. And finally, Section 5 states the conclusions and future work.

figure c

2 Teaching Learning Based Optimization algorithm

The TLBO algorithm starts with an initialization procedure, where N random solutions (students) Xii ∈{1,⋯ ,N} are generated within the search space. In the TLBO context, the student Xi of the population is a real-valued vector with D elements, where D is the dimension of the problem and is used to represent the number of subjects that an individual enrolls for. The algorithm tries to improve the population by changing individuals during two consecutive phases: The teacher phase and the learner phase. The teacher phase aims to increase the knowledge level of the whole class and to help students individually to get better grades. The learner phase, on its part, attempts knowledge increase through the interaction between students. The algorithm is terminated after a certain number of iterations is completed.

Within the teacher phase, the best individual (best solution) is assigned as the teacher Xteacher. The algorithm attempts to improve other individuals by moving their position towards the position of the teacher by taking into account the current mean value of the individuals. The student position Xi is updated by:

$$ X_{new} = X_{i} + r \cdot (X_{teacher} - T_{F} \cdot X_{mean}), $$
(1)

where r is a real random number between 0 and 1 and TF, called the teaching factor, can be either 1 or 2 and is decided randomly with equal probability. The former equation indicates how the improvement of student Xi may be influenced by the difference between the knowledge of the teacher and the qualities of all students. Thus, Xi is replaced by Xnew if the latter gives better fitness value. The factors TF and r contribute to the exploration and exploitation capabilities of the TLBO algorithm. When TF = 1 and r approximates to 1, the individuals try to approximate the teacher, thus exploiting the search space near to the teacher. Conversely, when TF = 2, the individuals tend to explore far from the teacher according to the value of r.

During the second and final phase, the learner phase, a student learns with the help of other students. Hence, student Xi tries to improve its knowledge by learning from an arbitrary student Xj. In the case that Xj is better than Xi, Xi is moved towards Xj according to:

$$ X_{new} = X_{i} + r \cdot (X_{j} - X_{i}). $$
(2)

Otherwise, it is moved away from Xj according to:

$$ X_{new} = X_{i} + r \cdot (X_{i} - X_{j}). $$
(3)

The objective of this phase is to attain knowledge transfer from a more qualified student to a less qualified student. To this end, Xi is replaced by Xnew if the latter gives better fitness value.

The TLBO algorithm is a successful meta-heuristic method for solving complex optimization problems, still keeping a simple structure and an easy implementation. Thence, several engineering and scientific applications using this meta-heuristic have been published [29,30,31,32]. The simplest form of the TLBO process is described in Algorithm 1. The proposed method adopts this process for circle extraction as explained in the following section.

3 Circle detection using the TLBO algoritm

In this section, we describe the proposed approach for circle extraction. Our method aims different objectives: To have high detection rate and good accuracy in images with cluttered textures, blurring boundaries, low contrast and occluded circles; to detect multiple circles; to work with real images; and to produce a few or no false detections. In order to achieve these objectives, the TLBO algorithm is used, and gradient information is exploited. Since our detector is based on a meta-heuristic, we describe the following elements: The search space organization, the individual representation, and the objective-function definition. Further, we explain the use of gradient orientation for the particular case of circle detection.

3.1 Search space organization

Regarding the organization of the search space, in previous works [23,24,25,26, 28], edge extraction is first performed, to then organize the search space in a set where all edgel locations are indexed one after the other as the edgels are visited in the edge map from left to right and top to bottom. A different approach involves storing edgel locations randomly within the set [33]. These organizations, as stated in [34], do not ensure that nearby pixels in the edge map are neighbors in the search space. This is an important issue to our approach, since the TLBO algorithm locates better individuals in each iteration by shifting them towards the position of the best one. Thus, neighboring individuals within the search space are expected to belong to the same circle and have similar fitness value. Consequently, we perform a different procedure to enhance the search space for the TLBO algorithm. This improvement is achieved by reducing the size of the search space and by customizing its organization, so that its shape better suits the geometric meaning of the TLBO algorithm.

For the search space definition, we use gradient information extracted from image derivatives. First, image noise is reduced by using a 3 × 3 Gaussian filter. Then, edge extraction is performed in order to obtain one-pixel-wide edges. Image derivatives in horizontal (gx) and vertical (gy) directions are performed to extract gradient information, both magnitude and orientation. Gradient magnitude M(x, y) is computed by:

$$ M(x,y) = \sqrt{g_{x}(x,y)^{2} + g_{y}(x,y)^{2}}, $$
(4)

and gradient orientation O(x, y) is obtained by:

$$ O(x,y) = atan2\left( g_{y}(x,y), g_{x}(x,y)\right). $$
(5)

Where atan2(⋅) is the function that returns the value of the arc tangent of gy/gx in radians; the function takes into account the sign of both arguments in order to determine the quadrant.

To perform the image derivatives gx and gy, we convolve the image with derivative kernels. To reduce the error in the gradient computation, the 3 × 3 Sobel operators are used since the accuracy of these operators can be up to 0.12 radians in noiseless conditions [35, 36].

We use gradient magnitude to achieve one of the objectives of the search space enhancement, which is to reduce the search space. This reduction is attained in two steps. Within the first step, all pixels with gradient magnitude lower than a threshold Tm are removed. The threshold Tm is computed as follows:

$$ T_{m} = \tau \cdot M_{mean} $$
(6)

where Mmean is the mean magnitude value for the image as computed by Eq. 4, and τ ∈ [0,1] is the factor that controls the distinctiveness of the magnitude values. When τ is near 1, more pixels are discarded. Conversely, when τ is near 0, less pixels are discarded. Finally, within the second step, the remaining pixels are connected into contours using the border-following algorithm that constructs the adjacency tree of the image [37]. Then, all the contours that are considered too small (i.e. below a threshold Tc pixels) to form a significant part of a circle are removed. To define the threshold Tc, we define a minimum radius rmin and compute Tc as follows:

$$ T_{c} = ceiling(2\pi r_{min}). $$
(7)

In consequence of the previous steps, all edgels with small magnitude are removed as well as the short linked contours. Hence, the result is a smaller edge map organized into connected contours that are sufficiently large to be part of a circle. Also, gradient orientation of the remaining edgels is available. Figure 1 summarizes the operations of the preprocessing steps for the proposed approach.

Fig. 1
figure 1

The preprocessing step aims to reduce the search space and customize its organization. The gray-scale input image in (a) is processed to obtain the edge map as shown in (b). Then, edge pixels with small gradient magnitude are removed to obtain the image in (c). The remaining pixels are connected into contours as shown in (d). However, short contours are not considered to be part of the search space and are consequently removed. Thus, the input information to the proposed method is organized into linked contours large enough to be part of a circle as shown in (e)

The search space is finally organized in a set Vc with edgel locations stored together and ordered according to their respective contour c. Hence, the search space is encoded within the set Vc = {c1, c2,⋯,cn} with n the number of linked contours, and \(c_{i} = \{p_{i_{1}}(x_{i_{1}}, y_{i_{1}} ), {\cdots } , p_{i_{m_{i}}} (x_{i_{m_{i}}}, y_{i_{m_{i}}} )\} \) with mi the number of edgels connected in the i-contour. One result of this organization is an increase of the probability that nearby edgels in the search space belong to the same circle within the edge map, since connected edgels are stored together.

3.2 Individual representation

Each student X of the population encodes a candidate circle C that passes through three different edgels. Thus, to define student X, three different elements are randomly chosen from Vc. Hence, X = {i, j, k}, with i, j and k being the index positions in the search space encoded in Vc for the edgel positions pi(xi, yi), pj(xj, yj) and pk(xk, yk) in the edge map, respectively.

From student X, the center (x0, y0) and the radius r of a candidate circle C are calculated by the following equations:

$$ x_{0}=\frac{\begin{vmatrix} {x_{j}^{2}} + {y_{j}^{2}} - ({x_{j}^{2}} + {y_{i}^{2}}) & 2(y_{j} - y_{i}) \\ {x_{k}^{2}} + {y_{k}^{2}} - ({x_{i}^{2}} + {y_{i}^{2}}) & 2(y_{k} - y_{i}) \end{vmatrix}}{4((x_{j}-x_{i})(y_{k}-y_{i})-(x_{k}-x_{i})(y_{j}-y_{i}))}\ , $$
(8)
$$ y_{0}=\frac{\begin{vmatrix} 2(x_{j} - x_{i}) & {x_{j}^{2}} + {y_{j}^{2}} - ({x_{j}^{2}} + {y_{i}^{2}}) \\ 2(x_{k} - x_{i}) & {x_{k}^{2}} + {y_{k}^{2}} - ({x_{i}^{2}} + {y_{i}^{2}}) \end{vmatrix}}{4((x_{j}-x_{i})(y_{k}-y_{i})-(x_{k}-x_{i})(y_{j}-y_{i}))}\ , $$
(9)

and

$$ r=\sqrt{(x_{0}-x_{d})^{2} + (y_{0}-y_{d})^{2}}\ , $$
(10)

where d ∈{i, j, k}. Therefore, a candidate circle C(x0, y0, r) can be represented by Vc indexes i, j, and k belonging to the student X = {i, j, k}, using (8) through (10).

3.3 Objective function

The last element to define is the objective function that guides the search. Usually, reported meta-heuristic approaches for circle detection only use edgel locations in the objective function [23,24,25,26, 28]. Conversely, our proposed method improve results by using additional data provided by the gradient orientation. However, the pattern of the gradient orientations within a circumference is not the same for a circle with less intensity than the background and a circle with more intensity than the background. This results in a gradient orientation inconsistency problem that needs to be tackled to reliably use gradient orientation in the definition of the objective function.

3.3.1 Orientation alignment

The gradient orientation inconsistency problem is shown in Fig. 2. This problem entails that for the same circle parameters (x0, y0, r), one pixel orientation, say π/2, may belong to a concave segment as in Fig. 2a; or to a convex segment as in Fig. 2b. In other words, the circle parameters encoded by student X is not enough information to assume whether the orientation vectors should point towards or against the center of the circle.

Fig. 2
figure 2

Gradient orientation inconsistency problem. The orientation pattern obtained from image derivatives is different for a circle a brighter than the background, and b darker than the background

To solve the orientation inconsistency problem, the work in [18] uses a set of four 9 × 9 masks to verify whether an edgel belongs to a concave or convex segment. A different mask is used in different sections of the same circumference. Another used strategy involves the computation of second derivatives in order to calculate the contour curvature and decide whether a curve is concave or convex, consequently finding the correct orientation pattern [15]. These techniques are computational expensive or sensitive to noise. Hence, in order to reduce the computational burden, the proposed method partially verifies orientation alignment as now explained.

Instead of verifying whether a pixel belongs to a concave or convex segment, the proposed strategy validates the gradient orientation of a pixel within a circumference regardless it lies o n a concave or a convex segment. In regard to Fig. 2, it is clear that for a circle C with parameters (x0, y0, r), the pixel p1(x0 + r, y0) within the perimeter of C has gradient orientation of either 0 as in Fig. 2a, or π as in Fig. 2b. Likewise, the pixel p2(x0, y0 + r) has an orientation of π/2 as in Fig. 2a, or − π/2 as in Fig. 2b. For all pixels in the perimeter of C, the absolute difference of the two facing valid orientations is always π. We use this fact to verify orientation alignment.

Given the circle parameters (x0, y0, r) encoded by a student X, two valid patterns of gradient orientations can be computed. Taking the case of Fig. 2a for convenience, it is noted that for each pixel pi(xi, yi) within the circumference, the ideal gradient orientation \( \overline {O}_{i} \) can be computed by:

$$ \overline{O}_{i} = atan2\left( y_{i}-y_{0},x_{i}-x_{0}\right). $$
(11)

Thus, the proposed algorithm computes the degree of orientation alignment of the actual orientation Oi of the edgel pi(xi, yi) w.r.t the ideal orientation \( \overline {O}_{i} \) using the following metric:

$$ M(O_{i}) = |cos(|O_{i} - \overline{O}_{i}|)|. $$
(12)

This metric approximates to 1 whether the real gradient vector of pi points towards or against the center of the circle, as long as its orientation approximates to either one of the two valid orientations of the concave and convex cases. On the other hand, the metric approaches 0 as the real gradient vector becomes perpendicular to either of the two valid orientations. According with this metric, the proposed algorithm classifies orientation alignment into three categories:

$$ O_{i}\ \text{alignment} = \left\{\begin{array}{ll} \theta \text{-aligned} & \text{if}\ M(O_{i}) > cos(\theta) \\ \gamma \text{-aligned} & \text{else if}\ M(O_{i}) \!>\! \mathit{cos}(\gamma)\!\!\\ \text{not aligned} & \text{otherwise} \end{array}\right. $$
(13)

Within this classification, the orientation Oi is 𝜃-aligned when it deviates less than 𝜃 radians from either of the two valid orientations. Similarly, the orientation Oi is γ-aligned when it deviates less than γ radians (but more than 𝜃) from either of the two valid orientations. An illustration of the three classifications is shown in Fig. 3.

Fig. 3
figure 3

Orientation alignment. The proposed algorithm categorizes the orientation alignment of each edge pixel into three classifications according to their gradient orientation

The gradient orientation pattern is preserved even in the presence of noise. In Fig. 4, the error between an ideal and a real orientation pattern is shown. To compute the error, the circle parameters are manually detected. Then, a valid gradient orientation \( \overline {O}_{i} \) is computed for each edgel within the circumference. The real gradient orientation Oi, on the other hand, is obtained for the same edgels with derivative kernels. As shown in the figure, for this particular image with different circles of different intensities, the majority of edgels are 𝜃-aligned even in the presence of different levels of Gaussian noise.

Fig. 4
figure 4

Orientation alignment test in real images. a Original image corrupted with different levels of Gaussian noise. 𝜃-aligned edgels are shown in blue, while γ-aligned edgels in red. b Boxplots showing the orientation alignment error of pixels within the circumference of each circle

3.3.2 Objective-function definition

Having defined the orientation alignment, we now describe how it is used in the objective function computation. A well fitted student is the one that encodes a candidate circle that actually exists within the edge map and has a valid gradient orientation pattern. To score a solution, reported meta-heuristic approaches for circle detection do not use gradient information and proceed as follows. For a candidate circle C, a certain amount of test points in the perimeter of C is generated. The value of the classical objective function, Fclassical, is the ratio of the total number of test points appearing in the edge map to the total number of test points. Variations to this conventional objective function include different penalizations as the edge points recede from the test circle. Unfortunately, when in noisy conditions, the quantity of false positive circles may increase using this approach due to the fact that small circumferences may contain enough pixels in the edge map to give a high ratio. For this reason, in the proposed method, additional information provided by the gradient orientation is used in order to surmount the problem.

Given a candidate circle C(x0, y0, r) encoded by a student X, Nc test triplets \( T = \{t_{1} (x_{1} , y_{1} , \overline {O}_{1} ), {\cdots } ,t_{N_{c}} (x_{N_{c}}, y_{N_{c}}, \overline {O}_{N_{c}} )\} \) are generated. In the interest of reducing the computational burden and improving the sub-pixel accuracy, the locations of test points are generated using the Midpoint Circle Algorithm (MCA) [38]. The MCA aims to minimize the error between the pixel discrete positions and the continuous candidate circumference. Additionally, it reduces the computational burden of the algorithm by only computing pixel positions within the first octant of the circumference and mirroring the rest. Gradient orientation of each test point, on the other hand, is computed using (11).

Candidate test points within the perimeter of C must exist in the edge map, and their gradient orientation must be aligned. Thus, the proposed fitness function is computed by:

$$ F_{proposed}(X) = \frac{{\sum}_{i = 1}^{N_{c}} E(x_{i}, y_{i}, \overline{O}_{i})}{N_{c}}, $$
(14)

where E(⋅) is the function that verifies the pixel existence in pi(xi, yi), and its orientation alignment Oi w.r.t \( \overline {O}_{i} \). E returns zero when the test point pi(xi, yi) is not an edgel. On the other hand, when the pixel pi belongs to the edge map, E returns:

$$ E(x_{i}, y_{i}, \overline{O}_{i}) = \left\{\begin{array}{ll} \varphi_{1} \cdot M(O_{i}) & \text{if } \theta \text{-aligned}\\ \varphi_{2} \cdot M(O_{i}) & \text{if } \gamma \text{-aligned}\\ \kappa & \text{if not aligned}, \end{array}\right. $$
(15)

where M(Oi) is the metric for orientation alignment in (12), and the weights φ1, φ2 and κ can be set according to the desired accuracy. We set and fixed the weights empirically to: φ1 = 1, φ2 = 0.5 and κ = 0.25; and the threshold angles to 𝜃 = 0.12 and γ = 0.26 radians. Different values modify the relevance of orientation alignment within the search process.

The example of Fig. 5 illustrates the evaluation of two test points pT1 and pT2 belonging to a circle encoded by student X = {i, j, k}. Since pT1 is 𝜃-aligned, PT1 contributes to Fproposed by a factor of φ1M(oT1). On the contrary, since the test point PT2 is neither 𝜃-aligned nor γ-aligned, it only contributes by a factor of κ. Recall that both PT1 and PT2 belong to the edge map, however PT1 meets the additional orientation test.

Fig. 5
figure 5

Fitness evaluation. a A candidate solution X = {i, j, k} represents a candidate circle C(x0, y0, r). b Two pixels pT1 and pT2 within the perimeter of C are evaluated. Both pixels contribute to the fitness of X. However, pT1 contributes to a greater extent than pT2, since the former meets the additional orientation test

3.4 Implementation of TLBO-based circle detector

The whole circle detection algorithm is summarized in Fig. 6. First, the preprocessing step is performed in order to obtain the edge map, gradient information, and the search space encoded in Vc. Then, the TLBO algorithm is executed. The first step of the TLBO algorithm involves generating the initial population. All the solutions within the first population must consist of three non-collinear points. To achieve this, the algorithm first verifies if the denominator in (8) or 9 is different from zero. If this is not the case, at least two of the points are collinear, and that particular combination of points is not added to the population. Later in the process, in the Teacher an Learner phases, the algorithm prevents individuals consisting in collinear points by assigning a fitness equal to zero if the denominator in (8) or (9) is equal to zero. At the end, the teacher of the last iteration of the TLBO algorithm is selected as the solution.

Fig. 6
figure 6

General procedure of the proposed meta-heuristic-based circle detector

Our proposed method is able to achieve multiple-circle detection. To this end, the proposed method is executed as many times as needed. After one execution, the detected circle is removed from the search space and the edge map. Then, the process is carried out again over the modified search space and edge map. Multiple executions of the whole process are carried out until the algorithm returns a final solution whose fitness value is below a predefined threshold fmin. Finally, every detected circle is validated by analyzing the continuity of the detected circumference segments as in [23].

4 Experimental results

In this section, results of the application of the proposed method on real images are reported, and compared with five different approaches that also use gradient information: 1) The OpenCV implementation of a HT-based circle detector; 2) The isophotes RCD algorithm with the same parameters as in [19]; 3) The on-line demo of EDCircles provided by the authors; 4) the Matlab implementation of CACD provided by the authors; and 5) The classical DE algorithm with the same search space and objective function as the TLBO algorithm. We have selected these methodologies in the interest of contrasting our method with other approaches that also use gradient information, while at the same time are based on different methodologies. The OpenCV implementation is a one-to-many CHT, while the CACD is a one-to-one CHT. Isophotes RCD, on its part, is based on an iterative sampling methodology. EDCircles is an arc-based circle detector; and the DE-based circle detector relies on a meta-heuristic.

The experimental setup includes the use of real images commonly used in the literature: Streetlight (544 × 509), Plates (504 × 489), Bowling (467 × 480), Gobang (234 × 231), Cells (519 × 459), Cell (701 × 664), Watch (467 × 480), Cookies (295×292), Eye (190×143), and Insulator (492 × 553). All the experiments were executed on a 2.80GHz Intel Core i7-7700HQ CPU, with a C+ + implementation of the algorithm. To perform edge extraction and border following, implementations from OpenCV were utilized.

4.1 Parameter setup

The sets of parameters for the meta-heuristics, shown in Tables 1 and 2, have been chosen empirically in favor of performing a fair comparison. First, the settings for the TLBO algorithm were experimentally defined. Then, the parameters of the DE algorithm that control the number of objective function evaluations (FEs) were set specifically to equate this number for both approaches. Finally, the rest of the DE parameters were set after experimentation. On the other hand, the thresholds for the preprocessing step and the multiple-circle detection process were fixed at τ = 0.05, Tc = 2π ⋅ 5 pixels, and fmin = 0.20, respectively. The parameters and thresholds for both meta-heuristics remained fixed for every experiment.

Table 1 Parameter setup for the DE-based circle detector
Table 2 Parameter setup for the TLBO-based circle detector

As stated above, when the number of FEs is the same for all methods, a fair comparison is guaranteed since all algorithms sample the search space an equal number of times. Otherwise, an algorithm with more FEs has, a priori, more chances to provide a better solution, since it gathers more information of the problem. The number of FEs for each approach is now described.

Given M individuals and N iterations, the number of FEs for the TLBO algorithm is

$$ FEs_{TLBO} = (2N + 1)\cdot M. $$
(16)

The above equation is easily deduced considering that in the initialization step for the TLBO algorithm, the objective function is evaluated once for each individual; and that at each iteration, two function evaluations are carried out for each individual (one per step: teacher and learner). Distinctively, the DE-based detector only requires one objective function evaluation at each epoch for each individual, and another within the initialization step. Thus, the number of FEs for the DE algorithm is

$$ FEs_{ED} = (N + 1)\cdot M. $$
(17)

We now describe results related to the convergence of the algorithm, since our approach is based on a meta-heuristic. Then, in the following subsections, we discuss qualitative and quantitative results.

4.2 Convergence analysis

The evolution of the best individual, the mean fitness value and the similarity of the population are examined for every generation. To compute a measure of similarity S for a population P, the student X = {i, j, k} is considered as a vector. Thus, the L2-norm of student X is \(|X|=\sqrt {i^{2} + j^{2} + k^{2}}\). To calculate S, we first compute the L2-norm of each student within P. Then, each output value is divided by the maximum L2-norm value within P. The output of the last computation is a set of values between 0 and 1. We thus define S as the standard deviation of these values. For convenience, S is plotted along with the mean fitness value and the best individual in Fig. 7.

Fig. 7
figure 7

Comparison between different combinations of meta-heuristic, search-space organization, and objective function. a Obtained results with DE optimizing over different search-space organizations and guided by different objective functions. b Results for the TLBO algorithm optimizing over different search-space organizations and guided by different objective functions

Within the convergence analysis, the TLBO and DE algorithms optimize over two different representations of the search space: 1) Edgels locations are indexed in a set V one after the other as they are visited within the edge map from left to right and top to bottom; and 2) Edgels locations are indexed in a set Vc with linked contours as proposed in Section 3.1. Further, to guide the search, two different objective functions are used: 1) The classical objective function Fclasical that only considers edgel locations; and 2) The objective function Fproposed as described in Section 3.3.

Results demonstrate that the proposed combination of an objective function that considers gradient orientation, an adequate search space, and the TLBO algorithm, results in an efficient circle detector. First, we discuss the performance of the proposed objective function. Figure 7 shows the detected circles after one execution of each meta-heuristic. From the figure, it is clear that when Fclassical is used, false positives are detected because they have high fitness value. Conversely, when guided by the proposed objective function, a true circle is detected.

To better explain why our proposed objective function guides more efficiently the search, Fig. 8 depicts that, oppositely to Fclasical, Fproposed clearly differentiates good from bad solutions, since it scores better a true circle than a false positive circle. The last statement is true due to the fact that Fproposed does not only verifies edgels existence in the perimeter of a candidate circumference, but gradient orientation as well.

Fig. 8
figure 8

Comparison between objective functions. a Test image and linked contours. b Two different candidate solutions are to be scored. c Fitness values computed with the classical objective function. d Fitness values obtained with the proposed objective function. Fproposed truly differentiates good from bad solutions by additionally evaluating orientation alignment (𝜃-aligned, green; γ-aligned, red; and not aligned, blue), and not only the existence of edgels within the edge map like Fclassical

By additionally organizing the search space into linked contours, the fitness of the final solution is better, and the TLBO tends to converge. The graphs in Fig. 7b show for the TLBO algorithm that, when optimizing over the unorganized search space V and guided by either of the two objective functions, the search is random, and in consequence the best solution does not evolve. This is true since the similarity of the population remained almost equal throughout the iterations. Conversely, it is only when using the proposed search space representation Vc along with the proposed objective function Fproposed, that a clear evolution and convergence of the population is seen. As a result, the final solution has a higher fitness because the detected circle fits better a true circle. In other words, more edgels with a valid orientation pattern are truly present within the perimeter of the detected circle. Another advantage of the proposed search space representation is that it permits to obtain accuracy while keeping a simple coding.

It is clear that optimizing over Vc and guided by Fproposed, good accuracy is obtained. Furthermore, by also utilizing the TLBO algorithm, results are improved in comparison with the DE approach. We discuss the advantages of the TLBO algorithm by analyzing its exploration and exploitation behavior. In comparison with DE, TLBO explores more the search space as shown by the similarity of the populations in Fig. 7. The DE approach usually converges faster (the similarity becomes zero); this means that the DE algorithm stops searching. Differently, the TLBO algorithm makes more exploration of the search space, since there are more variability within the population while keeping the best solution. By allowing more iterations to DE, no changes in the results would exist. To change the exploration and exploitation capabilities of the DE approach, a different setting of parameters is needed. Conversely, the TLBO algorithm does not require the tunning of algorithm-specific parameters to modify its convergence behavior.

4.3 Image performance

To evaluate the qualitative performance of the TLBO-based detector, several tests were carried out regarding different tasks involving:

  1. 1.

    Circle localization.

  2. 2.

    Multiple circle detection.

  3. 3.

    Blurred and low contrast circle detection.

  4. 4.

    Circular approximation.

  5. 5.

    Circle detection in presence of Gaussian noise.

The relevance of such tasks comes from the fact that they are commonly found in typical computer vision applications.

Results shown in Figs. 9 and 10 demonstrate that the proposed circle detector achieves efficiently every task. Our circle detector found all circles present in the test images despite cluttered textures, blurred and low-contrast circles, occluded circles, and Gaussian noise.

Fig. 9
figure 9

Performance of the six methods for the tasks of circle localization with cluttered textures (column 1), multiple-circle detection (columns 2–4), and blurred or low-contrast circle detection (columns 5–6). The number of detected circles (including false positives) for the best case is indicated

Fig. 10
figure 10

Performance of the six methods in regard to the tasks of circular approximation (columns 1–2), and circle detection under Gaussian noise (column 3–6). The number of detected circles (including false positives) for the best case is indicated

To test the capabilities of the proposed method for the first task, image Streetlight is used. For this task, the TLBO-based detector outperforms the OpenCV implementation and EDCircles. The OpenCV implementation does not fit accurately the circle present in the image; while EDCircles falsely detects a circular shape in the background.

Our method also detects multiple and concentric circles, as shown by the results of the second task. Images Plates, Bowling and Gobang show a better performance of our method in comparison with the Opencv implementation and EDCircles. For instance, EDCircles detects reflections as circles in Bowling and Gobang; while the Opencv implementation does not detect all circles in Plates. Regarding the task of dealing with blurred and low-contrast circle detection, images Cells and Cell are presented. For this task, the TLBO-based detector outperforms the the Opencv implementation, and the CACD algorithm.

For the rest of the tasks, Fig. 10 shows the results involving circular approximation and noisy images. In comparison with other approaches, the proposed detector obtains better results. For instance, the proposed detector outperforms EDCircles in images Watch, Cookies and Eye. EDCircles tends to classify as circles small curves like the number “0” and “9” in image Watch. On the other hand, the Isophotes RCD approach is outperformed by our method in images Eye and Insulator with Gaussian noise.

It is noted that the DE algorithm has a similar performance to the TLBO for the all images, except the image Eye. This is due to the fact that they share the search space and objective function. However, quantitative results described in the next subsection show that the TLBO algorithm obtained better quantitative accuracy.

4.4 Performance evaluation

To obtain quantitative information of the accuracy of all detectors, a score metric is used to quantify their performance. Results from the methods are compared to a manually detected ground-truth circle using this score metric. Further, to compute a statistical analysis, the meta-heuristic-based circle detectors were executed 100 times for each test image.

The metric to evaluate a quantitative performance looks at the percent overlap of the circle area. The overlap error Eo is calculated as:

$$ E_{o} = 1 - \frac{\overline{C_{1} \cap C_{2}}}{\overline{C_{1}\cup C_{2}}}, $$
(18)

where the second term is the overlap percentage, and is the area of the overlap between circle 1, C1 and circle 2, C2, divided by the area of the union of the circles. For multiple circle evaluation, the average value of the Eo errors, \(M_{E_{o}}\), is calculated by:

$$ M_{E_{o}} = \left( \frac{1}{NC}\right)\cdot \sum\limits_{i = 1}^{NC}E_{o_{i}}, $$
(19)

where NC is the total number of detected circles in the test image.

For the meta-heuristic approaches, we also compute a success rate Sr as now explained. Given an specific image, let CGT be the set of ground truth circles, and CD the set of circles detected by the method. For each circle in CD, we find the match circle in CGT subject to Eo < 0.20. Only one circle in CD is accepted as a valid match per ground truth circle. Then, all the accepted circles are considered as true positives and stored in a set CTP. Finally, we compute the success rate Sr as follows:

$$ S_{r} = \frac{card(C_{TP})}{max(card(C_{GT}),card(C_{D}))}, $$
(20)

where card(⋅) returns the cardinality of a set. It is noted that Sr is equal to 1 when all the ground truth circles are found and no false positives are detected. Differently, when all ground truth circles are found, but false positives are detected, Sr decreases. The more false positives are detected or the less ground truth circles are found, the more Sr decreases and approximates to 0. Also, Sr is equal to 0 when there are no found circles by the method that match the ground truth circles. Sr penalizes even multiple detections of circles with similar centers and radii. The succes rate Sr allows us to obtain a measure of the performance of the algorithm to detect all ground truth circles and discard false positives. The error Eo, on the other hand, when applied only to circles in CTP, allow us to obtain a measure of the accuracy of the detected true-positives circles.

Quantitative results are shown in Tables 3 and 4. Table 3 exposes the average time, average error, and success rate for the meta-heuristic approaches. Table 4, on its part, shows the time and error for the non-meta-heuristic approaches. In the case of EDCircles, computational time is omitted since the on-line demo provided by the authors was used.

Table 3 Average time, average Eo error, and success rate for the meta-heuristic methods, considering the test images in Figs. 9 and 10
Table 4 Time and Eo error for the non-meta-heuristic methods, considering the test images in Figs. 9 and 10

5 Conclusions

In this paper, we presented a meta-heuristic circle detector based on the TLBO algorithm. The proposed method differs from previous meta-heuristic approaches in the way that it uses additional information provided by the gradient to customize the search space, and to better guide the search with a novel objective function.

In comparison with other approaches, the results obtained by the TLBO-based detector required less effort from the user because there are less parameters to tune for this particular meta-heuristic. This is an advantage in comparison to other meta-heuristic approaches, and even to the OpenCV CHT and the isophotes RCD algorithms that also require the set of various parameters. To test the performance of the proposed approach, computation time and accuracy have been compared with five different approaches based on different principles: The OpenCV CHT, the isophotes RCD algorithm, EDCircles, CACD, and a meta-heuristic based on DE. We used a score metric to evaluate the mismatch between a ground-truth circle and the detected circle. Also, since our proposed circle detector is based on a meta-heuristic, an evaluation of the convergence of the algorithm was performed.

Our approach accurately detects circles in real images despite the presence of cluttered textures, circle occlusions, blurred effects, and Gaussian noise. Further, the detected circles hold a sub-pixel accuracy due to the use of the circle equation and the MCA method.

In future work, we will make efforts to expand our method to detect ellipses and reduce the computation time; and also to explore the use of gradient magnitude, and not only orientation in the objective function, since usually pixels of the same circumference have similar magnitude values.