find barycenter of several objects on an image

Illustration
Lechaten - 2021-06-17T14:06:00+00:00
Question: find barycenter of several objects on an image

Hi, I have a logical symmetric matrix in matlab: crossing_table, see attached file as well as the plot of this matrix. I would like to identify the white "blobs" (objects?) that are on the upper part of the image (above the diagonal) and to compute the barycenter of each of these blobs. Is there any Matlab function which would allow me to get the coordinates (indexes) of all pixels of a given blob, for each blob?

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

I just tried the following, I think I am getting close but I am quite there:
 
 
% take the upper part of the matrix (above the diagonal)
crossing_tri=tril(nan(size(crossing_table)))+[tril(crossing_table')]';
% remove the diagonal (with the cloud around it)
for icol=2:size(crossing_tri,2)
     lastblack=find(crossing_tri(1:icol,icol)==0,1,'last');
     crossing_tri(lastblack:icol,icol)=0;
end
% make it a logical matrix (with no NaN)
ab(isnan(crossing_tri))=0;
figure
imshow(crossing_tri)
hold on
s=regionprops(logical(crossing_tri),'Centroid')
centroids=cat(1,s.Centroid)
plot(centroids(:,1),centroids(:,2),'rx')


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!