Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating the coordinates for the center of a circle in an image

enter image description here

Say I have this image and I want to get the center of each circle in (X , Y).

Is there an algorithm to do so in MatLab??

like image 844
HSN Avatar asked Nov 13 '12 20:11

HSN


1 Answers

That's possible with one call to regionprops:

img = imread('KxJEJ.jpg');                      % read the image
imgbw = ~im2bw(img,graythresh(img));            % convert to grayscale

stats  = regionprops(bwlabel(imgbw), 'centroid','area'); % call regionprops to find centroid and area of all connected objects
area = [stats.Area];                            % extract area
centre = cat(1,stats.Centroid);                 % extract centroids

centre = centre(area>10,:);                     % filter out dust specks in the image

Now centre contains an Nx2 array: first column is x-position, second column is y-position of the centres:

centre =

   289.82       451.73
   661.41       461.21
   1000.8       478.01
   1346.7       482.98
like image 188
Gunther Struyf Avatar answered Sep 30 '22 01:09

Gunther Struyf