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

20 vues (au cours des 30 derniers jours)
Ahmad Gad
Ahmad Gad le 20 Sep 2022
Commenté : Ahmad Gad le 20 Sep 2022
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 commentaires
Ahmad Gad
Ahmad Gad le 20 Sep 2022
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 le 20 Sep 2022
Please check the attached files. They will work on any mp4 video. Thanks a lot for the help.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Sep 2022
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 commentaire
Ahmad Gad
Ahmad Gad le 20 Sep 2022
Thanks a lot for the help in the answer. They both worked fine.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by