diff options
author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
---|---|---|
committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/texture_synthesis/src/matlab/buildSFpyr.m | |
parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/buildSFpyr.m')
-rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/buildSFpyr.m | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/buildSFpyr.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/buildSFpyr.m new file mode 100755 index 0000000..ae67206 --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/matlab/buildSFpyr.m | |||
@@ -0,0 +1,102 @@ | |||
1 | % [PYR, INDICES, STEERMTX, HARMONICS] = buildSFpyr(IM, HEIGHT, ORDER, TWIDTH) | ||
2 | % | ||
3 | % Construct a steerable pyramid on matrix IM, in the Fourier domain. | ||
4 | % This is similar to buildSpyr, except that: | ||
5 | % | ||
6 | % + Reconstruction is exact (within floating point errors) | ||
7 | % + It can produce any number of orientation bands. | ||
8 | % - Typically slower, especially for non-power-of-two sizes. | ||
9 | % - Boundary-handling is circular. | ||
10 | % | ||
11 | % HEIGHT (optional) specifies the number of pyramid levels to build. Default | ||
12 | % is maxPyrHt(size(IM),size(FILT)); | ||
13 | % | ||
14 | % The squared radial functions tile the Fourier plane, with a raised-cosine | ||
15 | % falloff. Angular functions are cos(theta-k\pi/(K+1))^K, where K is | ||
16 | % the ORDER (one less than the number of orientation bands, default= 3). | ||
17 | % | ||
18 | % TWIDTH is the width of the transition region of the radial lowpass | ||
19 | % function, in octaves (default = 1, which gives a raised cosine for | ||
20 | % the bandpass filters). | ||
21 | % | ||
22 | % PYR is a vector containing the N pyramid subbands, ordered from fine | ||
23 | % to coarse. INDICES is an Nx2 matrix containing the sizes of | ||
24 | % each subband. This is compatible with the MatLab Wavelet toolbox. | ||
25 | % See the function STEER for a description of STEERMTX and HARMONICS. | ||
26 | |||
27 | % Eero Simoncelli, 5/97. | ||
28 | % See http://www.cns.nyu.edu/~eero/STEERPYR/ for more | ||
29 | % information about the Steerable Pyramid image decomposition. | ||
30 | |||
31 | function [pyr,pind,steermtx,harmonics] = buildSFpyr(im, ht, order, twidth) | ||
32 | |||
33 | %----------------------------------------------------------------- | ||
34 | %% DEFAULTS: | ||
35 | |||
36 | max_ht = floor(log2(min(size(im)))) - 2; | ||
37 | |||
38 | if (exist('ht') ~= 1) | ||
39 | ht = max_ht; | ||
40 | else | ||
41 | if (ht > max_ht) | ||
42 | error(sprintf('Cannot build pyramid higher than %d levels.',max_ht)); | ||
43 | end | ||
44 | end | ||
45 | |||
46 | if (exist('order') ~= 1) | ||
47 | order = 3; | ||
48 | elseif ((order > 15) | (order < 0)) | ||
49 | fprintf(1,'Warning: ORDER must be an integer in the range [0,15]. Truncating.\n'); | ||
50 | order = min(max(order,0),15); | ||
51 | else | ||
52 | order = round(order); | ||
53 | end | ||
54 | nbands = order+1; | ||
55 | |||
56 | if (exist('twidth') ~= 1) | ||
57 | twidth = 1; | ||
58 | elseif (twidth <= 0) | ||
59 | fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n'); | ||
60 | twidth = 1; | ||
61 | end | ||
62 | |||
63 | %----------------------------------------------------------------- | ||
64 | %% Steering stuff: | ||
65 | |||
66 | if (mod((nbands),2) == 0) | ||
67 | harmonics = [0:(nbands/2)-1]'*2 + 1; | ||
68 | else | ||
69 | harmonics = [0:(nbands-1)/2]'*2; | ||
70 | end | ||
71 | |||
72 | steermtx = steer2HarmMtx(harmonics, pi*[0:nbands-1]/nbands, 'even'); | ||
73 | |||
74 | %----------------------------------------------------------------- | ||
75 | |||
76 | dims = size(im); | ||
77 | ctr = ceil((dims+0.5)/2); | ||
78 | |||
79 | [xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ... | ||
80 | ([1:dims(1)]-ctr(1))./(dims(1)/2) ); | ||
81 | angle = atan2(yramp,xramp); | ||
82 | log_rad = sqrt(xramp.^2 + yramp.^2); | ||
83 | log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1); | ||
84 | log_rad = log2(log_rad); | ||
85 | |||
86 | %% Radial transition function (a raised cosine in log-frequency): | ||
87 | [Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]); | ||
88 | Yrcos = sqrt(Yrcos); | ||
89 | |||
90 | YIrcos = sqrt(1.0 - Yrcos.^2); | ||
91 | lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); | ||
92 | imdft = fftshift(fft2(im)); | ||
93 | lo0dft = imdft .* lo0mask; | ||
94 | |||
95 | [pyr,pind] = buildSFpyrLevs(lo0dft, log_rad, Xrcos, Yrcos, angle, ht, nbands); | ||
96 | |||
97 | hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); | ||
98 | hi0dft = imdft .* hi0mask; | ||
99 | hi0 = ifft2(ifftshift(hi0dft)); | ||
100 | |||
101 | pyr = [real(hi0(:)) ; pyr]; | ||
102 | pind = [size(hi0); pind]; | ||