-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpOccObj.m
253 lines (205 loc) · 9.6 KB
/
expOccObj.m
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
stimpath='C:\Users\Zahra\Documents\ZDoc\IPM project\experiment stimulus';
AssertOpenGL;
NOISE=imresize(imread(strcat(stimpath,'\',char('Noise.jpg'))),[256 256]);
KbName('UnifyKeyNames');
try
screens=Screen('Screens');
screenNumber=max(screens);
HideCursor;
gray=GrayIndex(screenNumber);
[w, wRect]=Screen('OpenWindow',screenNumber, gray);
% Set priority for script execution to realtime priority:
priorityLevel=MaxPriority(w);
Priority(priorityLevel);
str1=sprintf('You will see a scenary image followed by an image of an image of an occluded object\n');
str2=sprintf('You will be asked to type the name of the object you see\n');
message = ['test phase ...\n' str1 str2 '... press mouse button to begin ...'];
DrawFormattedText(w, message, 'center', 'center', WhiteIndex(w));
% Update the display to show the instruction text:
Screen('Flip', w);
% Wait for mouse click:
GetClicks(w);
Screen('Flip', w);
WaitSecs(1.000);
ntrials=1;
randomorder1=randperm(ntrials); % randperm() is a matlab function 3 yani tedate frame ha
TT=randperm(ntrials);
for trial=1:ntrials
% if (trial==floor(ntrials/3) || trial == floor(ntrials*2/3))
% str2=sprintf('Take a rest \n');
% str3=sprintf('5 Minutes \n');
% message = [str2 str3 '... press mouse button to continue ...'];
% DrawFormattedText(w, message, 'center', 'center', WhiteIndex(w));
% % Update the display to show the instruction text:
% Screen('Flip', w);
%
% % Wait for mouse click:
% GetClicks(w);
% WaitSecs(2);
%
% end
objNum=1;rndlist=randperm(6);
imglist=dir(stimpath);
% read images of a scene
sceneDir=strcat([stimpath '\' ],'scene');
scenefiles=dir(sceneDir);s=1;
for l=1:length(scenefiles)
if ~strcmp(scenefiles(l).name,'.') && ~strcmp(scenefiles(l).name,'..')
sceneimgs(s)=scenefiles(l);s=s+1;
end
end
% read images of objects
objDir=strcat([stimpath '\' ],'object');
objfiles=dir(objDir);s=1;
for l=1:length(objfiles)
if ~strcmp(objfiles(l).name,'.') && ~strcmp(objfiles(l).name,'..')
objimgs(s)=objfiles(l);s=s+1;
end
end
for o=1:objNum
% 1-select a scene randomly
stimfilename=strcat([stimpath '\' ],'scene','\',sceneimgs(rndlist(o)).name); % assume stims are in subfolder "stims"
imdata=(imresize((imread(char(stimfilename))),[256 256]));
% 2-show fixation point
centx = wRect(3)/2;
centy = wRect(4)/2;
fixationArea = [centx-5, centy-5, centx+5, centy+5];
Screen('FillOval', w, [0 255 0], fixationArea);
Screen('Flip',w);
% Fixation presentation
WaitSecs(1);
% % [KeyIsDown, endrt, KeyCode]=KbCheck;
% 3-display the scene image
Screen('PutImage', w, imdata);
% tex=Screen('MakeTexture', w, imdata);
% Screen('DrawTexture', w, tex);
[~, startstim]=Screen('Flip', w);
while (GetSecs - startstim)<=0.1
end
% make the screen gray
Screen(w, 'FillRect', gray);
[~,startgray1]=Screen(w, 'Flip');
Trial.Stimulus_duration(trial)=startgray1-startstim;
while (GetSecs - startgray1)<=0.02
end
% -dispaly noisy image
tex=Screen('MakeTexture', w, NOISE);
Screen('DrawTexture', w, tex);
[~, startNoise]=Screen('Flip', w);
% make the screen gray
Trial.gary_duration1(trial)=startNoise-startgray1;
while (GetSecs - startNoise)<=0.1
end
Screen(w, 'FillRect', gray);
[~,startgray2]=Screen(w, 'Flip');
Trial.Noise_duration(trial)=startgray2-startNoise;
% key3=zeros(size(KeyCode));
% key2=zeros(size(KeyCode));
% endrt2=0;
% [KeyIsDown, endrt, KeyCode]=KbCheck;
% while ( KeyCode(GO)==0 && KeyCode(NOGO)==0)
% [KeyIsDown, endrt, KeyCode]=KbCheck;
% key1=KeyCode;
% WaitSecs(0.001);
% end
WaitSecs(1);
% if (strcmp(Type,'test'))
% if KeyCode(GO)==1
% Trial.SubjectRes=[Trial.SubjectRes 0];
% else
% Trial.SubjectRes=[Trial.SubjectRes 1];
% end
% end
% compute response time
% rt=round(1000*(endrt-startgray2));
% if (strcmp(Type,'test'))
% Trial.ImageNumber=[Trial.ImageNumber CollNum];
% Trial.SubRespTime=[Trial.SubRespTime rt];
% end
% -select an object randomly
stimfilename=strcat([stimpath '\' ],'object','\',objimgs(rndlist(o)).name); % assume stims are in subfolder "stims"
imdata=(imresize((imread(char(stimfilename))),[256 256]));
% -show fixation point
centx = wRect(3)/2;
centy = wRect(4)/2;
fixationArea = [centx-5, centy-5, centx+5, centy+5];
Screen('FillOval', w, [0 255 0], fixationArea);
Screen('Flip',w);
WaitSecs(1);
% % [KeyIsDown, endrt, KeyCode]=KbCheck;
% -show object
Screen('PutImage', w, imdata);
% tex=Screen('MakeTexture', w, imdata);
% Screen('DrawTexture', w, tex);
[~, startstim]=Screen('Flip', w);
%- wait for .... seconds ????
while (GetSecs - startstim)<=0.1
end
%- gray the screen?????
Screen(w, 'FillRect', gray);
[~,startgray1]=Screen(w, 'Flip');
Trial.Stimulus_duration(trial)=startgray1-startstim;
while (GetSecs - startgray1)<=0.02
end
%- show noise
tex=Screen('MakeTexture', w, NOISE);
Screen('DrawTexture', w, tex);
[~, startNoise]=Screen('Flip', w);
Trial.gary_duration1(trial)=startNoise-startgray1;
%-wait for --- secnods ???
while (GetSecs - startNoise)<=0.1
end
%- make the screen gray
Screen(w, 'FillRect', gray);
[~,startgray2]=Screen(w, 'Flip');
% Trial.Noise_duration(trial)=startgray2-startNoise;
% key3=zeros(size(KeyCode));
% key2=zeros(size(KeyCode));
% endrt2=0;
% [KeyIsDown, endrt, KeyCode]=KbCheck;
% while ( KeyCode(GO)==0 && KeyCode(NOGO)==0)
% [KeyIsDown, endrt, KeyCode]=KbCheck;
% key1=KeyCode;
% WaitSecs(0.001);
% end
WaitSecs(1);
% str2=sprintf('Type the name of the object \n');
% message = [str2 '...'];
% DrawFormattedText(w, message, 'center', 'center', WhiteIndex(w));
% % Update the display to show the instruction text:
% Screen('Flip', w);
% nameTyped=GetString('useKbCheck'==1);
% DrawFormattedText(sprintf('\n your response is:%s',nameTyped));
% DrawFormattedText(sprintf('\n press mouse button to continue %s',nameTyped));
typedName=Ask(w,'Type the name of the object you saw, then press enter ',[],[],'GetChar','center','center',[])
% typedName = GetString('useKbCheck'==1)
% make the screen gray
Screen(w, 'FillRect', gray);
[~,startgray1]=Screen(w, 'Flip');
% Trial.Stimulus_duration(trial)=startgray1-startgray1;
% str1='\n press mouse button to continue ';
% message=[str1 '...'];
% DrawFormattedText(w, message, 'center', 'center', WhiteIndex(w));
%
% while (GetSecs - startgray1)<=0.02
% end
% % Wait for mouse click:
% GetClicks(w);
WaitSecs(1);
end
end % for trial loop
Screen('CloseAll');
ShowCursor;
fclose('all');
Priority(0);
% End of experiment:
return;
catch
% Do same cleanup as at the end of a regular session...
Screen('CloseAll');
ShowCursor;
fclose('all');
Priority(0);
% Output the error message that describes the error:
psychrethrow(psychlasterror);
end % try ... catch %