-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaturalImages2.m
More file actions
181 lines (135 loc) · 5.88 KB
/
NaturalImages2.m
File metadata and controls
181 lines (135 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
function NaturalImages2
%this script presents natural images with this protocol:
%repeted a number of times defined in repetitions:
%trigger
%for the time in the variable "gray_delay" gray screen
%for the time in the variable "movie_delay" one image
%goes through all the images, then goes back to wait for the trigger
%the order of image presentation can be randomized and the order is saved
%square for photodiode recordings possible
try
% This script calls Psychtoolbox commands available only in OpenGL-based
% versions of the Psychtoolbox. (So far, the OS X Psychtoolbox is the
% only OpenGL-base Psychtoolbox.) The Psychtoolbox command AssertPsychOpenGL will issue
% an error message if someone tries to execute this script on a computer without
% an OpenGL Psychtoolbox
AssertOpenGL;
%photodiode settings
use_pd=1; % 0 disables photodiode square
diodesz=100; %size of photodiode detection square in pixels
%Parameters
filename='C:\Users\Chiara\Documents\MATLAB\visual stimuli\natural images\NatImag.mat'; %where to take the natural images
load(filename)
n_pictures=length(Images);
frames=[1:n_pictures];
repetitions=2; %number of trials
set_trigger=0 ; % 0 disables external trigger, 1 activates external trigger
test = 1 ; % set to 1 if you wan t to test without external triggering
gray_delayStart=2.2; % First delay in the trial of gray screen before image presentation in seconds
gray_delay=2.6; % delay of gray screen before image presentation in seconds
movie_delay=0.4; % movie duration in seconds
rand_fr=1; % select 1 to randomize frames
% window configuration
clear mex;
timestampmode=1;
Screen('Preference', 'VBLTimestampingMode', timestampmode);
tic
[window,screenRect,ifi,whichScreen]=initScreen;
init_delay=toc;
HideCursor;
priorityLevel=MaxPriority(window);
Priority(priorityLevel);
% images loading
for i=1:n_pictures;
imgtex(i)=Screen('MakeTexture', window, Images{i});
end
% parameters:
hz=1/ifi;
%set the trigger
if test == 0
dio = digitalio('nidaq','Dev1');
%dio2 = digitalio('nidaq',1);
addline(dio,0,'in');
%addline(dio2,1,'out');
end
%where to save the order of image presentation
dirname=['C:\Users\Chiara\Documents\MATLAB\visual stimuli\natural images' '\' datestr(now, 'yyyy_mm_dd') '\' datestr(now, 'yyyy_mm_dd_HH_MM_SS') ];
mkdir(dirname);
save([dirname '\imagesPresented.mat'],'Images')
Screen('FillRect', window,127);
Screen('Flip',window);
tic
for rep=1:repetitions;
%randomize image order if required
if rand_fr
rand_frames=randperm(n_pictures);
else
rand_frames=frames;
end
%wait for the trigger
if set_trigger
if getvalue(dio),
while getvalue(dio),end
end
while ~getvalue(dio),
if KbCheck Screen('Close'); clear mex,clear imgstack,clear imgtex Images ans i prioritylevel rand_frames rep w
,return,end;
end
else
while ~KbCheck;end
pause(0.5);
end
for i=1:n_pictures
frame_order(rep,i)=rand_frames(i); %save order of images presented
toclist(i,rep)=toc;
% delay of gray screen
if i==1
Gray_delay=gray_delayStart;
else
Gray_delay=gray_delay;
end
for w=1:Gray_delay*hz;
Screen('FillRect', window,120);
if use_pd % photodiode
Screen('FillRect', window,0,[screenRect(1) screenRect(4)-diodesz diodesz screenRect(4)] );
end
Screen('Flip',window);
if KbCheck Screen('Close'); clear mex,clear imgstack i ii,clear imgtex Images ans i prioritylevel rand_frames rep w
,
save([dirname '\image_sequence.mat'],'frame_order'),return,end;
end
% image presentation
for delay=1:movie_delay*hz;
Screen('DrawTexture', window, imgtex(rand_frames(i)),[],screenRect);
if use_pd %photodiode
Screen('FillRect', window,255,[screenRect(1) screenRect(4)-diodesz diodesz screenRect(4)] );
end
Screen('Flip',window);
if KbCheck Screen('Close'); clear mex,clear imgstack i ii,clear imgtex Images ans i prioritylevel rand_frames rep w
save([dirname '\image_sequence.mat'],'frame_order'),return,end;
end
Screen('FillRect', window,120);
if use_pd
Screen('FillRect', window,0,[screenRect(1) screenRect(4)-diodesz diodesz screenRect(4)] );
end
Screen('Flip',window);
end
end
Screen('FillRect', window,120);
if use_pd
Screen('FillRect', window,0,[screenRect(1) screenRect(4)-diodesz diodesz screenRect(4)] );
end
Screen('Flip',window);
KbWait;
Screen('Close')
clear mex,clear imgstack i ii,clear imgtex Images ans i prioritylevel rand_frames rep w
save([dirname '\image_sequence.mat'],'frame_order')
ShowCursor;
catch
%this "catch" section executes in case of an error in the "try" section
%above. Importantly, it closes the onscreen window if its open.
Screen('CloseAll');
Priority(0);
psychrethrow(psychlasterror);
end %try..catch..
end