Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a few things you can do to improve your results. To reduce noise in the image, you can apply a median blur before applying the Canny operator. This is a common de-noising technique. Also, try to avoid using the C API and <code>IplImage</code>.</p> <pre><code> cv::Mat img = cv::imread("c:\\dot1.bmp", 0); // dot1.bmp = Fig. 1 cv::medianBlur(img, img, 7); // Perform canny edge detection cv::Canny(img, img, 33, 100); </code></pre> <p>This significantly reduces the amount of noise in your edge image: <img src="https://i.stack.imgur.com/ZYYsQ.png" alt="Canny result"></p> <p>To better retain the original sizes of your dots, you can perform a few iterations of morphological closing with a smaller kernel rather than dilation. This will also reduce joining of the dots with the circle:</p> <pre><code>// This replaces the call to dilate() cv::morphologyEx(src, dilation, MORPH_CLOSE, cv::noArray(),cv::Point(-1,-1),2); </code></pre> <p>This will perform two iterations with a 3x3 kernel, indicated by using <code>cv::noArray()</code>.</p> <p>The result is cleaner, and the dots are completely filled:</p> <p><img src="https://i.stack.imgur.com/IOuyg.png" alt="Closing result"></p> <p>Leaving the rest of your pipeline unmodified gives the final result. There are still a few spurious mass centers from the circle, but considerably fewer than the original method:</p> <p><img src="https://i.stack.imgur.com/ZPCZX.png" alt="Mass centers"></p> <p>If you wanted to attempt removing the circle from the results entirely, you could try using <a href="http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?#houghcircles" rel="noreferrer"><code>cv::HoughCircles()</code></a> and adjusting the parameters until you get a good result. This might have some difficulties because the entire circle is not visible in the image, only segments, but I recommend you experiment with it. If you did detect the innermost circle, you could use it as a mask to filter out external mass centers.</p>
 

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