Convert image coordinate to cartesian coordinates

18 ビュー (過去 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 Center および File ExchangeSpecifying 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