Convert image coordinate to cartesian coordinates
36 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
vidhathri bhat
on 27 Jun 2019
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
0 Comments
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!