summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m
diff options
context:
space:
mode:
authorleochanj105 <leochanj@live.unc.edu>2020-10-19 23:09:30 -0400
committerleochanj105 <leochanj@live.unc.edu>2020-10-20 02:40:39 -0400
commitf618466c25d43f3bae9e40920273bf77de1e1149 (patch)
tree460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m
parent47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff)
initial sd-vbs
initial sd-vbs add sd-vbs sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m')
-rwxr-xr-xSD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m202
1 files changed, 202 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m
new file mode 100755
index 0000000..0d85f9d
--- /dev/null
+++ b/SD-VBS/benchmarks/texture_synthesis/src/matlab/showLpyr.m
@@ -0,0 +1,202 @@
1% RANGE = showLpyr (PYR, INDICES, RANGE, GAP, LEVEL_SCALE_FACTOR)
2%
3% Display a Laplacian (or Gaussian) pyramid, specified by PYR and
4% INDICES (see buildLpyr), in the current figure.
5%
6% RANGE is a 2-vector specifying the values that map to black and
7% white, respectively. These values are scaled by
8% LEVEL_SCALE_FACTOR^(lev-1) for bands at each level. Passing a value
9% of 'auto1' sets RANGE to the min and max values of MATRIX. 'auto2'
10% sets RANGE to 3 standard deviations below and above 0.0. In both of
11% these cases, the lowpass band is independently scaled. A value of
12% 'indep1' sets the range of each subband independently, as in a call
13% to showIm(subband,'auto1'). Similarly, 'indep2' causes each subband
14% to be scaled independently as if by showIm(subband,'indep2').
15% The default value for RANGE is 'auto1' for 1D images, and 'auto2' for
16% 2D images.
17%
18% GAP (optional, default=1) specifies the gap in pixels to leave
19% between subbands (2D images only).
20%
21% LEVEL_SCALE_FACTOR indicates the relative scaling between pyramid
22% levels. This should be set to the sum of the kernel taps of the
23% lowpass filter used to construct the pyramid (default assumes
24% L2-normalalized filters, using a value of 2 for 2D images, sqrt(2) for
25% 1D images).
26
27% Eero Simoncelli, 2/97.
28
29function [range] = showLpyr(pyr, pind, range, gap, scale);
30
31% Determine 1D or 2D pyramid:
32if ((pind(1,1) == 1) | (pind(1,2) ==1))
33 oned = 1;
34else
35 oned = 0;
36end
37
38%------------------------------------------------------------
39%% OPTIONAL ARGS:
40
41if (exist('range') ~= 1)
42 if (oned==1)
43 range = 'auto1';
44 else
45 range = 'auto2';
46 end
47end
48
49if (exist('gap') ~= 1)
50 gap = 1;
51end
52
53if (exist('scale') ~= 1)
54 if (oned == 1)
55 scale = sqrt(2);
56 else
57 scale = 2;
58 end
59end
60
61%------------------------------------------------------------
62
63nind = size(pind,1);
64
65%% Auto range calculations:
66if strcmp(range,'auto1')
67 range = zeros(nind,1);
68 mn = 0.0; mx = 0.0;
69 for bnum = 1:(nind-1)
70 band = pyrBand(pyr,pind,bnum)/(scale^(bnum-1));
71 range(bnum) = scale^(bnum-1);
72 [bmn,bmx] = range2(band);
73 mn = min(mn, bmn); mx = max(mx, bmx);
74 end
75 if (oned == 1)
76 pad = (mx-mn)/12; % *** MAGIC NUMBER!!
77 mn = mn-pad; mx = mx+pad;
78 end
79 range = range * [mn mx]; % outer product
80 band = pyrLow(pyr,pind);
81 [mn,mx] = range2(band);
82 if (oned == 1)
83 pad = (mx-mn)/12; % *** MAGIC NUMBER!!
84 mn = mn-pad; mx = mx+pad;
85 end
86 range(nind,:) = [mn, mx];
87
88elseif strcmp(range,'indep1')
89 range = zeros(nind,2);
90 for bnum = 1:nind
91 band = pyrBand(pyr,pind,bnum);
92 [mn,mx] = range2(band);
93 if (oned == 1)
94 pad = (mx-mn)/12; % *** MAGIC NUMBER!!
95 mn = mn-pad; mx = mx+pad;
96 end
97 range(bnum,:) = [mn mx];
98 end
99
100elseif strcmp(range,'auto2')
101 range = zeros(nind,1);
102 sqsum = 0; numpixels = 0;
103 for bnum = 1:(nind-1)
104 band = pyrBand(pyr,pind,bnum)/(scale^(bnum-1));
105 sqsum = sqsum + sum(sum(band.^2));
106 numpixels = numpixels + prod(size(band));
107 range(bnum) = scale^(bnum-1);
108 end
109 stdev = sqrt(sqsum/(numpixels-1));
110 range = range * [ -3*stdev 3*stdev ]; % outer product
111 band = pyrLow(pyr,pind);
112 av = mean2(band); stdev = sqrt(var2(band));
113 range(nind,:) = [av-2*stdev,av+2*stdev];
114
115elseif strcmp(range,'indep2')
116 range = zeros(nind,2);
117 for bnum = 1:(nind-1)
118 band = pyrBand(pyr,pind,bnum);
119 stdev = sqrt(var2(band));
120 range(bnum,:) = [ -3*stdev 3*stdev ];
121 end
122 band = pyrLow(pyr,pind);
123 av = mean2(band); stdev = sqrt(var2(band));
124 range(nind,:) = [av-2*stdev,av+2*stdev];
125
126elseif isstr(range)
127 error(sprintf('Bad RANGE argument: %s',range))
128
129elseif ((size(range,1) == 1) & (size(range,2) == 2))
130 scales = scale.^[0:nind-1];
131 range = scales(:) * range; % outer product
132 band = pyrLow(pyr,pind);
133 range(nind,:) = range(nind,:) + mean2(band) - mean(range(nind,:));
134
135end
136
137%% Clear Figure
138clf;
139
140if (oned == 1)
141
142 %%%%% 1D signal:
143 for bnum=1:nind
144 band = pyrBand(pyr,pind,bnum);
145 subplot(nind,1,nind-bnum+1);
146 plot(band);
147 axis([1, prod(size(band)), range(bnum,:)]);
148 end
149
150else
151
152 %%%%% 2D signal:
153 colormap(gray);
154 cmap = get(gcf,'Colormap');
155 nshades = size(cmap,1);
156
157 % Find background color index:
158 clr = get(gcf,'Color');
159 bg = 1;
160 dist = norm(cmap(bg,:)-clr);
161 for n = 1:nshades
162 ndist = norm(cmap(n,:)-clr);
163 if (ndist < dist)
164 dist = ndist;
165 bg = n;
166 end
167 end
168
169 %% Compute positions of subbands:
170 llpos = ones(nind,2);
171 dir = [-1 -1];
172 ctr = [pind(1,1)+1+gap 1];
173 sz = [0 0];
174 for bnum = 1:nind
175 prevsz = sz;
176 sz = pind(bnum,:);
177
178 % Determine center position of new band:
179 ctr = ctr + gap*dir/2 + dir.* floor((prevsz+(dir>0))/2);
180 dir = dir * [0 -1; 1 0]; % ccw rotation
181 ctr = ctr + gap*dir/2 + dir.* floor((sz+(dir<0))/2);
182 llpos(bnum,:) = ctr - floor(sz./2);
183 end
184
185 %% Make position list positive, and allocate appropriate image:
186 llpos = llpos - ones(nind,1)*min(llpos) + 1;
187 urpos = llpos + pind - 1;
188 d_im = bg + zeros(max(urpos));
189
190 %% Paste bands into image, (im-r1)*(nshades-1)/(r2-r1) + 1.5
191 for bnum=1:nind
192 mult = (nshades-1) / (range(bnum,2)-range(bnum,1));
193 d_im(llpos(bnum,1):urpos(bnum,1), llpos(bnum,2):urpos(bnum,2)) = ...
194 mult*pyrBand(pyr,pind,bnum) + (1.5-mult*range(bnum,1));
195 end
196
197 hh = image(d_im);
198 axis('off');
199 pixelAxes(size(d_im),'full');
200 set(hh,'UserData',range);
201
202end