function [X, Y] = findCOM(wholeMask) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Find the center of mass of the masks contained in wholeMask % Inputs: % - wholeMask: a MxNx number neurons matrix containing the individual % masks of the neurons from a video % Output: % - X: The x coordinates of the center of mass % - Y: The y coordinates of the center of mass %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [a b nNeurons] = size(wholeMask); for k = 1:nNeurons img = wholeMask(:,:,k); [idy,idx] = find(img); id = find(img); X(k,1) = sum(idx.*img(id))/sum(img(id)); Y(k,1) = sum(idy.*img(id))/sum(img(id)); end