-
Notifications
You must be signed in to change notification settings - Fork 0
/
illustration.m
389 lines (326 loc) · 10.9 KB
/
illustration.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
%% script with commands for illustration figures showing processing
% use the currently saved parameters
pars = getPars();
%% get original images
% A grating
grating = image_hanningGrating([512,512],[2,2],2,.1,[1,1],1,85,[1,1],1);
% A natural image
natImage = imread('DSC_0339.JPG');
natImageSmall=imresize(natImage,[96,96]);
%% show original image
image(natImage)
axis square
set(gca,'Visible','off')
%% convert to luminance and show again
[natImage] = convert_lum_spectra(natImage);
natImageSmall=imresize(natImage,[96,96]);
natImageBackground = imresize(natImage,[256,256]);
natImageBackground = natImageBackground-min(natImageBackground(:));
natImageBackground = natImageBackground./max(natImageBackground(:));
natImageBackground = imadjust(natImageBackground,[min(natImageBackground(:)),max(natImageBackground(:))],[0,1],1/2.2);
% linear scale in luminance looks strange...
%imagesc(natImage)
% instead with gamma = 2.2
figure
J = natImage./max(natImage(:));
J = imadjust(J,[min(J(:)),max(J(:))],[0,1],1/2.2);
imagesc(J)
axis square
set(gca,'Visible','off')
colormap(gray(256))
figure
JG = grating./mean(grating(:))./2;
JG = imadjust(JG,[0,1],[0,1],1/2.2);
imagesc(JG,[0,1])
axis square
set(gca,'Visible','off')
colormap(gray(256))
%% Optics
natImage = watson_filter_eye(natImage,[2,2],4);
grating = watson_filter_eye(grating,[2,2],4);
figure
J = natImage./max(natImage(:));
J = imadjust(J,[min(J(:)),max(J(:))],[0,1],1/2.2);
imagesc(J)
axis square
set(gca,'Visible','off')
colormap(gray(256))
figure
JG = grating./mean(grating(:))./2;
JG = imadjust(JG,[0,1],[0,1],1/2.2);
imagesc(JG,[0,1])
axis square
set(gca,'Visible','off')
colormap(gray(256))
%% "fovea cut out
natImageCut = natImage./mean(natImage(:))-1;
gratingCut = grating./mean(grating(:))-1;
natImageCut = cutFovea(natImageCut,[2,2],[1.5,1.5],256);
gratingCut = cutFovea(gratingCut,[2,2],[1.5,1.5],256);
figure
J = (natImageCut-min(natImageCut(:)))./(max(natImageCut(:))-min(natImageCut(:)));
J = imadjust(J,[min(J(:)),max(J(:))],[0,1],1/2.2);
imagesc(J)
axis square
set(gca,'Visible','off')
colormap(gray(256))
figure
JG = (gratingCut-min(gratingCut(:)))./(max(gratingCut(:))-min(gratingCut(:)));
JG = imadjust(JG,[0,1],[0,1],1/2.2);
imagesc(JG,[0,1])
axis square
set(gca,'Visible','off')
colormap(gray(256))
%% full foveation
nframes = 228;
timecourse = 0.5 -0.5*cos((0:(nframes-1))/(nframes-1)*2*pi);
timecourse = imresize(timecourse,[1,1497],'nearest')';
[natImageLong,degSize] = foveate_image1(natImage,[2,2],timecourse,[1,1],[],256);
[natImageMiddle,degSize] = foveate_image1(natImage,[2,2],ones(250,1),[1,1],[],256);
[natImageShort,degSize] = foveate_image1(natImage,[2,2],ones(20,1),[1,1],[],256);
figure
for iPlot = 1:3
subplot(1,3,iPlot)
switch iPlot
case 1
imagesc(natImageLong,[-1.75,3])
case 2
imagesc(natImageMiddle,[-1.75,3])
case 3
imagesc(natImageShort,[-1.75,3])
end
axis square
set(gca,'Visible','off')
colormap(gray(256))
end
figure
imagesc(natImageMiddle)
axis square
set(gca,'Visible','off')
colormap(gray(1000))
%% V1 stuff
% parameters
noiseConst = pars(1);
noiseFactor = pars(2);
CNaka = pars(3); % Naka rushton constant
ExNaka = pars(4); % Naka rushton Exponent top
ExNakaNorm = pars(5); % Naka rushton Exponent below
bw(1) = pars(6); % bandwidth in frequency (std of log-Gabor in octaves)
bw(2) = pars(7); % bandwidth in orientation (std log-Gabor in radiants)
nFreq = pars(8); % number of frequency bands
nOrient = pars(9); % number of orientations
poolSize = pars(10); % meaning depends on type, spatial size of normalization pool
poolbw = pars(11); % bandwidth of the normalization pool (Octaves in frequency)
minF = pars(12); % lowest frequency band
maxF = pars(13); % highest frequency band
%% Decomposition
[outNatImage,~,~,~,filters] = decomp_Gabor(natImageMiddle,degSize,[minF,maxF],nFreq,nOrient,bw);
figure
imagesc(flip(squeeze(mean(mean(abs(outNatImage),1),2)),2))
set(gca,'FontSize',14);
%xlabel('Frequency [cyc/deg]','FontSize',14)
%ylabel('Orientation [deg]','FontSize',14)
set(gca,'XTick',1:nFreq);
freq = 2.^linspace(log2(minF),log2(maxF),nFreq);
set(gca,'XTicklabel',sprintf('%.1f\n',freq))
orient = linspace(0,(nOrient-1)./nOrient*180,nOrient);
set(gca,'YTicklabel',sprintf('%.1f\n',orient))
%title('Raw Frequency Decomposition');
colormap(gray(256));
set(gca,'XTickLabelRotation',90)
figure
overlay = abs(outNatImage(:,:,5,7));
overlay = overlay./max(overlay(:));
im = cat(3,natImageBackground.*overlay,natImageBackground.*overlay,natImageBackground.*(1-overlay));
image(im)
axis square
set(gca,'Visible','off')
allNumbers = real(outNatImage(:,:,:,5));
for iChannel = 1:8
natImageSmall=imresize(real(outNatImage(:,:,iChannel,5)),[96,96]);
natImageSmall=natImageSmall-min(allNumbers(:));
% imwrite(imadjust(natImageSmall./(max(allNumbers(:))-min(allNumbers(:))),[0,1],[0,1],1),sprintf('../../../figures/earlyVision/GifMaking/%03d.jpg',iChannel+15))
end
allNumbers = real(outNatImage(:,:,8,:));
for iChannel = 1:12
natImageSmall=imresize(real(outNatImage(:,:,8,iChannel)),[96,96]);
natImageSmall=natImageSmall-min(allNumbers(:));
% imwrite(imadjust(natImageSmall./(max(allNumbers(:))-min(allNumbers(:))),[0,1],[0,1],1),sprintf('../../../figures/earlyVision/GifMaking/%03d.jpg',iChannel+15+8))
end
%% Normalization -> full V1
outNatImageNormalized = V1(natImageMiddle,degSize,1,pars(3:14));
figure
imagesc(flip(squeeze(mean(mean(outNatImageNormalized,1),2)),2))
set(gca,'FontSize',14);
%xlabel('Frequency [cyc/deg]','FontSize',14)
%ylabel('Orientation [deg]','FontSize',14)
set(gca,'XTick',1:nFreq);
freq = 2.^linspace(log2(minF),log2(maxF),nFreq);
set(gca,'XTicklabel',sprintf('%.1f\n',freq))
orient = linspace(0,(nOrient-1)./nOrient*180,nOrient);
set(gca,'YTicklabel',sprintf('%.1f\n',orient))
set(gca,'XTickLabelRotation',90)
%title('Activity after Normalization');
colormap(gray(256));
figure
imagesc(natImageBackground)
colormap(gray(256));
hold on
h =image(0.5*cat(3,ones(256),ones(256),ones(256)));
overlay = outNatImageNormalized(:,:,5,7);
set(h,'AlphaData',1-overlay./max(overlay(:)));
axis square
set(gca,'Visible','off')
figure
imagesc(natImageBackground)
colormap(gray(256));
hold on
h =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = outNatImageNormalized(:,:,5,7);
set(h,'AlphaData',overlay./max(overlay(:)));
axis square
set(gca,'Visible','off')
figure
overlay = outNatImageNormalized(:,:,5,7);
overlay = overlay./max(overlay(:));
im = cat(3,natImageBackground.*overlay,natImageBackground.*overlay,natImageBackground.*(1-overlay));
image(im)
axis square
set(gca,'Visible','off')
%% show individual images
res =get(0,'ScreenPixelsPerInch');
h = figure;
pause(.5);
imagesc(real(outNatImage(:,:,5,12)))
colormap(gray(256));
hold on
set(gca,'Visible','off')
set(gca,'Units','pixels')
set(h,'Units','pixels')
set(h,'PaperUnits','inches')
set(h,'PaperPositionMode', 'manual');
set(gca,'Position',[1,1,257,257])
set(h,'PaperSize',[256,256]./res);
set(h,'PaperPosition',[0,0,256,256]./res)
pos = get(h,'Position');
set(h,'Position',[pos(1),pos(2),256,256])
drawnow
%print('../../../figures/EVIllustration/Channel1.jpg','-djpeg','-r96')
imagesc(real(outNatImage(:,:,4,8)))
colormap(gray(256));
drawnow
%print('../../../figures/EVIllustration/Channel2.jpg','-djpeg','-r96')
imagesc(real(outNatImage(:,:,1,5)))
colormap(gray(256));
drawnow
%print('../../../figures/EVIllustration/Channel3.jpg','-djpeg','-r96')
imagesc(real(outNatImageNormalized(:,:,5,12)))
colormap(gray(256));
drawnow
%print('../../../figures/EVIllustration/Channel1N.jpg','-djpeg','-r96')
imagesc(real(outNatImageNormalized(:,:,4,8)))
colormap(gray(256));
drawnow
%print('../../../figures/EVIllustration/Channel2N.jpg','-djpeg','-r96')
imagesc(real(outNatImageNormalized(:,:,1,5)))
colormap(gray(256));
drawnow
%print('../../../figures/EVIllustration/Channel3N.jpg','-djpeg','-r96')
hold off
imagesc(natImageBackground)
colormap(gray(256));
hold on
him =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = abs(outNatImage(:,:,5,12));
set(him,'AlphaData',overlay./max(overlay(:)));
set(gca,'Visible','off')
drawnow
%print('../../../figures/EVIllustration/Overlay1.jpg','-djpeg','-r96')
imagesc(natImageBackground)
colormap(gray(256));
hold on
him =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = abs(outNatImage(:,:,4,8));
set(him,'AlphaData',overlay./max(overlay(:)));
set(gca,'Visible','off')
drawnow
%print('../../../figures/EVIllustration/Overlay2.jpg','-djpeg','-r96')
imagesc(natImageBackground)
colormap(gray(256));
hold on
him =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = abs(outNatImage(:,:,1,5));
set(him,'AlphaData',overlay./max(overlay(:)));
set(gca,'Visible','off')
drawnow
%print('../../../figures/EVIllustration/Overlay3.jpg','-djpeg','-r96')
imagesc(natImageBackground)
colormap(gray(256));
hold on
him =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = outNatImageNormalized(:,:,5,12);
set(him,'AlphaData',overlay./max(overlay(:)));
set(gca,'Visible','off')
drawnow
%print('../../../figures/EVIllustration/Overlay1N.jpg','-djpeg','-r96')
imagesc(natImageBackground)
colormap(gray(256));
hold on
him =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = outNatImageNormalized(:,:,4,8);
set(him,'AlphaData',overlay./max(overlay(:)));
set(gca,'Visible','off')
drawnow
%print('../../../figures/EVIllustration/Overlay2N.jpg','-djpeg','-r96')
imagesc(natImageBackground)
colormap(gray(256));
hold on
him =image(cat(3,ones(256),ones(256),zeros(256)));
overlay = outNatImageNormalized(:,:,1,5);
set(him,'AlphaData',overlay./max(overlay(:)));
set(gca,'Visible','off')
drawnow
%print('../../../figures/EVIllustration/Overlay3N.jpg','-djpeg','-r96')
%% Phase
h = figure;
pause(.5);
imagesc(real(outNatImage(:,:,4,5)))
colormap(gray(256));
hold on
set(gca,'Visible','off')
set(gca,'Units','pixels')
set(h,'Units','pixels')
set(h,'PaperUnits','inches')
set(h,'PaperPositionMode', 'manual');
set(gca,'Position',[1,1,257,257])
set(h,'PaperSize',[256,256]./res);
set(h,'PaperPosition',[0,0,256,256]./res)
pos = get(h,'Position');
set(h,'Position',[pos(1),pos(2),256,256])
drawnow
colormap(gray(256));
imagesc(real(outNatImage(:,:,4,5)))
drawnow
%print('../../../figures/EVIllustration/Real.jpg','-djpeg','-r96')
imagesc(imag(outNatImage(:,:,4,5)))
drawnow
%print('../../../figures/EVIllustration/Imag.jpg','-djpeg','-r96')
imagesc(abs(outNatImage(:,:,4,5)),[0,0.589])
drawnow
%print('../../../figures/EVIllustration/Absolute.jpg','-djpeg','-r96')
imagesc(natImageMiddle,[min(natImageMiddle(:)),max(natImageMiddle(:))])
drawnow
%print('../../../figures/EVIllustration/FinalNeuschwanstein.jpg','-djpeg','-r96')
hold off
Filt = fftshift(ifft2(filters{5}(:,:,4)));
imagesc(imag(Filt(65:192,65:192)),[-max(abs(Filt(:))),max(abs(Filt(:)))])
colormap(gray(256));
hold on
set(gca,'Visible','off')
set(gca,'Units','pixels')
set(gca,'Position',[1,1,257,257])
drawnow
%print('../../../figures/EVIllustration/FilterImag.jpg','-djpeg','-r96')
imagesc(real(Filt(65:192,65:192)),[-max(abs(Filt(:))),max(abs(Filt(:)))])
drawnow
%print('../../../figures/EVIllustration/FilterReal.jpg','-djpeg','-r96')