Plotting points on top of image (imshow) (uiaxes)

조회 수: 30 (최근 30일)
Doctor G
Doctor G 2015년 4월 22일
답변: Daksh 2023년 1월 31일
I had the following code (which works) that does an imshow raster data and then plots red dots on top of a list of markers (I.e. the base layer is an image of stars, and the overlay is red dots that mark them).
function plot(this)
imshow(WORLD.image, [0 1]);
hold on
plot([this.centers.x], [this.centers.y], 'r.');
hold off
end
OK, now I am using GUIDE to create the GUI, and I have the imshow using the parent property to get the image inside of a ui-axes. That part works, but the plot does not seem to take Parent, and besides hold on and hold off does not work (it creates a new window with the plot). How do I fix this? [handles.pictureBox is the handle for the axes control]
imshow(WORLD.mask, [0 1], 'Parent', handles.pictureBox);
hold on
plot([p.centers.x], [p.centers.y], 'r.', 'Parent', handles.pictureBox);
hold off
What I observe is that if I remove the hold on, hold off, then the base image is replaced by the plot. But if I leave it in, the same thing happens, but a pop-up also shown.
  댓글 수: 2
Doctor G
Doctor G 2015년 4월 22일
Oh yes, It is very important that the scale of the axis be maintained between the image and the plot. Right now, I see the plot adjusting the x,y bounds. If the imshow is a image of 1K x 1K, then I want the plot range to be exactly the same so that the labels overlay.
Doctor G
Doctor G 2015년 4월 23일
I waited two days, and tried stack overflow. I got a great answer in a few hours:

댓글을 달려면 로그인하십시오.

답변 (1개)

Daksh
Daksh 2023년 1월 31일
I understand that you're experiencing issues with plotting points on top of image while using GUIDE and using "hold on" and "hold off" as "plot()" method seems to be not taking the parent handle for your case.
As per the R2022b documentation for MATLAB, "plot" method indeed accepts a parent handle, kindly refer to this link:
plot(handles.pictureBox,[p.centers.x], [p.centers.y], 'r.');
Furthermore, "hold" ("on" and "off" both) also accepts axes handle, kindly use them as follows:
hold(handles.pictureBox,'on');
Hope this helps!

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by