MATLAB: Calculating Centroids in a Specfic Region of an Image

calculatingcentroidsspecificregion

Hey !
I am here with a question that I am trying to find the total number of centroid in a specific region. Let say I have an image of which I have calculated the centroids,Now i want to calculate the numbers of centroid of some specific region,for example rectangular bottom portion. Hope will get answer ASAP

Best Answer

I'll assume you have a list of centroids in arrays xCentroids and yCentroids, and that x1, x2, y1, y2 define your rectangular region. So then
xInRange = xCentroids >= x1 & xCentroids <= x2;
yInRange = yCentroids >= y1 & yCentroids <= y2;
bothInRange = xInRange & yInRange;
% Count the number that are in the rectangular region:
count = sum(bothInRange);
If you have a non-rectangular region, like some arbitrarily shaped blob, then let me know.