MATLAB: After calculating the centroid of an image, which value from the resulting structure is the result

algorithmcentroidimage processingMATLABstructures

Hello everyone, I hope that you could help me solve this:
I am working with image processing, after taking several pictures with a CCD camera I need to find the centroid of each one, and I did it as following:
%Change image to 2bw
for i = 1:1:232
Kft(:,:,i) = im2bw(Kf(:,:,i));
Krt(:,:,i) = im2bw(Kr(:,:,i));
end
%Fill holes
Kft = imfill(Kft,'holes');
Krt = imfill(Krt,'holes');
%Structured element
se = strel('disk',10);
Kft = imopen(Kft,se);
Krt = imopen(Krt,se);
%Centroids
for i = 1:1:232
pf = regionprops(Kft(:,:,i),'centroid');
pr = regionprops(Krt(:,:,i),'centroid');
xy1=cat(1,pf.Centroid);
yz1=cat(1,pr.Centroid);
s(i,:)=xy1(1,:);
h(i,:)=yz1(1,:);
clear xy1
clear yz1
end
However, as you can see I save the 1st element of the xy1 and yz1 variables (which are structures with variable sizes for example "18×2", "25×2", "26×2") and I do not know how the algorithm works or if the first element is the image's centroid.
Greetings!

Best Answer

regionprops assumes (with the syntax you have used) that your images are binary, with a number of disconnected regions of white pixels. The list of centroids xy1 and yz1 that you have formed are the centroids of these disconnected regions.