Figure to movie frame with set size
Afficher commentaires plus anciens
I'm generating movie frames from figures using the getframe function. However, I need the movie frame matrix output to be of a certain size (a set dimension in pixel units for each frame). I have tried
set(gca,'Units','pixels','Position',[10 10 sizeX sizeY])
But when I export the movie frame the cdata of the frame never seems to be the same size as sizeX and sizeY. There is change in the size of the frame, but it doesn't end up identical.
I know I could just resize the output frames to the size I want, but under some circumstances it resizes away edges and other effects mess up the final result, so it would be preferable if I could get the correct output size directly from the figure.
Réponse acceptée
Plus de réponses (4)
Image Analyst
le 30 Sep 2018
0 votes
What do you mean by resize and export? You mean "on screen" or the actual image size in pixels? And export how? To a disk file or to a movie variable?
See my movie resizing demo, attached.
Image Analyst
le 30 Sep 2018
0 votes
Try truesize(), or see the attached demo.
5 commentaires
Oscar Frick
le 1 Oct 2018
Image Analyst
le 1 Oct 2018
Modifié(e) : Image Analyst
le 1 Oct 2018
If I project my image onto a secondary display, my laptop display and the external display will show all pixels on both screens but the physical size will be different because the display is a different size. Are you hoping to control the physical size of the image regardless of the size of the monitor it's displayed on?
Oscar Frick
le 2 Oct 2018
sam l
le 25 Août 2020
Hi
I have similare issue regarding the figure plot frame size controlling.
I am plotting a figure inside for looop - create a array to store the frame size.
Even I am using the gcf to enter the required frame size, the plot frame size is different and it changes after some steps. The figure plot has 4 subplots - three are in 3D plot..
Could you help if I can get a constant frame size, so I am able to create a vedio animation.


Image Analyst
le 25 Août 2020
You can call imresize() after you get thisFrame to set it to the exact size you want.
Eduardo Vicente Wolf Trentini
le 26 Nov 2022
0 votes
I had the same problem as you and finally managed to solve it.
The problem is the camera's field of view.
In this link I comment about:
Yes, display scaling will affect this. In Windows, it's in the settings. I tested that in a remote linux server the size is the one specified using fig.Position, since there's no display. If you want a scaling different from the display scaling, we can do
fig = figure();
frame = getframe(gcf);
img = frame2im(frame);
img = imresize(img, scale);
writeVideo(video, img);
Catégories
En savoir plus sur Image Arithmetic 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!