forked from PumpkinPop/StdVisualModel
-
Notifications
You must be signed in to change notification settings - Fork 2
/
s1_prepare_inputs.m
77 lines (64 loc) · 2.19 KB
/
s1_prepare_inputs.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
function s1_prepare_inputs(ds)
%% Parse the hyperparameters
% the data set
if ~exist('ds', 'var') || isempty(ds), ds = 1; end
% the spatial frequency
if ~exist('filter_cpd', 'var'), filter_cpd = logspace(log10(.75), log10(6), 8); end
%% download the fmri data % update the origin image
% url= 'https://osf.io/xv8m2/download';
% pth = fullfile(stdnormRootPath, 'Data', 'Data.zip');
% fname = websave(pth, url);
% unzip( fname, fullfile(stdnormRootPath, 'Data'));
%% Prepare input for the Φ fn.
% save address
save_address = fullfile(stdnormRootPath, 'Data', 'E');
if ~exist(save_address, 'dir'), mkdir(save_address); end
% Tell the current process
fprintf('Computing E_ori, E_xy, Z1, Z2 for dataset %d\n', ds);
fname = sprintf('stimuli-dataset%02d_orig.mat', ds);
path = fullfile(stdnormRootPath, 'Data', 'Stimuli', fname);
load(path, 'stimuli');
% preprocess
stimuli = double(stimuli);
stimuli = stimuli./255 - .5;
[Gabor_c, Gabor_s] = get_Filters(stimuli, ds, filter_cpd);
%{
figure(1), m = size(Gabor_s, 1); n = size(Gabor_s, 2);
tiledlayout(m,n, 'TileSpacing','tight')
for ii = 1:m
for jj = 1:n
nexttile()
im = zeros(256);
f = Gabor_c{ii,jj};
im(1:size(f,1), 1:size(f,2)) = f;
A{ii,jj} = fftshift(abs(fft2(im)));
imagesc(im); axis square off; colormap gray
end
end
figure(2)
tiledlayout(m,n, 'TileSpacing','tight')
B = zeros(size(A{1,1}));
for ii = 1:m
for jj = 1:n
nexttile()
imagesc(A{ii,jj}); axis square off; colormap gray
B = B + A{ii,jj};
end
end
figure, imagesc(B); axis square
%}
[E_ori, E_xy] = cal_E(stimuli, ds, Gabor_c, Gabor_s);
% save E_ori
fname = sprintf('E_ori_%02d.mat', ds);
save(fullfile(save_address, fname), 'E_ori')
% save E_xy
fname = sprintf('E_xy_%02d.mat', ds);
save(fullfile(save_address, fname), 'E_xy','-v7.3')
% cal Z1 and save: Z1 orientation tuned
Z1 = cal_Z(E_xy);
fname = sprintf('Z1_%02d.mat', ds);
save(fullfile(save_address, fname), 'Z1','-v7.3')
% cal Z2 and save: Z2 not tuned
Z2 = cal_Z(E_xy, 'unTuned');
fname = sprintf('Z2_%02d.mat', ds);
save(fullfile(save_address, fname), 'Z2','-v7.3')