draw line in a picture
Show older comments
Hello guys does anyone know how can i draw a line in a picture.
For example i want to draw a 45 degree red line in the next picture starting from the top left corner of the picture and ending n the other end of the picture.

Accepted Answer
More Answers (1)
MG
on 26 Mar 2021
Would this work for you:
hold on
ax=axis;
x = ax(1:2);
y = ax([3 4]); %might want to change cordinates (check with 'axis on')
line(x,y,'Color','red','LineStyle','-')
4 Comments
Adam Danz
on 26 Mar 2021
What if the axis limits do not start and end at the image bounds or what if the image was plotted using a function like imshow() that produces it's own axes?
MG
on 26 Mar 2021
See Walter's reply. Our two replies were written (almost) simultaneoulsy, and I was not yet awae of his, leaving my addional reply redundant.
Walter Roberson
on 26 Mar 2021
Edited: Walter Roberson
on 26 Mar 2021
In my code, the approaches do not change if you use imshow() instead of image()
lena kappa
on 26 Mar 2021
Categories
Find more on Computer Vision Toolbox 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!

