PCL
RedundantMultiscaleTransform.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/RedundantMultiscaleTransform.h - Released 2024-05-07T15:27:32Z
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-2024 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 (https://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_RedundantMultiscaleTransform_h
53 #define __PCL_RedundantMultiscaleTransform_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
61 #include <pcl/ParallelProcess.h>
62 #include <pcl/Vector.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
103  public ParallelProcess
104 {
105 public:
106 
110  using layer = Image;
111 
116 
121 
146  RedundantMultiscaleTransform( int n = 4, int d = 0 )
147  : m_delta( Max( 0, d ) )
148  , m_numberOfLayers( Max( 1, n ) )
149  {
150  PCL_PRECONDITION( n >= 1 )
151  PCL_PRECONDITION( d >= 0 )
152  InitializeLayersAndStates();
153  }
154 
160  , ParallelProcess( x )
161  , m_delta( x.m_delta )
162  , m_numberOfLayers( x.m_numberOfLayers )
163  , m_transform( x.m_transform )
164  , m_layerEnabled( x.m_layerEnabled )
165  {
166  m_transform.EnsureUnique();
167  }
168 
173 
179  {
180  }
181 
186  {
187  (void)BidirectionalImageTransformation::operator =( x );
188  (void)ParallelProcess::operator =( x );
189  m_delta = x.m_delta;
190  m_numberOfLayers = x.m_numberOfLayers;
191  m_transform = x.m_transform;
192  m_transform.EnsureUnique();
193  m_layerEnabled = x.m_layerEnabled;
194  return *this;
195  }
196 
201 
215  int ScalingSequence() const
216  {
217  return m_delta;
218  }
219 
229  void SetScalingSequence( int d )
230  {
231  PCL_PRECONDITION( d >= 0 )
232  DestroyLayers();
233  m_delta = Max( 0, d );
234  }
235 
246  {
247  SetScalingSequence( 0 );
248  }
249 
259  void SetLinearScalingSequence( int d = 1 )
260  {
261  PCL_PRECONDITION( d >= 1 )
262  SetScalingSequence( Max( 1, d ) );
263  }
264 
271  int FilterSize( int j ) const
272  {
273  return 1 + (((m_delta < 1) ? 1 << j : (1 + j)*m_delta) << 1);
274  }
275 
285  int NumberOfLayers() const
286  {
287  return m_numberOfLayers;
288  }
289 
300  void SetNumberOfLayers( int n )
301  {
302  PCL_PRECONDITION( n >= 1 )
303  m_numberOfLayers = Max( 1, n );
304  InitializeLayersAndStates();
305  }
306 
318  const layer& Layer( int i ) const
319  {
320  ValidateLayerAccess( i );
321  return m_transform[i];
322  }
323 
330  layer& Layer( int i )
331  {
332  ValidateLayerAccess( i );
333  return m_transform[i];
334  }
335 
345  const layer& operator []( int i ) const
346  {
347  return Layer( i );
348  }
349 
359  layer& operator []( int i )
360  {
361  return Layer( i );
362  }
363 
376  void DeleteLayer( int i )
377  {
378  ValidateLayerAccess( i );
379  m_transform[i].FreeData();
380  }
381 
388  bool IsLayer( int i ) const
389  {
390  ValidateLayerIndex( i );
391  return !m_transform[i].IsEmpty();
392  }
393 
411  void EnableLayer( int i, bool enable = true )
412  {
413  ValidateLayerIndex( i );
414  m_layerEnabled[i] = enable;
415  }
416 
425  void DisableLayer( int i, bool disable = true )
426  {
427  EnableLayer( i, !disable );
428  }
429 
435  bool IsLayerEnabled( int i ) const
436  {
437  ValidateLayerIndex( i );
438  return m_layerEnabled[i];
439  }
440 
477  void BiasLayer( int i, float k )
478  {
479  ValidateLayerAccess( i );
480  if ( k != 0 )
481  m_transform[i] *= (k > 0) ? (1 + k) : 1/(1 - k);
482  }
483 
497  {
498  transform r = m_transform;
499  DestroyLayers();
500  return r;
501  }
502 
507  virtual void Reset()
508  {
509  InitializeLayersAndStates();
510  }
511 
512 protected:
513 
514  /*
515  * delta >= 1 :
516  * Linear scaling sequence. delta is the constant scale difference
517  * between two consecutive layers.
518  *
519  * delta < 1 :
520  * Dyadic scaling sequence (1, 2, 4, 8, 16, ...).
521  */
522  int m_delta = 0;
523 
524  /*
525  * Number of detail layers, *not including* the residual smoothed layer,
526  * which is always generated in a multiscale transform.
527  */
528  int m_numberOfLayers = 4;
529 
530  /*
531  * Array of transform layers, including the residual layer, so the length
532  * of this array is numberOfLayers+1.
533  */
534  transform m_transform;
535 
536  /*
537  * Vector of layer enable/disable states.
538  */
539  layer_state_set m_layerEnabled;
540 
541  /*
542  * Inverse transform (reconstruction)
543  */
544  void Apply( pcl::Image& ) const override;
545  void Apply( pcl::DImage& ) const override;
546  void Apply( pcl::ComplexImage& ) const override;
547  void Apply( pcl::DComplexImage& ) const override;
548  void Apply( pcl::UInt8Image& ) const override;
549  void Apply( pcl::UInt16Image& ) const override;
550  void Apply( pcl::UInt32Image& ) const override;
551 
552  void InitializeLayersAndStates()
553  {
554  DestroyLayers();
555  m_layerEnabled = layer_state_set( true, m_numberOfLayers+1 );
556  }
557 
558  void DestroyLayers()
559  {
560  m_transform = transform( size_type( m_numberOfLayers+1 ) );
561  }
562 
563  void ValidateLayerIndex( int j ) const;
564  void ValidateLayerAccess( int j ) const;
565 
566  friend class MTReconstruction;
567 };
568 
569 // ----------------------------------------------------------------------------
570 
571 } // pcl
572 
573 #endif // __PCL_RedundantMultiscaleTransform_h
574 
575 // ----------------------------------------------------------------------------
576 // EOF pcl/RedundantMultiscaleTransform.h - Released 2024-05-07T15:27:32Z
void EnsureUnique()
Definition: Array.h:242
Root base class for bidirectional PCL image transformations.
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
A process using multiple concurrent execution threads.
Base class of all redundant multiscale transforms.
void Apply(pcl::Image &) const override
RedundantMultiscaleTransform(const RedundantMultiscaleTransform &x)
void Apply(pcl::DImage &) const override
void Apply(pcl::DComplexImage &) const override
void Apply(pcl::UInt16Image &) const override
RedundantMultiscaleTransform(RedundantMultiscaleTransform &&)=default
void Apply(pcl::UInt32Image &) const override
void DisableLayer(int i, bool disable=true)
void Apply(pcl::UInt8Image &) const override
void Apply(pcl::ComplexImage &) const override
size_t size_type
Definition: Defs.h:609
constexpr const T & Max(const T &a, const T &b) noexcept
Definition: Utility.h:119
PCL root namespace.
Definition: AbstractImage.h:77