How measure distance from center of the image to the object

4 ビュー (過去 30 日間)
Malik Malik
Malik Malik 2019 年 5 月 22 日
編集済み: Malik Malik 2019 年 5 月 22 日
Hi,
I have an image in which i want to measure the distance in pixels from the center of the image to the object as shown in the attached image. any suggestions how to do that? The object will move and get closer to the center of the image so my intenstion is to keep track of that distance. i think if i would be able to measuer the distance from this image i could extend that to rest.
Looking forward to your kind suggestions
Regards
Malik

採用された回答

KSSV
KSSV 2019 年 5 月 22 日
YOu can measure the distance from center of the object to center of the image as below:
I = imread('object_with problem.png');
% Center of image
[nx,ny,nz] = size(I) ;
[X,Y] = meshgrid(1:ny,1:nx) ;
O = [mean(X(:)) mean(Y(:))] ;
%%
I1 = rgb2gray(I) ;
[y,x] = find(I1) ;
A = [mean(x) mean(y)] ;
%% distance
d = sqrt((O(1)-A(1))^2+(O(2)-A(2))^2) ;
  1 件のコメント
Malik Malik
Malik Malik 2019 年 5 月 22 日
編集済み: Malik Malik 2019 年 5 月 22 日
Thank you KSSV!
After your suggestion realized that i am already measuring the object length, and i could use the end point of the object and subtract it from the center of the image to get the distance.
Best Regards
Malik

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

その他の回答 (0 件)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by