compute centroid of a matrix

69 次查看(过去 30 天)
how to compute centroid of a matrix? is it possible?

采纳的回答

Matt J
Matt J 2014-6-9
编辑:Matt J 2014-6-9
If you have the Image Processing Toolbox,
regionprops(true(size(matrix)), matrix, 'WeightedCentroid');
Otherwise,
matrix=matrix/sum(matrix(:));
[m,n]=size(matrix);
[I,J]=ndgrid(1:m,1:n);
centroid=[dot(I(:),matrix(:)), dot(J(:),matrix(:))]

更多回答(1 个)

David Lieberman
David Lieberman 2017-8-10
x = sum(sum(matrix).*(1:size(matrix,2)))/sum(sum(matrix))
y is computed similarly

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by