PCL
PyramidalWaveletTransform.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/PyramidalWaveletTransform.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_PyramidalWaveletTransform_h
53 #define __PCL_PyramidalWaveletTransform_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
61 #include <pcl/String.h>
62 #include <pcl/Vector.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
77 class PCL_CLASS WaveletFilter
78 {
79 public:
80 
84  WaveletFilter() = default;
85 
89  virtual ~WaveletFilter()
90  {
91  }
92 
96  virtual String Name() const = 0;
97 
109  template <typename T>
110  void operator ()( T* f, size_type n, bool inverse = false ) const
111  {
112  Apply( f, n, inverse );
113  }
114 
115 protected:
116 
117  const double* Kc = nullptr; // wavelet filter coefficients
118  Vector Kr; // transpose of filter coefficients
119  int N = 0; // number of coefficients
120  int ioff = 0;
121  int joff = 0;
122 
123  void Initialize()
124  {
125  PCL_CHECK( Kc != nullptr && N > 0 )
126  Kr = Vector( N );
127  for ( int k = 0, sig = -1; k < N; ++k )
128  {
129  Kr[N-1-k] = sig*Kc[k];
130  sig = -sig;
131  }
132  // ioff = joff = -(N >> 1);
133  ioff = -2;
134  joff = -N + 2;
135  }
136 
137 private:
138 
139  void Apply( float*, size_type, bool ) const;
140  void Apply( double*, size_type, bool ) const;
141 };
142 
143 // ----------------------------------------------------------------------------
144 
150 class PCL_CLASS Daubechies4Filter : public WaveletFilter
151 {
152 public:
153 
158 
161  String Name() const override
162  {
163  return "Daubechies-4";
164  }
165 };
166 
167 extern PCL_DATA Daubechies4Filter Daubechies4;
168 
169 // ----------------------------------------------------------------------------
170 
176 class PCL_CLASS Daubechies6Filter : public WaveletFilter
177 {
178 public:
179 
184 
187  String Name() const override
188  {
189  return "Daubechies-6";
190  }
191 };
192 
193 extern PCL_DATA Daubechies6Filter Daubechies6;
194 
195 // ----------------------------------------------------------------------------
196 
202 class PCL_CLASS Daubechies8Filter : public WaveletFilter
203 {
204 public:
205 
210 
213  String Name() const override
214  {
215  return "Daubechies-8";
216  }
217 };
218 
219 extern PCL_DATA Daubechies8Filter Daubechies8;
220 
221 // ----------------------------------------------------------------------------
222 
228 class PCL_CLASS Daubechies10Filter : public WaveletFilter
229 {
230 public:
231 
236 
239  String Name() const override
240  {
241  return "Daubechies-10";
242  }
243 };
244 
245 extern PCL_DATA Daubechies10Filter Daubechies10;
246 
247 // ----------------------------------------------------------------------------
248 
254 class PCL_CLASS Daubechies12Filter : public WaveletFilter
255 {
256 public:
257 
262 
265  String Name() const override
266  {
267  return "Daubechies-12";
268  }
269 };
270 
271 extern PCL_DATA Daubechies12Filter Daubechies12;
272 
273 // ----------------------------------------------------------------------------
274 
280 class PCL_CLASS Daubechies20Filter : public WaveletFilter
281 {
282 public:
283 
288 
291  String Name() const override
292  {
293  return "Daubechies-20";
294  }
295 };
296 
297 extern PCL_DATA Daubechies20Filter Daubechies20;
298 
299 // ----------------------------------------------------------------------------
300 
318 {
319 public:
320 
328  PyramidalWaveletTransform() = default;
329 
335  m_scalingFunction( &f )
336  {
337  PCL_CHECK( m_scalingFunction != nullptr )
338  }
339 
344 
349 
355  {
356  }
357 
361  PyramidalWaveletTransform& operator =( const PyramidalWaveletTransform& ) = default;
362 
366  PyramidalWaveletTransform& operator =( PyramidalWaveletTransform&& ) = default;
367 
373  {
374  PCL_PRECONDITION( m_scalingFunction != nullptr )
375  return *m_scalingFunction;
376  }
377 
383  {
384  Clear();
385  m_scalingFunction = &f;
386  PCL_CHECK( m_scalingFunction != nullptr )
387  }
388 
393  bool IsStandard() const
394  {
395  return !m_nonstandard;
396  }
397 
405  bool IsNonstandard() const
406  {
407  return m_nonstandard;
408  }
409 
417  void SetStandard( bool b = true )
418  {
419  Clear();
420  m_nonstandard = !b;
421  }
422 
432  void SetNonstandard( bool b = true )
433  {
434  Clear();
435  m_nonstandard = b;
436  }
437 
445  const Image& Transform() const
446  {
447  return m_transform;
448  }
449 
458  {
459  return m_transform;
460  }
461 
465  void Clear()
466  {
467  m_transform.FreeData();
468  }
469 
470 protected:
471 
472  /*
473  * Scaling function, or wavelet filter.
474  */
475  const WaveletFilter* m_scalingFunction = nullptr;
476 
477  /*
478  * Flag true if nonstandard transforms are being used.
479  * Standard transforms are used otherwise (and by default).
480  */
481  bool m_nonstandard = true;
482 
483  /*
484  * Wavelet transform
485  */
486  pcl::Image m_transform;
487 
488  void Validate() const;
489  void DoTransform( StatusMonitor& );
490 
491  // Transform (decomposition)
492  void Transform( const pcl::Image& ) override;
493  void Transform( const pcl::DImage& ) override;
494  void Transform( const pcl::ComplexImage& ) override;
495  void Transform( const pcl::DComplexImage& ) override;
496  void Transform( const pcl::UInt8Image& ) override;
497  void Transform( const pcl::UInt16Image& ) override;
498  void Transform( const pcl::UInt32Image& ) override;
499 
500  // Inverse transform (reconstruction)
501  void Apply( pcl::Image& ) const override;
502  void Apply( pcl::DImage& ) const override;
503  void Apply( pcl::ComplexImage& ) const override;
504  void Apply( pcl::DComplexImage& ) const override;
505  void Apply( pcl::UInt8Image& ) const override;
506  void Apply( pcl::UInt16Image& ) const override;
507  void Apply( pcl::UInt32Image& ) const override;
508 };
509 
510 // ----------------------------------------------------------------------------
511 
512 } // pcl
513 
514 #endif // __PCL_PyramidalWaveletTransform_h
515 
516 // ----------------------------------------------------------------------------
517 // EOF pcl/PyramidalWaveletTransform.h - Released 2019-11-07T10:59:34Z
String Name() const override
Daubechies-4 wavelet filter.
Root base class for bidirectional PCL image transformations.
PCL root namespace.
Definition: AbstractImage.h:76
String Name() const override
16-bit unsigned integer image.
PyramidalWaveletTransform(const WaveletFilter &f)
size_t size_type
Definition: Defs.h:543
32-bit floating point complex image.
String Name() const override
Discrete two-dimensional wavelet transforms by the pyramidal algorithms.
void Apply(FI i, FI j, F f)
Definition: Utility.h:249
Unicode (UTF-16) string.
Definition: String.h:7911
Daubechies-10 wavelet filter.
String Name() const override
64-bit floating point real image.
32-bit unsigned integer image.
An asynchronous status monitoring system.
Daubechies-6 wavelet filter.
8-bit unsigned integer image.
void SetScalingFunction(const WaveletFilter &f)
64-bit floating point real vector.
String Name(int colorSpace)
String Name() const override
64-bit floating point complex image.
Daubechies-8 wavelet filter.
Daubechies-12 wavelet filter.
Daubechies-20 wavelet filter.
const WaveletFilter & ScalingFunction() const
Abstract base class of all orthogonal wavelet filters.
32-bit floating point real image.
String Name() const override