How to plot points in pixel coordinates?

41 visualizaciones (últimos 30 días)
Waleed Khalid
Waleed Khalid el 24 de Feb. de 2017
Comentada: Waleed Khalid el 3 de Abr. de 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.

Respuesta aceptada

Arnav Mendiratta
Arnav Mendiratta el 2 de Mzo. de 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')
  1 comentario
Waleed Khalid
Waleed Khalid el 3 de Abr. de 2017
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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by