How to pass from pixel coordinates to real world coordinates?

6 次查看(过去 30 天)
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