aimstil  5.0.5
dwt.h
Go to the documentation of this file.
1 #ifndef TIL_DWT_H_
2 #define TIL_DWT_H_
3 
5 
6 // includes from TIL
7 #include "til/numeric_array.h"
8 
9 namespace til
10 {
11 
12  //---------------------------------------------------------------------------
13 
14  //------------//
15  // DWTCubic //
16  //------------//
17 
19  template < typename T, typename BC >
20  struct DWTCubic
21  {
23  struct Direct
24  {
25  typedef T prec_type;
26  void operator()(T * s, std::size_t n, std::size_t step);
27  };
28 
30  struct Inverse
31  {
32  typedef T prec_type;
33  void operator()(T * s, std::size_t n, std::size_t step);
34  };
35  };
36 
37  //------------------------------------------------------------------------------------------------
38 
39  //---------------------//
40  // DWTCubicConjugate //
41  //---------------------//
42 
44  template < typename T, typename BC >
46  {
48  struct Direct
49  {
50  typedef T prec_type;
51  void operator()(T * s, std::size_t n, std::size_t step);
52  };
53 
55  struct Inverse
56  {
57  typedef T prec_type;
58  void operator()(T * s, std::size_t n, std::size_t step);
59  };
60  };
61 
62  //---------------------------------------------------------------------------
63 
64  //---------//
65  // DWTND //
66  //---------//
67 
69  template < typename DWT, std::size_t D >
70  class DWTND;
71 
72  //---------------------------------------------------------------------------
73 
74  template < typename DWT >
75  class DWTND< DWT, 2 >
76  {
77  public: // typedefs
78  typedef typename DWT::prec_type prec_type;
79  void operator()
80  (
81  prec_type * im
83  , int dir
86  );
87  private: // data
88  DWT m_dwt;
89  };
90 
91  //---------------------------------------------------------------------------
92 
93  template < typename DWT >
94  class DWTND< DWT, 3 >
95  {
96  public: // typedefs
97  typedef typename DWT::prec_type prec_type;
98  void operator()
99  (
100  prec_type * im
102  , int dir
105  );
106  private: // data
107  DWT m_dwt;
108  };
109 
110  /*
111  //---------------------------------------------------------------------------
112 
113  //--------------//
114  // DWTND (2D) //
115  //--------------//
116 
118  template < typename DWT >
119  class DWTND<DWT, 2>
120  {
121  public: // typedefs
122  typedef typename DWT::prec_type prec_type;
123 
124  public: // operators
125  void operator()(prec_type * im, numeric_array<std::size_t,2> dim, int dir, numeric_array<std::size_t,2> step, numeric_array<std::size_t,2> real_dim)
126  {
127  assert(dir >= 0);
128  assert(dir < 2);
129  if (dir == 0)
130  {
131  for (std::size_t j = 0; j < dim[1]; ++j)
132  {
133  m_dwt(im+j*step[1]*real_dim[0], dim[0], step[0]);
134  }
135  }
136  else if (dir == 1)
137  {
138  for (std::size_t i = 0; i < dim[0]; ++i)
139  {
140  m_dwt(im+i*step[0], dim[1], real_dim[0]*step[1]);
141  }
142  }
143  }
144 
145  private: // data
146  DWT m_dwt;
147  };
148 
149  //--------------//
150  // DWTND (3D) //
151  //--------------//
152 
154  template < typename DWT >
155  class DWTND<DWT,3>
156  {
157  public: // typedefs
158  typedef typename DWT::prec_type prec_type;
159 
160  public: // operators
161  void operator()(prec_type * im, numeric_array<std::size_t,3> dim, int dir, numeric_array<std::size_t,3> step, numeric_array<std::size_t,3> real_dim);
162 
163  private: // data
164  DWT m_dwt;
165  };
166  //------------------------------------------------------------------------------------------------
167  */
168 
169  //------------//
170  // MultiDWT //
171  //------------//
172 
175  struct MultiDWT
176  {
178  template < typename DWT >
179  class Direct
180  {
181  public: // typedefs
182  typedef typename DWT::prec_type prec_type;
183 
184  public: // operators
185  void operator()
186  (
187  prec_type * s,
188  std::size_t n
189  );
190 
191  private: // data
192  DWT m_dwt;
193  };
194 
196  template < typename IDWT >
197  class Inverse
198  {
199  public: // typedefs
200  typedef typename IDWT::prec_type prec_type;
201 
202  public: // operators
203  void operator()
204  (
205  prec_type * s,
206  std::size_t n
207  );
208 
209  private: // data
210  IDWT m_idwt;
211  };
212  };
213 
214  //------------------------------------------------------------------------------------------------
215 
216  //--------------//
217  // MultiDWTND //
218  //--------------//
219 
222  struct MultiDWTND
223  {
224  template < typename DWT, std::size_t D >
225  class Direct
226  {
227  public: // typedefs
228  typedef typename DWT::prec_type prec_type;
229  public: // operator
230  void operator()(prec_type * im, const numeric_array<std::size_t,D> dim);
231 
232  private: // function
233 
234  template < typename TIterator >
235  static bool or_all(TIterator begin, TIterator end)
236  {
237  for (; begin != end; ++begin)
238  {
239  if (*begin) return true;
240  }
241  return false;
242  }
243 
244  private: // data
245  DWT m_dwt;
246  };
247 
248 
249  template < typename IDWT, std::size_t D >
250  class Inverse
251  {
252  public: // typedefs
253  typedef typename IDWT::prec_type prec_type;
254 
255  public: // operator
256  void operator()(prec_type * im, const numeric_array<std::size_t,D> dim);
257 
258  private: // static functions
259 
260  static inline bool greater_than_others(numeric_array<std::size_t,D> sm, int i0)
261  {
262  for (std::size_t i = 0; i < D; ++i)
263  {
264  // NB: I removed this test, because I think, in general, it slows down the code. However it works
265  // only if the test is always true for two equal values.
266  //if (i == i0) continue;
267  if (sm[i] > sm[i0]) return false;
268  }
269  return true;
270  }
271 
272  private: // data
273  IDWT m_idwt;
274  };
275  };
276 
277  //------------------------------------------------------------------------------------------------
278 
279  template < typename T >
281  {
282  void operator()(T * s, std::size_t length, std::size_t hop);
283  };
284 
285  //------------------------------------------------------------------------------------------------
286 
287  template < typename T, std::size_t D >
289 
290  template < typename T >
291  struct MultiDWTNDPower< T, 3 >
292  {
293  void operator()(T * im, numeric_array<std::size_t,3> dim);
294  };
295 
296  //------------------------------------------------------------------------------------------------
297 
298  //--------------//
299  // DWTShuffle //
300  //--------------//
301 
302  template < typename T >
304  {
305  public: // constructors
306  MultiDWTShuffle() : m_buffer() {}
307  MultiDWTShuffle(std::size_t maxlength) : m_buffer(maxlength) {}
308  public: // functions
309  void shuffle(T * s, std::size_t length, std::size_t jump = 1);
310  void unshuffle(T * s, std::size_t length, std::size_t jump = 1);
311  private: // data
312  std::vector<T> m_buffer;
313  };
314 
315  //------------------------------------------------------------------------------------------------
316 
317  template < typename T, std::size_t D >
319 
320  //------------------------------------------------------------------------------------------------
321 
322  template < typename T >
323  struct MultiDWTNDShuffle<T,2>
324  {
325  void shuffle(T * im, numeric_array<std::size_t,2> dim);
326  void unshuffle(T * im, numeric_array<std::size_t,2> dim);
327  };
328 
329  //------------------------------------------------------------------------------------------------
330 
331  template < typename T >
332  struct MultiDWTNDShuffle<T,3>
333  {
334  void shuffle(T * im, numeric_array<std::size_t,3> dim);
335  void unshuffle(T * im, numeric_array<std::size_t,3> dim);
336  };
337 
338  //------------------------------------------------------------------------------------------------
339 
340  //---------------------------------//
341  // Helper functions for all this //
342  //---------------------------------//
343 
345  template < typename T, typename BC >
346  inline void dwt_cubic(T * s, std::size_t n, std::size_t step, BC);
347 
349  template < typename T >
350  inline void dwt_cubic(T * s, std::size_t n, std::size_t step);
351 
353  template < typename T, typename BC >
354  inline void idwt_cubic(T * s, std::size_t n, std::size_t step, BC);
355 
357  template < typename T >
358  inline void idwt_cubic(T * s, std::size_t n, std::size_t step);
359 
360  template < typename T, std::size_t D >
361  inline void dwtND_cubic(T * im, numeric_array<std::size_t, D> dim);
362 
363  template < typename T, std::size_t D >
364  inline void dwtND_cubicConjugate(T * im, numeric_array<std::size_t, D> dim);
365 
366  template < typename T, typename BC >
367  void multi_dwt_cubic(T * s, std::size_t dim, BC);
368 
369  template < typename T >
370  void multi_dwt_cubic(T * s, std::size_t dim);
371 
372  template < typename T, typename BC >
373  void multi_idwt_cubic(T * s, std::size_t dim, BC);
374 
375  template < typename T >
376  void multi_idwt_cubic(T * s, std::size_t dim);
377 
378  template < typename T, std::size_t D, typename BC >
379  void multi_dwtND_cubic(T * im, numeric_array<std::size_t,D> dim, BC);
380 
381  template < typename T, std::size_t D >
383 
384  template < typename T, std::size_t D, typename BC >
385  void multi_idwtND_cubic(T * im, numeric_array<std::size_t,D> dim, BC);
386 
387  template < typename T, std::size_t D >
389 
390  template < typename T >
391  void multi_dwt_shuffle(T * s, std::size_t n);
392 
393  template < typename T >
394  void multi_dwt_unshuffle(T * s, std::size_t n);
395 
396  template < typename T, std::size_t D >
398 
399  template < typename T, std::size_t D >
401 
402  template < typename T, std::size_t D >
404 
405 } // namespace til
406 
407 // package include
408 #include "dwt.tpp"
409 
410 #endif /*DWT_H_*/
void multi_dwt_cubic(T *s, std::size_t dim, BC)
void dwtND_cubic(T *im, numeric_array< std::size_t, D > dim)
DWT::prec_type prec_type
Definition: dwt.h:78
void dwtND_cubicConjugate(T *im, numeric_array< std::size_t, D > dim)
void multi_dwtND_shuffle(T *im, numeric_array< std::size_t, D > dim)
void dwt_cubic(T *s, std::size_t n, std::size_t step, BC)
In-place (4-2) DWT via lifting.
void idwt_cubic(T *s, std::size_t n, std::size_t step, BC)
In-place inverse (4-2) DWT via lifting.
void multi_idwtND_cubic(T *im, numeric_array< std::size_t, D > dim, BC)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
DWT::prec_type prec_type
Definition: dwt.h:182
DWT::prec_type prec_type
Definition: dwt.h:228
Direct DWT.
Definition: dwt.h:23
Extension of DWT to multidimensional arrays.
Definition: dwt.h:70
In-place (4-2) DWT via lifting.
Definition: dwt.h:20
DWT::prec_type prec_type
Definition: dwt.h:97
Multi-scale in-place DWT.
Definition: dwt.h:175
void multi_dwtND_power(T *im, numeric_array< std::size_t, D > dim)
void multi_dwtND_unshuffle(T *im, numeric_array< std::size_t, D > dim)
Inverse multiscale DWT.
Definition: dwt.h:197
IDWT::prec_type prec_type
Definition: dwt.h:253
Direct multiscale DWT.
Definition: dwt.h:179
void operator()(T *s, std::size_t n, std::size_t step)
void multi_dwt_shuffle(T *s, std::size_t n)
Inverse DWT.
Definition: dwt.h:30
Multi-scale in-place DWT in N-D.
Definition: dwt.h:222
void multi_dwt_unshuffle(T *s, std::size_t n)
void multi_idwt_cubic(T *s, std::size_t dim, BC)
IDWT::prec_type prec_type
Definition: dwt.h:200
void multi_dwtND_cubic(T *im, numeric_array< std::size_t, D > dim, BC)
Transposed filter of (4-2).
Definition: dwt.h:45
MultiDWTShuffle(std::size_t maxlength)
Definition: dwt.h:307