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.
댓글 수: 0
채택된 답변
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')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!