Hide figure while using geframe/videowriter function

I am using the function getframe in order to obtain frames from a figure and the videowriter to create a video from those frames. I need to hide the figure during the process. I used the command set(gcf,'visible','off') but the process stops with an error message popping up. It states that the frames obtained from the function getframe are not of the same size. Is there a solution or another way to overcome this problem? Thanks in advance.

Réponses (1)

Ameer Hamza
Ameer Hamza le 25 Avr 2020
Modifié(e) : Ameer Hamza le 25 Avr 2020
Call getframe with the axes handle
frame = getframe(gca); % gca is the current axes handle
It will only return the image of the axes.

8 commentaires

Thank you for your response Ameer. I used gca instead of gcf but again nothing. In case I was misunderstood, I need to hide the whole figure window. When I use either gca or gcf along with set(gcf, 'visible', 'off') the process stops with error message stating "Frame must be 478 by 336". In case that I use gcf the message states "Frame must be 560 by 420". When I don't use set(gcf, 'visible', 'off') both gcf and gca do the job.
If I understand correctly, you first want to make the figure window invisible and then apply the getframe on it. Right?
Which MATLAB release are you using. I am able to do it in R2020a.
R2016b. Are you able to do it also with gcf in R2020a?
Yes, following code work without any error on R2020a
plot(1:10);
set(gcf, 'Visible', 'off');
frame = getframe(gcf);
imshow(frame.cdata)
Paschalis Garouniatis
Paschalis Garouniatis le 26 Avr 2020
Modifié(e) : Paschalis Garouniatis le 26 Avr 2020
Your code works also with my MATLAB release. If it is possible try your code using the videoWriter function. My figure is an animation using plot function and illustrates a moving object. With some digging I found that getframe() cannot work with hidden figures and even if we use set(gcf,'visible','off') the figure window still pops up. In my case though, as I mentioned above, there is a problem with different frame size obtained using getframe() from each step of the plot. I think this has to do with the fact that the first frame size determines the size that will be used from the videoWriter. Anyway thank you for your time.
Can you write a small code snippet which gives an error with videoWriter?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Animation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by