I want to calculate the total centroid of an image stack. For a single image i could use the regionprops() to calculate it as shown here. For a single image my variable c1 is where the coordinates of all the centroids in the image are saved To calculate the total centroid I just summed all coordinates in the image up and divide it by amount of centroids in the picture. The first row should display the x and y coordinates of my total centroid for the first image, the second row for the second image, etc.
% single image
Ilabel = bwlabel(Ibw);stat1 = regionprops(Ilabel,'Area','centroid');c1 = cat(1, stat1.Centroid); % c1 is 16x2
[m1, n1] = size(c1); % m1= 16 amount of centroids in a single image
totalcentroid1 = sum(c1)/m1;
For an image stack my idea was to write a for loop to do this process. My first problem is when i save all centroids for all imagestacks in a variable , that i don't know the exact amount of centroids in a single image to calculate the total centroid of each image. How can i do this ? In the following i tried to implement the calculation of a total centroid for an imagestack. There is error message in this code. How can i fix this issue
%% imagestack
for i=0:options.ImageAmount-1 Ilabel(:,:,i+1) = bwlabel(Ibw(:,:,i+1)); stat1(:,:,i+1) =regionprops(Ilabel(:,:,i+1),'centroid'); %c1(:,:,i+1) = cat(1,stat1.Centroid(:,:,i+1); % unsure aboute this part
%[m1, n1] = size(c1(:,:,i+1));
% totalcentroid1(:,:,i+1) = sum(c1(:,:,i+1)/m1(:,:,i+1);
end%%
Subscripted assignment dimension mismatch.Error in delete (line 126) stat1(:,:,i+1) =regionprops(Ilabel(:,:,i+1),'centroid');
Best Answer