File: sara.cc

package info (click to toggle)
sopt 5.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,704 kB
  • sloc: cpp: 13,620; xml: 182; makefile: 6
file content (28 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download | duplicates (2)
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
#include "sopt/wavelets/sara.h"

int main(int, char const **) {
  // Creates SARA with two wavelets
  using t_i = std::tuple<std::string, sopt::t_uint>;
  sopt::wavelets::SARA sara{t_i{"DB4", 5}, t_i{"DB8", 2}};

  // Then another one for good measure
  sara.emplace_back("DB3", 7);

  // Creates a random signal
  sopt::Image<sopt::t_complex> const input = sopt::Image<sopt::t_complex>::Random(128, 128);
  // Now gets its coefficients
  auto coefficients = sara.direct(input);
  // And transform back. We pass a pre-defined matrix explicitly to illustrate that API.
  // But we could just store the return value as above.
  sopt::Image<sopt::t_complex> recover;  // This matrix will be resized if necessary
  sara.indirect(coefficients, recover);

  // Check the reconstruction is corrrect
  if (not input.isApprox(recover)) throw std::exception();

  // The coefficient for each wavelet basis is stored alongs columns:
  sopt::Image<sopt::t_complex> const DB3_coeffs = sara[2].direct(input) / std::sqrt(sara.size());
  if (not coefficients.rightCols(input.cols()).isApprox(DB3_coeffs)) throw std::exception();

  return 0;
}