How to plot points in pixel coordinates?

47 Ansichten (letzte 30 Tage)
Waleed Khalid
Waleed Khalid am 24 Feb. 2017
Kommentiert: Waleed Khalid am 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.

Akzeptierte Antwort

Arnav Mendiratta
Arnav Mendiratta am 2 Mär. 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 Kommentar
Waleed Khalid
Waleed Khalid am 3 Apr. 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by