필터 지우기
필터 지우기

How to pass from pixel coordinates to real world coordinates?

조회 수: 4 (최근 30일)
Gargolla9
Gargolla9 2022년 7월 1일
편집: Gargolla9 2022년 9월 15일
Hi everyone! I have the following problem. I have obtained a binary image M that has value 1 when there is the obstacle, otherwise value 0 and then I have calculated the centroids of each cluster of pixels in this way.
s = regionprops(M,'centroid');
centroids = cat(1,s.Centroid);
figure
plot(centroids(:,1), centroids(:,2),'b*')
Now i would like to know how do i get these centroid values from pixel coordinates back to real world coordinates. How can i do? Thanks in advance.

채택된 답변

Voss
Voss 2022년 7월 1일
편집: Voss 2022년 7월 1일
unzip reticolato_centroids.zip
load reticolato_centroids.mat
x = -1600:3:1600; %real world coordinate
y = -1200:3:1200; %real world coordinate
s = regionprops(M,'centroid');
centroids = cat(1,s.Centroid);
% linear transform from
% pixel indices to [x y ]
% [1 1] -> [x(1) y(1) ]
% size(M,[2 1]) -> [x(end) y(end)]
centroids_real_world = (centroids-1)./(size(M,[2 1])-1).*[x(end)-x(1) y(end)-y(1)]+[x(1) y(1)];
figure
plot(xv,yv,'.r')
hold on
plot(centroids_real_world(:,1), centroids_real_world(:,2),'b.')
figure
set(pcolor(M),'EdgeColor','none')
hold on
plot(centroids(:,1), centroids(:,2),'m.')
% linear transform from
% [x y ] to pixel indices
% [x(1) y(1) ] -> [1 1]
% [x(end) y(end)] -> size(M,[2 1])
limits = ([-400 -100; 300 600]-[x(1) y(1)])./[x(end)-x(1) y(end)-y(1)].*(size(M,[2 1])-1)+1;
xlim(limits(:,1))
ylim(limits(:,2))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by