source: branches/pixel-map-branch/src/ATrous/filter.cc

Last change on this file was 243, checked in by Matthew Whiting, 17 years ago

Large commit with the new version using Scans & Object just about working.

The major problem at the moment is that there seems to be something not quite working with the merger part of the code, and some dud scans are being introduced (where X & Y are very large numbers -- apparently unallocated...)

File size: 6.0 KB
Line 
1#include <iostream>
2#include <sstream>
3#include <duchamp.hh>
4#include <ATrous/filter.hh>
5#include <math.h>
6#include <vector>
7
8Filter::Filter()
9{
10  this->sigmaFactors.resize(3);
11  for(int i=0;i<3;i++) this->sigmaFactors[i] = new std::vector<double>(20);
12  this->loadSpline();
13}
14//-----------------------------------------------------------------------
15
16Filter::~Filter()
17{
18  filter1D.clear();
19  maxNumScales.clear();
20  sigmaFactors.clear();
21}
22//-----------------------------------------------------------------------
23
24void Filter::define(int filtercode)
25{
26  switch(filtercode)
27    {
28    case 2:
29      this->loadTriangle();
30      break;
31    case 3:
32      this->loadHaar();
33      break;
34    case 4:
35      //       this->loadTopHat();
36    case 1:
37    default:
38      if(filtercode!=1){
39        if(filtercode==4) {
40          std::stringstream errmsg;
41          errmsg << "TopHat Wavelet not being used currently."
42                 << "Using B3 spline instead.\n";
43          duchampWarning("Filter::define", errmsg.str());
44        }
45        else {
46          std::stringstream errmsg;
47          errmsg << "Filter code " << filtercode << " undefined. Using B3 spline.\n";
48          duchampWarning("Filter::define", errmsg.str());
49        }
50      }
51      this->loadSpline();
52      break;
53    }
54 
55}
56//-----------------------------------------------------------------------
57
58int Filter::getNumScales(long length)
59{
60  switch(this->filter1D.size()){
61  case 5:
62    return int(log(double(length-1))/M_LN2) - 1;
63    break;
64  case 3:
65    return int(log(double(length-1))/M_LN2);
66    break;
67  default:
68    return 1 + int(log(double(length-1)/double(this->filter1D.size()-1))/M_LN2);
69    break;
70  }
71}
72//-----------------------------------------------------------------------
73
74int Filter::getMaxSize(int scale)
75{
76  switch(this->filter1D.size()){
77  case 5:
78    return int(pow(2,scale+1)) + 1;
79    break;
80  case 3:
81    return int(pow(2,scale)) + 1;
82    break;
83  default:
84    return int(pow(2,scale-1))*(this->filter1D.size()-1) + 1;
85    break;
86  }
87}
88//-----------------------------------------------------------------------
89
90void Filter::loadSpline()
91{
92  double filter[5] = {0.0625, 0.25, 0.375, 0.25, 0.0625};
93  this->name = "B3 spline function";
94  this->filter1D.resize(5);
95  for(int i=0;i<5;i++) this->filter1D[i] = filter[i];
96  this->sigmaFactors.resize(3);
97  this->maxNumScales.resize(3);
98
99  this->maxNumScales[0] = 18;
100  double sigmaFactors1D[19] = {1.00000000000,7.23489806e-1,2.85450405e-1,1.77947535e-1,
101                               1.22223156e-1,8.58113122e-2,6.05703043e-2,4.28107206e-2,
102                               3.02684024e-2,2.14024008e-2,1.51336781e-2,1.07011079e-2,
103                               7.56682272e-3,5.35055108e-3,3.78341085e-3,2.67527545e-3,
104                               1.89170541e-3,1.33763772e-3,9.45852704e-4};
105  this->sigmaFactors[0]->resize(19);
106  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
107
108  this->maxNumScales[1] = 11;
109  double sigmaFactors2D[12] = {1.00000000000,8.90796310e-1,2.00663851e-1,8.55075048e-2,
110                               4.12474444e-2,2.04249666e-2,1.01897592e-2,5.09204670e-3,
111                               2.54566946e-3,1.27279050e-3,6.36389722e-4,3.18194170e-4};
112  this->sigmaFactors[1]->resize(12);
113  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
114
115  this->maxNumScales[2] = 7;
116  double sigmaFactors3D[8] = {1.00000000000,9.56543592e-1,1.20336499e-1,3.49500154e-2,
117                              1.18164242e-2,4.13233507e-3,1.45703714e-3,5.14791120e-4};
118  this->sigmaFactors[2]->resize(8);
119  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
120}
121//-----------------------------------------------------------------------
122
123void Filter::loadTriangle()
124{
125  double filter[3] = {1./4., 1./2., 1./4.};
126  this->filter1D.resize(3);
127  for(int i=0;i<3;i++) this->filter1D[i] = filter[i];
128  this->name = "Triangle function";
129  this->sigmaFactors.resize(3);
130  this->maxNumScales.resize(3);
131
132  this->maxNumScales[0] = 18;
133  double sigmaFactors1D[19] = {1.00000000000,6.12372436e-1,3.30718914e-1,2.11947812e-1,
134                               1.45740298e-1,1.02310944e-1,7.22128185e-2,5.10388224e-2,
135                               3.60857673e-2,2.55157615e-2,1.80422389e-2,1.27577667e-2,
136                               9.02109930e-3,6.37887978e-3,4.51054902e-3,3.18942978e-3,
137                               2.25527449e-3,1.59471988e-3,1.12763724e-4};
138  this->sigmaFactors[0]->resize(19);
139  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
140
141  this->maxNumScales[1] = 12;
142  double sigmaFactors2D[13] = {1.00000000000,8.00390530e-1,2.72878894e-1,1.19779282e-1,
143                               5.77664785e-2,2.86163283e-2,1.42747506e-2,7.13319703e-3,
144                               3.56607618e-3,1.78297280e-3,8.91478237e-4,4.45738098e-4,
145                               2.22868922e-4};
146  this->sigmaFactors[1]->resize(13);
147  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
148
149  this->maxNumScales[2] = 8;
150  double sigmaFactors3D[9] = {1.00000000000,8.959544490e-1,1.92033014e-1,5.76484078e-2,
151                              1.94912393e-2,6.812783870e-3,2.40175885e-3,8.48538128e-4,
152                              2.99949455e-4};
153  this->sigmaFactors[2]->resize(9);
154  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
155}
156//-----------------------------------------------------------------------
157
158void Filter::loadHaar()
159{
160  double filter[3] = {0., 1./2., 1./2.};
161  this->name = "Haar wavelet";
162  this->filter1D.resize(3);
163  for(int i=0;i<3;i++) this->filter1D[i] = filter[i];
164  this->sigmaFactors.resize(3);
165  this->maxNumScales.resize(3);
166
167  this->maxNumScales[0] = 6;
168  double sigmaFactors1D[7] = {1.00000000000,7.07167810e-1,5.00000000e-1,3.53553391e-1,
169                              2.50000000e-1,1.76776695e-1,1.25000000e-1};
170  this->sigmaFactors[0]->resize(7);
171  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
172
173  this->maxNumScales[1] = 6;
174  double sigmaFactors2D[7] = {1.00000000000,4.33012702e-1,2.16506351e-1,1.08253175e-1,
175                              5.41265877e-2,2.70632939e-2,1.35316469e-2};
176  this->sigmaFactors[1]->resize(7);
177  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
178
179  this->maxNumScales[2] = 8;
180  double sigmaFactors3D[9] = {1.00000000000,9.35414347e-1,3.30718914e-1,1.16926793e-1,
181                              4.13398642e-2,1.46158492e-2,5.16748303e-3,1.82698115e-3,
182                              6.45935379e-4};
183  this->sigmaFactors[2]->resize(9);
184  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
185}
Note: See TracBrowser for help on using the repository browser.