Need to find centre of the circle

7 views (last 30 days)
skyimager
skyimager on 1 Mar 2017
Need to find Centre of the black (approx) circle in the image. Please help.

Answers (3)

Frank Macias-Escriva
Frank Macias-Escriva on 2 Mar 2017
Try this code in order to find the center of your "circle"
% some constants for "circle" detection
GRAY_TH = 128; % gray threshold
ECCENTRICITY_TH = 0.5; % eccentricity threshold, from 0(=>circle) to 1(=>line)
% load and convert to a binary image
entropy_img = imread('entropyfilt_imgB.jpg');
bw_entropy_img = entropy_img < GRAY_TH;
imshow(bw_entropy_img); hold on;
% look for region properties
s = regionprops(bw_entropy_img, entropy_img, {'Eccentricity', 'Centroid'});
% keep and plot those close to be a "circle"
numRegions = numel(s);
for k = 1:numRegions
if s(k).Eccentricity < ECCENTRICITY_TH
px = s(k).Centroid(1);
py = s(k).Centroid(2);
ptxt = [' \leftarrow(' num2str(px) ', ' num2str(py) ')'];
text(px, py, ptxt, 'Background', [.5 .5 .5], 'Color', 'blue');
plot(px, py, 'wd', 'MarkerFaceColor', 'blue');
end
end
Of course, you can enhance this piece of code in many ways:
  • Make an interactive tool to adjust "gray" threshold (e.g. slider)
  • Add an input control to ask for eccentricity threshold
  • Allow the user to select the desired "circle" (add 'HitTest', 'on', and 'ButtonDownFcn' callback in the text call. See text and Text Properties)
  • Automatically dismiss the perfect circle (the big one -your lenses) that will be the one with the minimum of your eccentricity values (closest to zero)
Hope this help.

Walter Roberson
Walter Roberson on 1 Mar 2017
Invert your image so the circle is white. imclearborder (or whatever it is called) to clear the white pixels that would introduce at the outside edge. regionprops asking for area and centroid and take the one with the larger area

Image Analyst
Image Analyst on 1 Mar 2017
Invert the image, histogram it and find a good threshold, then threshold to find a binary image. Call imclearborder() and bwareafilt(). Then follow the steps in my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 where I find the centroids of blobs - just what you want to do.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!