フィルターのクリア

Measuring distance between centroid and perimeter points

1 回表示 (過去 30 日間)
ISABELLE GUNDRUM
ISABELLE GUNDRUM 2022 年 3 月 8 日
回答済み: KSSV 2022 年 3 月 8 日
My code currently allows me to draw three polygons on an image and then plot the centroid. How do I measure the distance between the centroid and each perimeter point?
Here is my current code:
close all, imshow(I),
for k = 1:3
title(['Polygon # ' int2str(k)]);
h = drawpolygon;
wait(h);
centroid=mean(h.Position);
drawpoint('Position',centroid,'Label','Centroid');
c{k}(1:2) = round([cx cy],0); % unit: pixels
c{k}(3) = round(area(polyin{k}),0)*p2cm; % unit: cm^2
disp(['Centroid of polygon: [' int2str([cx cy]) ']'])
disp(['Area of polygon = ' int2str(c{k}(3)) 'cm^2'])
end
Thanks!

回答 (1 件)

KSSV
KSSV 2022 年 3 月 8 日
If C is your centroid coordinates and P is your m*2 array of points. Where m is the number of points. Then you can get the distance using:
d = sqrt((C(1)-P(:,1)).^2+(C(2)-P(:,2)).^2) ;
Alo have a look on pdist2.

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by