Display Clips (Movies) in random order

1 view (last 30 days)
Ari
Ari on 3 Jun 2014
Commented: Image Analyst on 3 Jun 2014
Hi all,
Premise: I am a MATLAB beginner and I am trying to script something for a study. Basically what I am looking for is something very similar to this:
screenNumber=max(Screen('Screens'));
monitor = 0 ;
[ base_window, base_rect ] = Screen( 'OpenWindow', monitor, 0, [], [], 2 ) ;
Screen('TextFont', base_window, 'Calibri' ) ;
Screen('TextSize', base_window, 30 ) ;
wd = '/Users/experiment' ;
stimd = [ wd '/' 'stim' ] ;
textures = [] ;
im_fns = textread( [ wd '/images.txt' ], '%s', 'delimiter', '\n' ) ;
im_labels = strrep( im_fns, '.jpg', '' ) ;
for im_num=1:length( im_fns )
im_fn = im_fns{ im_num } ;
im = imread( [ stimd '/' im_fn ] ) ;
tex = Screen( 'MakeTexture', base_window, im ) ;
textures = [ textures ; tex ] ;
end ;
But, instead of displaying images I need to display in random order video clips that last few seconds. Basically I am looking for an alternative to imread that allows me to play .avi files instead of .jpg images. Is there such a command? Thanks a lot!

Answers (1)

Image Analyst
Image Analyst on 3 Jun 2014
Use randi() to get random numbers with possible repeats. Use randperm to get a random sequence with no repeats. Use movie() to play your avi files.
  2 Comments
Image Analyst
Image Analyst on 3 Jun 2014
Ari says:
Thanks for you answer. I've tried using movie ('file.avi') but it doesn't play the movie, it opens a plot. Am I doing something wrong?
Image Analyst
Image Analyst on 3 Jun 2014
Try something like this I pulled from my code:
% The only video format supported natively by MATLAB is avi.
% A more complicated video player plug in is on MATLAB File Central
% that will support more types of video. It has a bunch of DLL's and
% other files that you have to install.
% Read the file into a MATLAB movie structure.
myVideo = aviread(fullImageFileName);
myVideoParameters = aviinfo(fullImageFileName);
numberOfFrames = myVideoParameters.NumFrames;
% Play the movie in the axes. It doesn't stretch to fit the axes.
% The macro will wait until it finishes before continuing.
axes(handles.axesImage);
hold off;
cla(handles.axesImage, 'reset'); % Let image resize, for example demo video rhinos.avi won't fill the image buffer if we don't do this.
movie(handles.axesImage, myVideo);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!