How to plot points in pixel coordinates?

47 次查看(过去 30 天)
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.

采纳的回答

Arnav Mendiratta
Arnav Mendiratta 2017-3-2
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')
  1 个评论
Waleed Khalid
Waleed Khalid 2017-4-3
Hi, Thank you so much! That solved my problem!! Just a follow up question, suppose if I want to fill the circles in insertMarker, is it possible?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by