MATLAB: How to do to get centriod (x,y coordinates) for each point in binary image

binaryimageImage Processing Toolbox

Hi I am trying to get the x,y coordinates of dot points (in binary image) as shown in below pic (dotfig.png) using the code:
A=imread('dotfig.png');
B=im2bw(A)
[b,a]=find(B==0);
So, I get coordinates in terms of a,b for rows and cols. I got multiple a and multiple b (for 7 dots in pic). Actually, I just would like to get seven a and seven b, which represent seven dots in the pic. I understand that each dot has many pixel points, therefore, I got multiple a and b for each dot. However, is there anyway I can do that will give me only seven pairs of (a and b) that represents centriod of seven dots. I know
[x,y]=ginput()
might work, but i would like to avoid manual input as my code is part of very long codes.

Best Answer

Use regionprops():
labeledImage = bwlabel(B);
measurements = regionprops(labeledImage, 'Centroid');
measurements is a structure array where the field is the centroid. For example measurements(8).Centroid is an array [x, y] with the x and y centroid of the 8th blob.