How to pass from pixel coordinates to real world coordinates?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
Voss
am 1 Jul. 2022
Bearbeitet: Voss
am 1 Jul. 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))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!