How to plot some points on an image?

242 views (last 30 days)
Hamed Nazeri
Hamed Nazeri on 24 Feb 2016
Hi all,
I have an image, and I have the coordinates of a few points which I'd like to draw on the image. When using the hold on & plot() functions, the coordinates of the image is from the bottom left corner of the window! not the corner of the figure! Someone help me please!
Thanks,
  1 Comment
Geoff Hayes
Geoff Hayes on 24 Feb 2016
Hamed - can't you just apply an offset (to the y-coordinate) which is the number of rows of the image? For example, if your y-coordinate is 50 and the number of rows in your image is 500, then the transformed y-coordinate would be 500-50=450.

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 24 Feb 2016
You'd have to show us your code. The origin for both the image array and the plotting coordinates is at the upper left, not the bottom left. Run this code:
imshow('cameraman.tif');
axis on
hold on;
% Plot cross at row 100, column 50
plot(50,100, 'r+', 'MarkerSize', 30, 'LineWidth', 2);
Are you sure you're not making the common beginner mistake of mixing up the order of row,column and x,y - remember (x,y) is (column,row) not (row,column).

KSSV
KSSV on 24 Feb 2016
Edited: KSSV on 24 Feb 2016
First you have to read the image using imread. Then you have to fix the axes of the image. Later you can plot your points using hold on and plot.
data = imread('yourimage.ext') ;
image([xmin xmax], [ymin ymax],data);

MathWorks Computer Vision Toolbox Team
MathWorks Computer Vision Toolbox Team on 25 Nov 2024 at 17:10
As demonstrated in the two previous answers, fixing the axes of the image first and then using hold on and plot function should work correctly. Simply calling axis on before hold on, as in the first answer, should fix the axes.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!