필터 지우기
필터 지우기

compute centroid of a matrix

조회 수: 69 (최근 30일)
Elysi Cochin
Elysi Cochin 2014년 6월 9일
답변: David Lieberman 2017년 8월 10일
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