Effacer les filtres
Effacer les filtres

compute centroid of a matrix

69 vues (au cours des 30 derniers jours)
Elysi Cochin
Elysi Cochin le 9 Juin 2014
how to compute centroid of a matrix? is it possible?

Réponse acceptée

Matt J
Matt J le 9 Juin 2014
Modifié(e) : Matt J le 9 Juin 2014
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(:))]

Plus de réponses (1)

David Lieberman
David Lieberman le 10 Août 2017
x = sum(sum(matrix).*(1:size(matrix,2)))/sum(sum(matrix))
y is computed similarly

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by