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

22 ビュー (過去 30 日間)
Ahmad Gad
Ahmad Gad 2022 年 9 月 20 日
コメント済み: Ahmad Gad 2022 年 9 月 20 日
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.
  1 件のコメント
Ahmad Gad
Ahmad Gad 2022 年 9 月 20 日
Thanks a lot for the help in the answer. They both worked fine.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying 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