summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/texture_synthesis/src/matlab/textureAnalysis.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/textureAnalysis.m')
-rwxr-xr-xSD-VBS/benchmarks/texture_synthesis/src/matlab/textureAnalysis.m245
1 files changed, 0 insertions, 245 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/textureAnalysis.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/textureAnalysis.m
deleted file mode 100755
index d7a0ec1..0000000
--- a/SD-VBS/benchmarks/texture_synthesis/src/matlab/textureAnalysis.m
+++ /dev/null
@@ -1,245 +0,0 @@
1function [params] = textureAnalysis(im0, Nsc, Nor, Na)
2
3% Analyze texture for application of Portilla-Simoncelli model/algorithm.
4%
5% [params] = textureAnalysis(im0, Nsc, Nor, Na);
6% im0: original image
7% Nsc: number of scales
8% Nor: number of orientations
9% Na: spatial neighborhood considered (Na x Na)
10%
11% Example: Nsc=4; Nor=4; Na=7;
12%
13% See also textureSynthesis.
14
15% Javier Portilla and Eero Simoncelli.
16% Work described in:
17% "A Parametric Texture Model based on Joint Statistics of Complex Wavelet Coefficients".
18% J Portilla and E P Simoncelli. Int'l Journal of Computer Vision,
19% vol.40(1), pp. 49-71, Dec 2000.
20%
21% Please refer to this publication if you use the program for research or
22% for technical applications. Thank you.
23%
24% Copyright, Center for Neural Science, New York University, January 2001.
25% All rights reserved.
26
27
28%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30Warn = 0; % Set to 1 if you want to see warning messages
31
32%% Check required args are passed
33if (nargin < 4)
34 error('Function called with too few input arguments');
35end
36
37%% 1D interpolation filter, for scale cross-correlations:
38interp = [-1/16 0 9/16 1 9/16 0 -1/16]/sqrt(2);
39
40if ( mod(Na,2) == 0 )
41 error('Na is not an odd integer');
42end
43
44%% If the spatial neighborhood Na is too big for the lower scales,
45%% "modacor22.m" will make it as big as the spatial support at
46%% each scale:
47
48[Ny,Nx] = size(im0);
49nth = log2(min(Ny,Nx)/Na);
50if nth<Nsc & Warn,
51 fprintf(1,'Warning: Na will be cut off for levels above #%d !\n', floor(nth+1));
52end
53
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
56la = floor((Na-1)/2);
57
58%% Pixel statistics
59[mn0 mx0] = size(im0);
60mean0 = mean2(im0);
61var0 = var2(im0, mean0);
62skew0 = skew2(im0, mean0, var0);
63kurt0 = kurt2(im0, mean0, var0);
64statg0 = [mean0 var0 skew0 kurt0 mn0 mx0];
65
66% Add a little bit of noise to the original, in case it has been
67% artificially generated, to avoid instability crated by symmetric
68% conditions at the synthesis stage.
69
70%im0 = im0 + (mx0-mn0)/1000*randn(size(im0)); %kvs
71
72%% Build the steerable pyramid
73[pyr0,pind0] = buildSCFpyr(im0,Nsc,Nor-1);
74
75if ( any(vector(mod(pind0,2))) )
76 error('Algorithm will fail: Some bands have odd dimensions!');
77end
78
79%% Subtract mean of lowBand:
80nband = size(pind0,1);
81pyr0(pyrBandIndices(pind0,nband)) = ...
82 real(pyrBand(pyr0,pind0,nband)) - mean2(real(pyrBand(pyr0,pind0,nband)));
83
84rpyr0 = real(pyr0);
85apyr0 = abs(pyr0);
86
87figure(gcf)
88clf
89showIm(im0,'auto',1); title('Original'); drawnow
90
91%% Subtract mean of magnitude:
92magMeans0 = zeros(size(pind0,1), 1);
93for nband = 1:size(pind0,1)
94 indices = pyrBandIndices(pind0,nband);
95 magMeans0(nband) = mean2(apyr0(indices));
96 apyr0(indices) = apyr0(indices) - magMeans0(nband);
97end
98
99%% Compute central autoCorr of lowband
100acr = NaN * ones(Na,Na,Nsc+1);
101nband = size(pind0,1);
102ch = pyrBand(pyr0,pind0,nband);
103[mpyr,mpind] = buildSFpyr(real(ch),0,0);
104im = pyrBand(mpyr,mpind,2);
105[Nly Nlx] = size(ch);
106Sch = min(Nly,Nlx); %size of low band
107le = min(Sch/2-1,la);
108cy = Nly/2+1;
109cx = Nlx/2+1;
110ac = fftshift(real(ifft2(abs(fft2(im)).^2)))/prod(size(ch));
111ac = ac(cy-le:cy+le,cx-le:cx+le);
112acr(la-le+1:la+le+1,la-le+1:la+le+1,Nsc+1) = ac;
113skew0p = zeros(Nsc+1,1);
114kurt0p = zeros(Nsc+1,1);
115vari = ac(le+1,le+1);
116if vari/var0 > 1e-6,
117 skew0p(Nsc+1) = mean2(im.^3)/vari^1.5;
118 kurt0p(Nsc+1) = mean2(im.^4)/vari^2;
119else
120 skew0p(Nsc+1) = 0;
121 kurt0p(Nsc+1) = 3;
122end
123
124%% Compute central autoCorr of each Mag band, and the autoCorr of the
125%% combined (non-oriented) band.
126ace = NaN * ones(Na,Na,Nsc,Nor);
127for nsc = Nsc:-1:1,
128 for nor = 1:Nor,
129 nband = (nsc-1)*Nor+nor+1;
130 ch = pyrBand(apyr0,pind0,nband);
131 [Nly, Nlx] = size(ch);
132 Sch = min(Nlx, Nly);
133 le = min(Sch/2-1,la);
134 cx = Nlx/2+1; %Assumes Nlx even
135 cy = Nly/2+1;
136 ac = fftshift(real(ifft2(abs(fft2(ch)).^2)))/prod(size(ch));
137 ac = ac(cy-le:cy+le,cx-le:cx+le);
138 ace(la-le+1:la+le+1,la-le+1:la+le+1,nsc,nor) = ac;
139 end
140
141 %% Combine ori bands
142
143 bandNums = [1:Nor] + (nsc-1)*Nor+1; %ori bands only
144 ind1 = pyrBandIndices(pind0, bandNums(1));
145 indN = pyrBandIndices(pind0, bandNums(Nor));
146 bandInds = [ind1(1):indN(length(indN))];
147 %% Make fake pyramid, containing dummy hi, ori, lo
148 fakePind = [pind0(bandNums(1),:);pind0(bandNums(1):bandNums(Nor)+1,:)];
149 fakePyr = [zeros(prod(fakePind(1,:)),1);...
150 rpyr0(bandInds); zeros(prod(fakePind(size(fakePind,1),:)),1);];
151 ch = reconSFpyr(fakePyr, fakePind, [1]); % recon ori bands only
152 im = real(expand(im,2))/4;
153 im = im + ch;
154 ac = fftshift(real(ifft2(abs(fft2(im)).^2)))/prod(size(ch));
155 ac = ac(cy-le:cy+le,cx-le:cx+le);
156 acr(la-le+1:la+le+1,la-le+1:la+le+1,nsc) = ac;
157 vari = ac(le+1,le+1);
158 if vari/var0 > 1e-6,
159 skew0p(nsc) = mean2(im.^3)/vari^1.5;
160 kurt0p(nsc) = mean2(im.^4)/vari^2;
161 else
162 skew0p(nsc) = 0;
163 kurt0p(nsc) = 3;
164 end
165end
166
167%% Compute the cross-correlation matrices of the coefficient magnitudes
168%% pyramid at the different levels and orientations
169
170C0 = zeros(Nor,Nor,Nsc+1);
171Cx0 = zeros(Nor,Nor,Nsc);
172
173Cr0 = zeros(2*Nor,2*Nor,Nsc+1);
174Crx0 = zeros(2*Nor,2*Nor,Nsc);
175
176for nsc = 1:Nsc,
177 firstBnum = (nsc-1)*Nor+2;
178 cousinSz = prod(pind0(firstBnum,:));
179 ind = pyrBandIndices(pind0,firstBnum);
180 cousinInd = ind(1) + [0:Nor*cousinSz-1];
181
182 if (nsc<Nsc)
183 parents = zeros(cousinSz,Nor);
184 rparents = zeros(cousinSz,Nor*2);
185 for nor=1:Nor,
186 nband = (nsc-1+1)*Nor+nor+1;
187
188 tmp = expand(pyrBand(pyr0, pind0, nband),2)/4;
189 rtmp = real(tmp); itmp = imag(tmp);
190 %% Double phase:
191 tmp = sqrt(rtmp.^2 + itmp.^2) .* exp(2 * sqrt(-1) * atan2(rtmp,itmp));
192 rparents(:,nor) = vector(real(tmp));
193 rparents(:,Nor+nor) = vector(imag(tmp));
194
195 tmp = abs(tmp);
196 parents(:,nor) = vector(tmp - mean2(tmp));
197 end
198 else
199 tmp = real(expand(pyrLow(rpyr0,pind0),2))/4;
200 rparents = [vector(tmp),...
201 vector(shift(tmp,[0 1])), vector(shift(tmp,[0 -1])), ...
202 vector(shift(tmp,[1 0])), vector(shift(tmp,[-1 0]))];
203 parents = [];
204 end
205
206 cousins = reshape(apyr0(cousinInd), [cousinSz Nor]);
207 nc = size(cousins,2); np = size(parents,2);
208 C0(1:nc,1:nc,nsc) = innerProd(cousins)/cousinSz;
209 if (np > 0)
210 Cx0(1:nc,1:np,nsc) = (cousins'*parents)/cousinSz;
211 if (nsc==Nsc)
212 C0(1:np,1:np,Nsc+1) = innerProd(parents)/(cousinSz/4);
213 end
214 end
215
216 cousins = reshape(real(pyr0(cousinInd)), [cousinSz Nor]);
217 nrc = size(cousins,2); nrp = size(rparents,2);
218 Cr0(1:nrc,1:nrc,nsc) = innerProd(cousins)/cousinSz;
219 if (nrp > 0)
220 Crx0(1:nrc,1:nrp,nsc) = (cousins'*rparents)/cousinSz;
221 if (nsc==Nsc)
222 Cr0(1:nrp,1:nrp,Nsc+1) = innerProd(rparents)/(cousinSz/4);
223 end
224 end
225end
226
227%% Calculate the mean, range and variance of the LF and HF residuals' energy.
228
229channel = pyr0(pyrBandIndices(pind0,1));
230vHPR0 = mean2(channel.^2);
231
232statsLPim = [skew0p kurt0p];
233
234params = struct('pixelStats', statg0, ...
235 'pixelLPStats', statsLPim, ...
236 'autoCorrReal', acr, ...
237 'autoCorrMag', ace, ...
238 'magMeans', magMeans0, ...
239 'cousinMagCorr', C0, ...
240 'parentMagCorr', Cx0, ...
241 'cousinRealCorr', Cr0, ...
242 'parentRealCorr', Crx0, ...
243 'varianceHPR', vHPR0);
244
245