Note that there are some explanatory texts on larger screens.

plurals
  1. PORobustly find N circles with the same diameter: alternative to bruteforcing Hough transform threshold
    primarykey
    data
    text
    <p>I am developing application to track small animals in Petri dishes (or other circular containers). Before any tracking takes place, the first few frames are used to define areas. Each dish will match an circular independent static area (i.e. will not be updated during tracking). The user can request the program to try to find dishes from the original image and use them as areas.</p> <p>Here are examples: <img src="https://i.stack.imgur.com/eij4O.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/gKZvU.jpg" alt="enter image description here"></p> <p>In order to perform this task, I am using <strong>Hough Circle Transform</strong>. But in practice, different users will have very different settings and images and I do not want to ask the user to manually define the parameters. I cannot just guess all the parameters either.</p> <p>However, I have got additional informations that I would like to use:</p> <p>I know the exact number of circles to be detected.</p> <ul> <li>All the circles have the almost same dimensions.</li> <li>The circles cannot overlap.</li> <li>I have a rough idea of the minimal and maximal size of the circles.</li> <li>The circles must be entirely in the picture.</li> </ul> <p>I can therefore narrow down the number of parameters to define to one: <strong>the threshold</strong>. Using these informations and considering that I have got N circles to find, <strong>my current solution is to test many values of threshold and keep the circles between which the standard deviation is the smallest</strong> (since all the circles should have a similar size):</p> <pre><code>//at this point, minRad and maxRad were calculated from the size of the image and the number of circles to find. //assuming circles should altogether fill more than 1/3 of the images but cannot be altogether larger than the image. //N is the integer number of circles to find. //img is the picture of the scene (filtered). //the vectors containing the detected circles and the --so far-- best circles found. std::vector&lt;cv::Vec3f&gt; circles, bestCircles; //the score of the --so far-- best set of circles double bestSsem = 0; for(int t=5; t&lt;400 ; t=t+2){ //Apply Hough Circles with the threshold t cv::HoughCircles(img, circles, CV_HOUGH_GRADIENT, 3, minRad*2, t,3, minRad, maxRad ); if(circles.size() &gt;= N){ //call a routine to give a score to this set of circles according to the similarity of their radii double ssem = scoreSetOfCircles(circles,N); //if no circles are recorded yet, or if the score of this set of circles is higher than the former best if( bestCircles.size() &lt; N || ssem &gt; bestSsem){ //this set become the temporary best set of circles bestCircles=circles; bestSsem=ssem; } } } </code></pre> <p>With:</p> <pre><code> //the methods to assess how good is a set of circle (the more similar the circles are, the higher is ssem) double scoreSetOfCircles(std::vector&lt;cv::Vec3f&gt; circles, int N){ double ssem=0, sum = 0; double mean; for(unsigned int j=0;j&lt;N;j++){ sum = sum + circles[j][2]; } mean = sum/N; for(unsigned int j=0;j&lt;N;j++){ double em = mean - circles[j][2]; ssem = 1/(ssem + em*em); } return ssem; </code></pre> <p>}</p> <p>I have reached a higher accuracy by performing a second pass in which I repeated this algorithm narrowing the [minRad:maxRad] interval using the result of the first pass.</p> <p>For instance minRad2 = 0.95 * average radius of best circles and maxRad2 = 1.05 * average radius of best circles.</p> <p>I had fairly good results using this method so far. However, it is slow and rather dirty. My questions are:</p> <ul> <li>Can you thing of any alternative algorithm to solve this problem in a cleaner/faster manner ?</li> <li>Or what would you suggest to improve this algorithm?</li> <li>Do you think I should investigate generalised Hough transform ?</li> </ul> <p>Thank you for your answers and suggestions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload