grayImage = imread('nameimg.png');
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
binaryImage = im2bw(grayImage);
[labeledImage, numBlobs] = bwlabel(grayImage);
props = regionprops(labeledImage,'Centroid')
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end);
yCentroids = allCentroids(2:2:end);
Best Answer