필터 지우기
필터 지우기

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

조회 수: 20 (최근 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 CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by