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??
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With