How to pass from pixel coordinates to real world coordinates?

11 visualizaciones (últimos 30 días)
Gargolla9
Gargolla9 el 1 de Jul. de 2022
Editada: Gargolla9 el 15 de Sept. de 2022
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.

Respuesta aceptada

Voss
Voss el 1 de Jul. de 2022
Editada: Voss el 1 de Jul. de 2022
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))

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by