video in a figure

18 views (last 30 days)
C.G.
C.G. on 10 Mar 2020
Answered: Cedric on 10 Mar 2020
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');

Answers (2)

John D'Errico
John D'Errico on 10 Mar 2020
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 Comment
C.G.
C.G. on 10 Mar 2020
just tried your suggestion and it hasnt worked unfortunatley, video still coming out exactly the same

Sign in to comment.


Cedric
Cedric on 10 Mar 2020
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!