-
Notifications
You must be signed in to change notification settings - Fork 29
/
opCurvelet.m
127 lines (105 loc) · 4.09 KB
/
opCurvelet.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
123
124
125
126
127
classdef opCurvelet < opSpot
%OPCURVELET Two-dimensional curvelet operator.
%
% opCurvelet(M,N,NBSCALES,NBANGLES,TTYPE) creates a two-dimensional
% curvelet operator for M by N matrices. The curvelet transform is
% computed using the Curvelab code.
%
% The remaining three parameters are optional; NBSCALES gives the
% number of scales and is set to max(1,ceil(log2(min(M,N)) - 3)) by
% default, as suggested by Curvelab. NBANGLES gives the number of
% angles at the second coarsest level which must be a multiple of
% four with a minimum of 8. By default NBANGLES is set to 16. TTYPE
% determines the type of transformation and is set to 'WRAP' by
% default.
%
% See also CURVELAB.
% Copyright 2009, Gilles Hennenfent, Ewout van den Berg and Michael P. Friedlander
% See the file COPYING.txt for full copyright information.
% Use the command 'spot.gpl' to locate this file.
% http://www.cs.ubc.ca/labs/scl/spot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
properties (SetAccess = private)
funHandle = []; % Multiplication function
end % Properties
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Constructor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opCurvelet(m,n,nbscales,nbangles,ttype)
if nargin < 3, nbscales = max(1,ceil(log2(min(m,n)) - 3)); end;
if nargin < 4, nbangles = 16; end;
if nargin < 5, ttype = 'WRAP'; end; % Wrapping
finest = 1;
is_real = 1;
% Compute length of curvelet coefficient vector
if strcmp(ttype,'ME')
C = mefcv2(randn(m,n),m,n,nbscales,nbangles);
hdr{1}{1} = size(C{1}{1});
cn = prod(hdr{1}{1});
for i = 2:nbscales
nw = length(C{i});
hdr{i}{1} = size(C{i}{1});
hdr{i}{2} = size(C{i}{nw/2+1});
cn = cn + nw/2*prod(hdr{i}{1}) + nw/2*prod(hdr{i}{2});
end
else
C = fdct_wrapping_mex(m,n,nbscales,nbangles,finest,randn(m,n));
hdr{1}{1} = size(C{1}{1});
cn = prod(hdr{1}{1});
for i = 2:nbscales
nw = length(C{i});
hdr{i}{1} = size(C{i}{1});
hdr{i}{2} = size(C{i}{nw/4+1});
cn = cn + nw/2*prod(hdr{i}{1}) + nw/2*prod(hdr{i}{2});
end
end
parms = {m,n,cn,hdr,finest,nbscales,nbangles,is_real,ttype};
fun = @(x,mode) opCurvelet_intrnl(parms{:},x,mode);
% Construct operator
op = op@opSpot('Curvelet', cn, m*n);
op.cflag = ~is_real;
op.funHandle = fun;
end % Constructor
end % Methods
methods ( Access = protected )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multiply
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = multiply(op,x,mode)
y = op.funHandle(x,mode);
end % Multiply
end % Methods
end % Classdef
%=======================================================================
function y = opCurvelet_intrnl(m,n,cn,hdr,ac,nbs,nba,is_real,ttype,x,mode)
if mode == 1
% Analysis mode
if strcmp(ttype,'ME')
y = mefcv2(reshape(x,m,n),m,n,nbs,nba);
else
y = fdct_wrapping_mex(m,n,nbs,nba,ac,reshape(x,m,n));
y = fdct_wrapping_c2r(y);
end
y = spot.utils.fdct_c2v(y,cn);
else
% Synthesis mode
if strcmp(ttype,'ME')
x = mefdct_v2c(x,hdr,nba);
y = meicv2(x,m,n,nbs,nba);
else
x = spot.utils.fdct_v2c(x,hdr,ac,nba);
x = fdct_wrapping_r2c(x);
y = ifdct_wrapping_mex(m,n,nbs,nba,ac,x);
end
if is_real
y = real(y);
end
y = y(:);
end
end