How can I get a Zoom In/Out value for a figure in MATLAB?

22 次查看(过去 30 天)
Hello all.
I have a script that automatically moves through a video file frame by frame. At each frame, I manually click on any pixel in the figure and MATLAB record the coordinates of the selected pixel and moves automatically to the next frame.
The problem is when I zoom in at any frame, I lose the zooming when MATLAB moves to the next frame, and I have to zoom manually at each frame, which is impractical in my application.
Therefore, I am looking for a zooming function/object that can record the current zoom and so I can carry it to the following frame. The zoom object in MATLAB doesn't have the ability to get the current value/factor of the zoom.
Can anyone help with workarounds?
Thanks all.
  3 个评论
Ahmad Gad
Ahmad Gad 2022-9-20
I use imagesc(Data) to display the image, and I use simplified version of ginput() to record the click and a loop to move to the next Frame. I have edited the question and uploaded the scripts.
Ahmad Gad
Ahmad Gad 2022-9-20
Please check the attached files. They will work on any mp4 video. Thanks a lot for the help.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2022-9-20
You are using imagesc() in a loop. You do not have hold turned on, and you have not configured the axes NextPlot behaviour.
In such a situation, each time you imagesc(), the code for imagesc() internally calls nextplot, which looks at the axes NextPlot property. The default for that property is 'replace' -- which deletes all axes children and resets all axes properties except the Units and Positions properties. That includes clearing any Xlim, Ylim, and any internal recordings of zoom levels.
If you were to
set(gca, 'NextPlot', 'replacechildren')
then it would delete the children but the only axes properties it would reset would be the ColorOrderIdx and LineStyleOrderIdx properties -- so it would preserve the zoom level.
But an even better way of handling this situation would be to first, before the loop, do
h = imagesc();
and then inside the loop, delete the imagesc() and replace it with
h.CData = Data;
That will not change any axes properties (except possibly xlim and ylim and ticks if the image is a different size). And it is more efficient.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by