Last active
December 27, 2023 06:49
-
-
Save iandol/b0a0f7cf7febb882cf73a4d21bca9d7d to your computer and use it in GitHub Desktop.
Create stimulus frame movie from a previous opticka experiment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% This script loads a previous opticka experiment, then uses the screen and | |
% stimulus and task values to generate a series of movies or pictures for | |
% each stimulus frame. This assumes a single variable (i.e. angle). It runs | |
% 0.25 only showing fixation cross, then 1.5 secs of the stimulus, then | |
% another 0.25 seconds blank. | |
%% | |
% lets load from the saved MAT file | |
[mat,p] = uigetfile('*.mat','Select the Experiment MAT file'); | |
if isnumeric(mat); return; end | |
cd(p); | |
load(mat); | |
%% | |
% screen | |
sM = o.r.screen; % the screen manager we used | |
sM.checkPaths; % make sure we reset the paths to the current machine | |
%% | |
% stimuli | |
stim = o.r.stimuli; % the stimuli | |
reset(stim); | |
%% | |
% task parameters | |
task = o.r.task; | |
values = task.nVar(1).values; % the values of the first variable | |
variable = task.nVar(1).name; | |
%% | |
% open our screen | |
sv = open(sM); | |
% configuire the movie recording mode | |
sM.movieSettings.record = true; | |
sM.movieSettings.size = sv.winRect; % the movie frames is the same size as the original | |
sM.movieSettings.type = 'image'; | |
sM.movieSettings.quality = 0; % 0 = 8bit | |
%% | |
% set up the stimuli with the open screen | |
setup(stim, sM); | |
%% | |
%now we need to calculate how many frames of blank and how many of stimulus | |
blankframes = round(sv.fps * 0.25); % 0.25secs blank | |
stimframes = round(sv.fps * 1.5); % 1.5 seconds stimulus | |
%% | |
for ii = 1:length(values) | |
% reset the frame number and the prefix for the filename | |
sM.movieSettings.loop = 1; | |
sM.movieSettings.prefix = ['IM_' num2str(values(ii))]; | |
prepareMovie(sM); | |
stim{1}.([variable 'Out']) = values(ii); % set the variable to the current value | |
update(stim); % this updates the stimuli with our new value | |
hide(stim); % hide all stimuli as default | |
show(stim,2); % the second stim is fixation cross alone | |
for jj = 1:blankframes | |
draw(stim); | |
flip(sM); | |
addMovieFrame(sM); | |
animate(stim); | |
end | |
show(stim); % show the rest of the stimuli | |
for jj = 1:stimframes | |
draw(stim); | |
flip(sM); | |
addMovieFrame(sM); | |
animate(stim); | |
end | |
hide(stim); % blank screen | |
for jj = 1:blankframes | |
flip(sM); | |
addMovieFrame(sM); | |
end | |
finaliseMovie(sM); | |
end | |
%% | |
reset(stim); | |
close(sM); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment