-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtempsnippetsSOC.m
422 lines (373 loc) · 12.8 KB
/
tempsnippetsSOC.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
% For visual experiments, we use band-pass, gray-scale images, spanning
% many stimulus dimensions. Twelve were used in a prior publication [69,70],
% varying in contrast, number of component orientations (1, 2 or 16
% superimposed gratings), or spacing between contrast elements (from very
% sparse to very dense). Twelve are natural images of faces, objects, and
% scenes (also gray-scale, band-pass). These stimuli will be presented for
% 0.5 seconds each. Twelve other stimuli are simple noise patterns shown
% with different temporal profiles (single pulses with variable duration;
% or multiple pulses with variable interstimulus interval).
% CRF - 5 (zebra) KNK 162 164 166 168 116
% Orient - 3 (grating, plaid, circular) KNK 150, 154, 158 (*HC)
% Sparsity - 4 (zebras) KNK 181 182 183 184
% 1 Pulse - 6 (zebra??) KNK 183 * 6
% 2 Pulses - 6 (zebra??) KNK 183 * 6
% Faces - 4 KNK 171 (sample 6 * 8 for 12 runs, 4 each)
% Letters - 4 KNK 173 (sample 6 * 8 for 12 runs, 4 each)
% Scenes - 4 KNK 175 (sample 6 * 8 for 12 runs, 4 each)
% % Download spatiotemporal stimuli
% images = [];
% for ii = 1:13 % why 13?
% readPth = sprintf('https://wikis.nyu.edu/download/attachments/85394548/spatiotemporal%d.mat?api=v2', ii);
% stimDir = fullfile(BAIRRootPath, 'stimuli');
% fname = sprintf('spatiotemporal%d.mat', ii);
% writePth = fullfile(stimDir, fname);
% if ~exist(writePth, 'file'), websave(writePth,readPth); end
% tmp = load(writePth);
% images = [images tmp.im];
% end
knk_idx = [...
162 ... CRF-1
164 ... CRF-2
166 ... CRF-3
167 ... CRF-4
116 ... CRF-5
150 ... GRATING
154 ... PLAID
158 ... CIRCULAR
184 ... SPARSITY-1
183 ... SPARSITY-2
182 ... SPARSITY-3
181 ... SPARSITY-4
171 ... FACES-1
171 ... FACES-2
171 ... FACES-3
171 ... FACES-4
173 ... LETTERS-1
173 ... LETTERS-2
173 ... LETTERS-3
173 ... LETTERS-4
172 ... SCENES-1 (175??)
172 ... SCENES-2 (175??)
172 ... SCENES-3 (175??)
172 ... SCENES-4 (175??)
116 ... ONEPULSE-1
116 ... ONEPULSE-2
116 ... ONEPULSE-3
116 ... ONEPULSE-4
116 ... ONEPULSE-5
116 ... ONEPULSE-6
116 ... TWOPULSE-1
116 ... TWOPULSE-2
116 ... TWOPULSE-3
116 ... TWOPULSE-4
116 ... TWOPULSE-5
116 ... TWOPULSE-6
];
whichIm = {...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:2 ...
3:4 ...
5:6 ...
7:8 ...
1:2 ...
3:4 ...
5:6 ...
7:8 ...
1:2 ...
3:4 ...
5:6 ...
7:8 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
};
im_cell = images(knk_idx);
images = [];
for ii = 1:num_cats
these_images = im_cell{ii}(:,:,whichIm{ii});
images = cat(3, images, these_images);
end
%% durations
durations = [ ...
ones(1,24)*0.5 ... spatial
[1 2 4 8 16 32]/60 ... one pulse
ones(1,6)*8/60 ... two pulse
];
ISI = [ ...
zeros(1,24) ... spatial
zeros(1,6) ... one pulse
[1 2 4 8 16 32]/60 ... two pulse
];
%% indices into original unfitlered stim:
% LETTERS
% imageIndex = [13 21;
% 6 20;
% 1 9;
% 8 24];
% HOUSES
% imageIndex = [33 7;
% 24 20;
% 41 3;
% 31 25];
% FACES
% imageIndex = [30 35;
% 24 83;
% 74 13;
% 59 41];
%% DEBUG
%% Plot individual stimuli for a specific category ('images')
whichCat = 'FLH'; %pick: CRF, GPC, SPARSITY, FLH, or PULSE;
images = eval([whichCat 'images']);
figure;hold on
for ii = 1:size(images,3)
subplot(ceil(sqrt(size(images,3))),ceil(sqrt(size(images,3))),ii);
imshow(images(:,:,ii));
end
%% Plot exemplars for all categories ('im_cell')
figure('Name', 'NEW STIM');hold on
for ii = 1:24%length(stimulus.im_cell)
subplot(4,6,ii);
imshow(stimulus.im_cell{ii}(:,:,1));
title(stimulus.categories{ii});
end
% Compute power spectra for all categories ('im_cell')
D = loadDisplayParams('HiResDefault');
figure('Name', 'NEW STIM SF');hold on
peaks = [];
for ii = 1:24%length(stimulus.im_cell)
im = stimulus.im_cell{ii};
[frequencies, amplitudes, binnedFrequencies, binnedAmplitudes] = ...
compute2DamplitudeSpectrum(im, D);
[y,x] = max(binnedAmplitudes);
peaks(ii) = binnedFrequencies(x);
% Plot spectrum per category
subplot(4,6,ii);
plot(binnedFrequencies, binnedAmplitudes/max(binnedAmplitudes), 'LineWidth', 2);
xlabel('Cycles per degree')
xlim([0 7.5])
set(gca, 'XGrid', 'on', 'XTick', 0:1.5:7.5)
title(stimulus.categories{ii});
end
% Plot distribution of peaks
figure('Name', 'NEW STIM SF PEAKS');
subplot(1,2,1);histogram(peaks); xlabel('max spatial frequency'); ylabel('number of images')
xlim([0 4]);
subplot(1,2,2);plot(peaks, 'o-'); ylabel('category index'); ylabel('max spatial frequency');
xlim([0 25]);
% Compute luminance histograms
figure ('Name', 'NEW STIM LUM');hold on
for ii = 1:24%length(stimulus.im_cell)
im = stimulus.im_cell{ii};
% Plot histogram per category
subplot(4,6,ii);
histogram(im(im~=mode(im(:)))); title('(mode excluded from hist)');
xlabel('Pixel values')
xlim([0 255])
title(stimulus.categories{ii});
end
%% DO THE SAME FOR THE ORIGINAL KAY STIMULI
% Pattern stimuli from Kay et al 2013
load('/Volumes/server/Projects/BAIR/Stimuli/Kay2013_stimuli/stimuli.mat');
% From http://kendrickkay.net/socmodel/index.html#contentsofstimuli
% Contents of 'stimuli.mat':
%
% 'images' contains the raw stimulus frames for stimulus sets 1, 2, and 3
% (concatenated). The 'images' variable is a cell vector of dimensions 1 x
% 260 (since 69+156+35=260). Each entry corresponds to one stimulus, and
% each stimulus consists of one or more frames. For stimulus set 1 (1
% through 69), all entries consist of 30 distinct frames. For stimulus set
% 2 (70 through 225), all entries consist of 9 distinct frames except for
% entry #174 which consists of 7 distinct frames. For stimulus set 3 (226
% through 260), all entries consist of a single frame. The resolution of
% the images in stimulus set 1 is 600 pixels x 600 pixels; the resolution
% of the images in stimulus sets 2?3 is 800 pixels x 800 pixels. For all
% images, the format is uint8; the range of values is [0,254]; and the
% background has a value of 127.
%
% 'conimages' contains the spatial masks (contrast images) used in the
% generation of some of the stimuli. There is a direct correspondence
% between 'conimages' and 'images'. The 'conimages' variable is a cell
% vector of dimensions 1 x 260. Each entry gives the mask that was used to
% generate the corresponding stimulus in 'images'. The indices of the
% stimuli that have associated masks are 1:69, 70:138, and 185:208. For the
% other indices, the entry in 'conimages' is simply the empty matrix. The
% resolution of the contrast images in stimulus set 1 is 600 pixels x 600
% pixels; the resolution of the contrast images in stimulus sets 2?3 is 256
% pixels x 256 pixels. For all contrast images, the format is double; and
% the range of values is [0,1] where a value of X indicates that at that
% pixel, the underlying stimulus, weighted by X, was blended with the gray
% background, weighted by 1?X.
%
% 'bpfilter' contains the band-pass filter used to generate some of the
% stimuli in stimulus sets 2?3. The filter is a matrix of dimensions 21 x
% 21 and was used in stimulus construction, at which point the image
% resolution was 256 pixels x 256 pixels.
knk_idx = [...
162 ... CRF-1
164 ... CRF-2
166 ... CRF-3
167 ... CRF-4
116 ... CRF-5
150 ... GRATING
154 ... PLAID
158 ... CIRCULAR
184 ... SPARSITY-1
183 ... SPARSITY-2
182 ... SPARSITY-3
181 ... SPARSITY-4
171 ... FACES-1
171 ... FACES-2
171 ... FACES-3
171 ... FACES-4
173 ... LETTERS-1
173 ... LETTERS-2
173 ... LETTERS-3
173 ... LETTERS-4
172 ... SCENES-1 (175??)
172 ... SCENES-2 (175??)
172 ... SCENES-3 (175??)
172 ... SCENES-4 (175??)
116 ... ONEPULSE-1
116 ... ONEPULSE-2
116 ... ONEPULSE-3
116 ... ONEPULSE-4
116 ... ONEPULSE-5
116 ... ONEPULSE-6
116 ... TWOPULSE-1
116 ... TWOPULSE-2
116 ... TWOPULSE-3
116 ... TWOPULSE-4
116 ... TWOPULSE-5
116 ... TWOPULSE-6
];
whichIm = {...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:2 ...
3:4 ...
5:6 ...
7:8 ...
1:2 ...
3:4 ...
5:6 ...
7:8 ...
1:2 ...
3:4 ...
5:6 ...
7:8 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
1:6 ...
};
knk_im_cell = [];
for ii = 1:24%length(knk_idx)
knk_im_cell{ii} = images{knk_idx(ii)}(:,:,whichIm{ii}(1));
end
figure('Name', 'OLD STIM');hold on
for ii = 1:24%length(knk_im_cell)
subplot(4,6,ii);
imshow(knk_im_cell{ii}(:,:,1));
title(stimulus.categories{ii});
end
% D = loadDisplayParams('cni_lcd');
D = loadDisplayParams('cni_lcd_mock');
figure('Name', 'OLD STIM SF');hold on
peaks = [];
for ii = 1:24%length(knk_im_cell)
im = knk_im_cell{ii}(:,:,1);
[frequencies, amplitudes, binnedFrequencies, binnedAmplitudes] = ...
compute2DamplitudeSpectrum(im, D);
[y,x] = max(binnedAmplitudes);
peaks(ii) = binnedFrequencies(x);
% Plot spectrum per category
subplot(4,6,ii);
plot(binnedFrequencies, binnedAmplitudes/max(binnedAmplitudes), 'LineWidth', 2);
xlabel('Cycles per degree')
xlim([0 7.5])
set(gca, 'XGrid', 'on', 'XTick', 0:1.5:7.5)
title(stimulus.categories{ii});
end
% Plot distribution of peaks
figure('Name', 'OLD STIM SF PEAKS');
subplot(1,2,1);histogram(peaks); xlabel('max spatial frequency'); ylabel('number of images')
xlim([0 4]);
subplot(1,2,2);plot(peaks, 'o-'); ylabel('category index'); ylabel('max spatial frequency');
xlim([0 25]);
% Compute luminance histograms
figure('Name', 'OLD STIM LUM');hold on
for ii = 1:24%length(knk_im_cell)
im = knk_im_cell{ii};
% Plot histogram per category
subplot(4,6,ii);
histogram(im(im~=mode(im(:)))); title('(mode excluded from hist)');
xlabel('Pixel values')
xlim([0 255])
title(stimulus.categories{ii});
end
%% make stimulus movie
% movie ----
% movieName = sprintf('~/Desktop/spatiotemporal%02d.avi', runnum);
% nFramePerSec = 60;
%
% v = VideoWriter(movieName);
% v.FrameRate = nFramePerSec;
% v.Quality = 100;
% open(v)
% c = 1;
% %fH = figure(); set(fH, 'Visible', 'off')
%
% cmap = gray(256);
%
% fprintf('Making scan number %d\n', runnum);
% for ii = 1 : length(stimulus.seq)
%
%
% im = uint8(stimulus.images(:,:,stimulus.seq(ii)));
% frame = im2frame(im, cmap);
%
% writeVideo(v, frame);
%
% if mod(ii,100) == 0, fprintf('.'); drawnow(); end
%
% end
% close(v)