-
Notifications
You must be signed in to change notification settings - Fork 7
/
C1So.m
122 lines (91 loc) · 3.64 KB
/
C1So.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
function [c1,s1] = C1So(stim, filters, fSiz, c1SpaceSS, c1ScaleSS, c1OL,numChannel,numPhases)
%
% For more information about S1/C1 unit, refer to Thomas Serre's Matlab
% code in standard Hmax
% normalization params
k = 1; % scaling factor
sigma = 0.225; %semi-contrast constant
if(nargin < 10)
INCLUDEBORDERS = 0;
end
numScaleBands=length(c1ScaleSS)-1;
numScales=c1ScaleSS(end)-1;
% last index in scaleSS contains scale index where next band would start, i.e., 1 after highest scale!!
numSimpleFilters = floor(length(fSiz)/numScales/numChannel);
ScalesInThisBand = cell(1,numScaleBands);
for iBand = 1:numScaleBands
ScalesInThisBand{iBand} = c1ScaleSS(iBand):(c1ScaleSS(iBand+1) -1);
end
%% ---------------------------------------------------------------
% Calculate all filter responses (s1)
% -------------------------------------------------------------------------
s1 = {};
for iBand = 1:numScaleBands
for iScale = 1:length(ScalesInThisBand{iBand})
sc = (iBand-1)*length(ScalesInThisBand{iBand}) + iScale;
for iPhase = 1:numPhases
iUFilterIndex = 0;
% -----------Compute Single-Opponency-----------%
s1{iBand}{iScale}(:,:,:,:,iPhase) = computeSOhmax(stim,filters{sc}{iPhase},numChannel,numSimpleFilters);%SOS1 unit
if(~INCLUDEBORDERS)
for jj=1:numChannel
for ii = 1:numSimpleFilters
iUFilterIndex = iUFilterIndex+1;
s1{iBand}{iScale}(:,:,jj,ii,iPhase) = removeborders(s1{iBand}{iScale}(:,:,jj,ii,iPhase),fSiz(iUFilterIndex+numChannel*numSimpleFilters*(sc-1)));
end
end
end
s1{iBand}{iScale} = im2double(s1{iBand}{iScale});
end
% ------Divisive normalization over opponent color channels-----%
s1{iBand}{iScale} = divNorm_so(s1{iBand}{iScale},k,sigma,numChannel);
end
end
%% ---------------------------------------------------------------
% Calculate local pooling (assuming:SOC1 units)
% -------------------------------------------------------------------------
% (1) pool over scales within band
c1 = {};
for iBand = 1:numScaleBands
for jj=1:numChannel
for iFilt = 1:numSimpleFilters
for iPhase = 1:numPhases
c1{iBand}(:,:,jj,iFilt,iPhase) = zeros(size(s1{iBand}{1}(:,:,jj,iFilt,iPhase)));
for iScale = 1:length(ScalesInThisBand{iBand});
c1{iBand}(:,:,jj,iFilt,iPhase) = max(c1{iBand}(:,:,jj,iFilt,iPhase),s1{iBand}{iScale}(:,:,jj,iFilt,iPhase));
end
end
end
end
end
% (2) pool over local neighborhood
for iBand = 1:numScaleBands
poolRange = (c1SpaceSS(iBand));
for jj=1:numChannel
for iFilt = 1:numSimpleFilters
for iPhase = 1:numPhases
c1{iBand}(:,:,jj,iFilt,iPhase) = maxfilter(c1{iBand}(:,:,jj,iFilt,iPhase),[0 0 poolRange-1 poolRange-1]);
end
end
end
end
%
% (3) subsample
for iBand = 1:numScaleBands
sSS=ceil(c1SpaceSS(iBand)/c1OL);
clear T;
for jj=1:numChannel
for iFilt = 1:numSimpleFilters
for iPhase = 1:numPhases
T(:,:,jj,iFilt,iPhase) = c1{iBand}(1:sSS:end,1:sSS:end,jj,iFilt,iPhase);
end
end
end
c1{iBand} = T;
end
function sout = removeborders(sin,siz)
sin = unpadimage(sin, [(siz+1)/2,(siz+1)/2,(siz-1)/2,(siz-1)/2]);
sin = padarray(sin, [(siz+1)/2,(siz+1)/2],0,'pre');
sout = padarray(sin, [(siz-1)/2,(siz-1)/2],0,'post');
return
%