Borrar filtros
Borrar filtros

compute centroid of a matrix

69 visualizaciones (últimos 30 días)
Elysi Cochin
Elysi Cochin el 9 de Jun. de 2014
Respondida: David Lieberman el 10 de Ag. de 2017
how to compute centroid of a matrix? is it possible?

Respuesta aceptada

Matt J
Matt J el 9 de Jun. de 2014
Editada: Matt J el 9 de Jun. de 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(:))]

Más respuestas (1)

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by