-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathC2.m
57 lines (48 loc) · 1.53 KB
/
C2.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
function [c2,s2,c1,s1] = C2(stim,filters,fSiz,c1SpaceSS,c1ScaleSS,c1OL,s2Target,c1)
%
% given an image extracts layers s1 c1 s2 and finally c2
% for inputs stim, filters, fSiz, c1SpaceSS,c1ScaleeSS, and c1OL
% see the documentation for C1 (C1.m)
%
% briefly,
% stim is the input image.
% filters fSiz, c1SpaceSS, c1ScaleSS, c1OL are the parameters of
% the c1 process
%
% s2Target are the prototype (patches) to be used in the extraction
% of s2. Each patch of size [n,n,d] is stored as a column in s2Target,
% which has itself a size of [n*n*d, n_patches];
%
% if available, a precomputed c1 layer can be used to save computation
% time. The proper format is the output of C1.m
%
% See also C1
if nargin<8
[c1,s1] = C1(stim,filters,fSiz,c1SpaceSS,c1ScaleSS,c1OL);
end
nbands = length(c1);
c1BandImage = c1;
nfilts = size(c1{1},3);
n_rbf_centers = size(s2Target,2);
L = size(s2Target,1) / nfilts;
PatchSize = [L^.5,L^.5,nfilts];
%% Build s2:
% for all prototypes in s2Target (RBF centers)
% for all bands
% calculate the image response
s2 = cell(n_rbf_centers,1);
for iCenter = 1:n_rbf_centers
Patch = reshape(s2Target(:,iCenter),PatchSize);
s2{iCenter} = cell(nbands,1);
for iBand = 1:nbands
s2{iCenter}{iBand} = WindowedPatchDistance(c1BandImage{iBand},Patch);
end
end
%% Build c2:
% calculate minimum distance (maximum stimulation) across position and scales
c2 = inf(n_rbf_centers,1);
for iCenter = 1:n_rbf_centers
for iBand = 1:nbands
c2(iCenter) = min(c2(iCenter),min(min(s2{iCenter}{iBand})));
end
end