Convert image coordinate to cartesian coordinates

36 次查看(过去 30 天)
Given a image canvas I with 2 points (a_x, a_y) and (b_x, b_y). The plotted line on the image has the correct orientation.
However, when I plot the same coordinates (a and b) in a cartesian coordinate system, I get a line with the wrong orientation.
I would like to convert the image coordinates that they match with the cartesian system. Thanks.
% Create image canvas
canvas = zeros(320, 320);
I = uint8(canvas);
imshow(I)
a_x = 122.6544;
a_y = 234.9782;
b_x = 165.9290;
b_y = 126.9200;
hold on
plot([a_x, b_x], [a_y, b_y] )
% Plot cartesian coordinate system
figure()
plot([a_x, b_x], [a_y, b_y])
xlim([0 320])
ylim([0 320])
axis equal
grid on

回答(1 个)

vidhathri bhat
vidhathri bhat 2019-6-27
Hi,
In an image (0,0) co-ordinate is at top-left and in cartesian co-ordinate system it is at bottom left. That is why you are getting different orientation when you plot with same co-ordinates in both. In images 'y' co-ordinate grows in opposite direction to that of normal cartesian co-ordinate system. Just flip the y co-ordinate values while plotting in cartesian plot and you will get the correct orientation.
canvas = zeros(320, 320);
I = uint8(canvas);
imshow(I)
a_x = 122.6544;
a_y = 234.9782;
b_x = 165.9290;
b_y = 126.9200;
hold on
plot([a_x,b_x],[a_y,b_y] )
%Plot cartesian coordinate system
figure()
plot([a_x, b_x], [-a_y, -b_y])
xlim([0 320])
ylim([-320 0])
axis equal
grid on
Hope this helps

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by