find barycenter of several objects on an image

L
Lechaten · Jun 17, 2021 · 1.9K views
Question
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 PhD Expert
Answered Aug 25, 2026
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')
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!