How to plot points in pixel coordinates?
43 views (last 30 days)
Show older comments
Waleed Khalid
on 24 Feb 2017
Commented: Waleed Khalid
on 3 Apr 2017
Hi, I want to plot points at exact pixel coordinates in a figure. I have tried scatter plot and fixing the axis+figure and then saving the resulting image via print_f command. However, that doesn;t give me what I desire as end up back with matlab's auto axis and the points are plotted on an arbitrary axis rather than a fixed one. I want this so I can run some vector calculation in c++ (required) and no I can't do this manually as I have to generate a 1000 images this way and to do all those manually is not possible.
x0=0;
y0=0;
width=500;
height=500;
hold on
scatter(250,250);
scatter(260,250);
set(gca,'units','pixels','position',[0,0,500,500])
set(gcf,'units','pixels','position',[x0,y0,width,height])
eval(['print -djpeg fixedr_' '.jpeg']);
This is a snippet of the code I am trying, this gives me a figure of 781x781 (which is annoying on its own as it should be 500x500). of course I will change the code drastically and just want to know how I can plot points at exact pixel coordinates rather than matlab's inherent auto axis.
0 Comments
Accepted Answer
Arnav Mendiratta
on 2 Mar 2017
Hi,
You get different size of printed image possibly because the axes are printed as well. In your code you are setting the position of the figure and axes handles such that they are hidden from user view but they do exist.
A better snippet of code that achieves what you are trying to accomplish is this:
Img = zeros(500,500);
markerPos = [250 250; 250 260];
markedImg = insertMarker(Img, markerPos, 'size', 3);
imshow(markedImg)
imwrite(markedImg, 'fixedr.jpg')
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!