video in a figure

19 次查看(过去 30 天)
C.G.
C.G. 2020-3-10
回答: Cedric 2020-3-10
I have imported a video into MATLAB but when I play this in a figure, the figure dimensions are different to that of the video. Is there a way to change this and make it fit?
%Input video using videoreader and name it 'obj'
obj = VideoReader('highamballvideo.mov')
%Tell it to read the frames in the video where 20 is start and 34 finish
frames_no = [20:34];
vidFrames = read(obj,[20 34]);
%Tell it to get the number of individual frames in the video
numFrames = size(vidFrames,4);
%Get individual frames
%Colormap is a table of colors used for index color videos
%c.data is an image sequence matrix
%How many times you repeat a function in a loop is defined by 'k'. k = the
%range of values the for loop will run through before ending.
for k = 1: numFrames
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];
end
%Watch the video
figure(1), movie(mov, 1, obj.FrameRate), title('Original movie');

回答(2 个)

John D'Errico
John D'Errico 2020-3-10
Usually the trick is to use the command:
axis tight
to force a set of axes to fit tightly to what is plotted inside them, minimizing the white space.
  1 个评论
C.G.
C.G. 2020-3-10
just tried your suggestion and it hasnt worked unfortunatley, video still coming out exactly the same

请先登录,再进行评论。


Cedric
Cedric 2020-3-10
The reason is indicated in the doc: "The movie function uses a default figure size of 560-by-420 and does not resize figures to fit movies with larger or smaller frames. To accommodate other frame sizes, you can resize the figure to fit the movie."
There are many threads about it, e.g.:

标签

Community Treasure Hunt

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

Start Hunting!

Translated by