Convert image coordinate to cartesian coordinates

조회 수: 30 (최근 30일)
Kami
Kami 2019년 6월 26일
답변: vidhathri bhat 2019년 6월 27일
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