AsiJapan
AsiJapan

Reputation: 313

Draw angle line over an image - Matlab

Why the angle line I draw is not the correct one. instead of the 45 deg I get the 315?

Script:

clc;
clear;
url='http://clipart-library.com/images/Bcgrakezi.png';
I = imread(url);
imshow(I);
hold on;

[y1,x1,z1] = size(I);
cy=y1/2;
cx=x1/2;

sz = 50;
scatter(cx,cy,sz,'d')

lineLength = 250;
angle = 45;
xAngleLine(1) = cx;
yAngleLine(1) = cy;
xAngleLine(2) = xAngleLine(1) + lineLength * cosd(angle);
yAngleLine(2) = yAngleLine(1) + lineLength * sind(angle);
plot(xAngleLine, yAngleLine,'g','LineWidth',5);

Upvotes: 1

Views: 113

Answers (2)

gnovice
gnovice

Reputation: 125854

When showing images, such as with imshow or image, MATLAB inverts the y axis. This is so the first row of the image data (lowest row index) appears at the top of the plot. To account for this, you therefore need to flip the sign in the second-to-last line of code to a negative:

yAngleLine(2) = yAngleLine(1) - lineLength * sind(angle);

Upvotes: 2

Cris Luengo
Cris Luengo

Reputation: 60444

imshow turns the y-axis up-side down. You can see this with:

get(gca,'YDir')

Which will say either 'normal' (y-axis ticks increase upwards), or 'reverse' (y-axis ticks increase downwards). In your case you'll see 'reverse'.

You can also do

axis on

to see the tick marks and values.

Upvotes: 1

Related Questions