1% [PYR, INDICES, STEERMTX, HARMONICS] = buildSCFpyr(IM, HEIGHT, ORDER, TWIDTH)
2%
3% This is a modified version of buildSFpyr, that constructs a
4% complex-valued steerable pyramid  using Hilbert-transform pairs
5% of filters.  Note that the imaginary parts will *not* be steerable.
6%
7% To reconstruct from this representation, either call reconSFpyr
8% on the real part of the pyramid, *or* call reconSCFpyr which will
9% use both real and imaginary parts (forcing analyticity).
10%
11% Description of this transform appears in: Portilla & Simoncelli,
12% Int'l Journal of Computer Vision, 40(1):49-71, Oct 2000.
13% Further information: http://www.cns.nyu.edu/~eero/STEERPYR/
14
15% Original code: Eero Simoncelli, 5/97.
16% Modified by Javier Portilla to return complex (quadrature pair) channels,
17% 9/97.
18
19function [pyr,pind,steermtx,harmonics] = buildSCFpyr(im, ht, order, twidth)
20
21%-----------------------------------------------------------------
22%% DEFAULTS:
23
24max_ht = floor(log2(min(size(im)))) - 2;
25
26if (exist('ht') ~= 1)
27  ht = max_ht;
28else
29  if (ht > max_ht)
30    error(sprintf('Cannot build pyramid higher than %d levels.',max_ht));
31  end
32end
33
34if (exist('order') ~= 1)
35  order = 3;
36elseif ((order > 15)  | (order < 0))
37  fprintf(1,'Warning: ORDER must be an integer in the range [0,15]. Truncating.\n');
38  order = min(max(order,0),15);
39else
40  order = round(order);
41end
42nbands = order+1;
43
44if (exist('twidth') ~= 1)
45  twidth = 1;
46elseif (twidth <= 0)
47  fprintf(1,'Warning: TWIDTH must be positive.  Setting to 1.\n');
48  twidth = 1;
49end
50
51%-----------------------------------------------------------------
52%% Steering stuff:
53
54if (mod((nbands),2) == 0)
55  harmonics = [0:(nbands/2)-1]'*2 + 1;
56else
57  harmonics = [0:(nbands-1)/2]'*2;
58end
59
60steermtx = steer2HarmMtx(harmonics, pi*[0:nbands-1]/nbands, 'even');
61
62%-----------------------------------------------------------------
63
64dims = size(im);
65ctr = ceil((dims+0.5)/2);
66
67[xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ...
68    ([1:dims(1)]-ctr(1))./(dims(1)/2) );
69angle = atan2(yramp,xramp);
70log_rad = sqrt(xramp.^2 + yramp.^2);
71log_rad(ctr(1),ctr(2)) =  log_rad(ctr(1),ctr(2)-1);
72log_rad  = log2(log_rad);
73
74%% Radial transition function (a raised cosine in log-frequency):
75[Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]);
76Yrcos = sqrt(Yrcos);
77
78YIrcos = sqrt(1.0 - Yrcos.^2);
79lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
80imdft = fftshift(fft2(im));
81lo0dft =  imdft .* lo0mask;
82
83[pyr,pind] = buildSCFpyrLevs(lo0dft, log_rad, Xrcos, Yrcos, angle, ht, nbands);
84
85hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
86hi0dft =  imdft .* hi0mask;
87hi0 = ifft2(ifftshift(hi0dft));
88
89pyr = [real(hi0(:)) ; pyr];
90pind = [size(hi0); pind];
91