how to find the distance of all objects in given image

7 ビュー (過去 30 日間)
Rahul punk
Rahul punk 2021 年 5 月 11 日
コメント済み: Rahul punk 2021 年 5 月 22 日

採用された回答

DGM
DGM 2021 年 5 月 11 日
編集済み: DGM 2021 年 5 月 11 日
This will give an array mapping the distance from every object to every other object. You could reduce this with triu() if you want, due to the symmetry.
inpict = rgb2gray(imread('dots.jpeg'))>128;
L = bwlabel(inpict); % this identfies all the objects
C = regionprops(inpict,'centroid');
C = vertcat(C.Centroid);
D = sqrt((C(:,1)-C(:,1).').^2 + (C(:,2)-C(:,2).').^2);
If you wanted to find the distance to the nearest object, you could use this (there are probably other ways).
D(abs(D)<1E-6) = NaN; % remove zeros
[Dn Nn] = min(D,[],2); % minimize
% Dn is distance to nearest neighbor
% Nn is nearest neighbor
.
  18 件のコメント
DGM
DGM 2021 年 5 月 21 日
I don't know what that means.
Rahul punk
Rahul punk 2021 年 5 月 22 日
i d'nt required center distance i have only required corner to corner distances. i agree with DGm Answer.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by