4

I have a very basic code that uses the standardized HoughCircles command in openCV to detect a circle. However, my problem is that my data (images) are generated using an algorithm (for the purpose of data simulation) that plots a point in the range of +-15% (randomly in this range) of r (where r is the radius of the circle, that has been randomly generated to be between 5 and 10 (real numbers)) and does so for 360 degrees using the equation of a circle. (Attached a sample image). https://i.stack.imgur.com/OOj0a.jpg Now using the Hough circle command, I was able to detect a circle of approximately the same radius by manually playing around with the parameters (by settings up trackbars, inspired from a github code of the same nature) but I want to automate the process as I have over a 1000 images that I want to do this over and over on. Is there a better way to do that? Or if anyone has any suggestions, I would highly appreciate them as I am a beginner in the field of image processing and have a physics background rather than a CS one. A rough sample of my code (without trackbars etc is below):

Mat img = imread("C:\\Users\\walee\\Documents\\MATLAB\\plot_2 .jpeg", 0);
Mat cimg,copy;
copy = img;
medianBlur(img, img, 5);
GaussianBlur(img, img, Size(1, 5), 1.1, 0);

cvtColor(img, cimg, COLOR_GRAY2BGR);
vector<Vec3f> circles;
HoughCircles(img, circles, HOUGH_GRADIENT,1, 10, 94, 57, 120, 250);
for (size_t i = 0; i < circles.size(); i++)
{
    Vec3i c = circles[i];
    circle(cimg, Point(c[0], c[1]), c[2], Scalar(0, 0, 255), 1, LINE_AA);
    circle(cimg, Point(c[0], c[1]), 2, Scalar(0, 255, 0), 1, LINE_AA);
}
imshow("detected circles", cimg);
waitKey();
return 0;
WaleeK
  • 71
  • 8

1 Answers1

0

If all images have the same nature (black axis and points as circles) I would suggest to do following:

1) remove axis by finding black elements and replace them with background

2) invert colours to have black background

3) perform morphological closing to fill the circles and create more solid points

4) (optional) if the density of the points is high you can try to apply another morphological operation, namely dilation to make the data circle thinner

5) apply Hough circle

MateuszB
  • 320
  • 1
  • 9
  • I will fill the circles and get back to you asap as doing that is easy. (since it is a simulation and I can control the data I give the program, the non filled circles was just me being lazy during data generation). As for inverting colors, I was under the impression binarizing the image made the image only black and white, am I wrong in that assumption? – WaleeK Feb 14 '17 at 08:39
  • That's correct - binarization makes the image black and white. I just want to assure that background is black and the foreground is white. Otherwise morphological operations would work as opposite. – MateuszB Feb 14 '17 at 09:06
  • I tried all of that and while it did improve results for the first few pictures, the program failed to do it for more images. I also thought of implementing a sort of a search algo for the perfect value of accumulator array to detect the best single circle but then the program started to detect circles a bit smaller than the ones I intended it too. – WaleeK Feb 21 '17 at 10:39
  • Can you post some exemplary image that fails? Also mark found circle and the one you would like to get – MateuszB Feb 21 '17 at 11:56