PCL
PSFScaleEstimator.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/PSFScaleEstimator.h - Released 2024-06-18T15:48:54Z
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_PSFScaleEstimator_h
53 #define __PCL_PSFScaleEstimator_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/PSFEstimator.h>
60 #include <pcl/SurfaceSpline.h>
61 
62 namespace pcl
63 {
64 
65 // ----------------------------------------------------------------------------
66 
72 class PCL_CLASS PSFScaleEstimator : public PSFEstimator
73 {
74 public:
75 
79  using psf_function = PSFEstimator::psf_function;
80 
82 
87  struct Estimates
88  {
89  double scale = 1;
90  double sigma = 0;
91  int total = 0;
92  int count = 0;
94 
98  operator double() const
99  {
100  return scale;
101  }
102 
106  bool IsValid() const
107  {
108  return count > 0 && 1 + scale != 1;
109  }
110  };
111 
115  PSFScaleEstimator() = default;
116 
121 
126  {
127  }
128 
132  PSFScaleEstimator& operator =( const PSFScaleEstimator& ) = default;
133 
153  float PSFSearchTolerance() const
154  {
155  return m_psfSearchTolerance;
156  }
157 
162  void SetPSFSearchTolerance( float t )
163  {
164  PCL_PRECONDITION( t >= 0 )
165  m_psfSearchTolerance = Max( 0.0F, t );
166  }
167 
181  float RejectionLimit() const
182  {
183  return m_rejectionLimit;
184  }
185 
190  void SetRejectionLimit( float r )
191  {
192  PCL_PRECONDITION( r > 0 && r < 1 )
193  m_rejectionLimit = Range( r, 0.0F, 1.0F );
194  }
195 
207  int SetReference( const ImageVariant& image );
208 
217  bool IsLocalModelEnabled() const
218  {
219  return m_enableLocalModel;
220  }
221 
225  void EnableLocalModel( bool enable = true )
226  {
227  m_enableLocalModel = enable;
228  }
229 
233  void DisableLocalModel( bool disable = true )
234  {
235  EnableLocalModel( !disable );
236  }
237 
254  Estimates EstimateScale( const ImageVariant& image ) const;
255 
265  Estimates operator()( const ImageVariant& image ) const
266  {
267  return EstimateScale( image );
268  }
269 
270 private:
271 
272  Array<PSFData> m_psfReference;
273  float m_psfSearchTolerance = 4.0F; // px
274  float m_rejectionLimit = 0.3F;
275  bool m_enableLocalModel = false;
276 
277  /*
278  * Auxiliary structure for generation of first-order local scale models.
279  */
280  struct Sample
281  {
282  double x, y, z;
283 
284  operator double() const
285  {
286  return z;
287  }
288 
289  bool operator <( const Sample& s ) const
290  {
291  return z < s.z;
292  }
293  };
294 
295  using sample_vector = GenericVector<Sample>;
296 };
297 
298 // ----------------------------------------------------------------------------
299 
300 } // pcl
301 
302 #endif // __PCL_PSFScaleEstimator_h
303 
304 // ----------------------------------------------------------------------------
305 // EOF pcl/PSFScaleEstimator.h - Released 2024-06-18T15:48:54Z
Generic dynamic array.
Definition: Array.h:100
Acts like a union for all types of images in PCL, with optional class-wide ownership of transported i...
Definition: ImageVariant.h:322
Base class of estimators based on PSF photometry.
Definition: PSFEstimator.h:73
StarDetector::psf_function psf_function
Definition: PSFEstimator.h:79
Estimation of relative image scale based on PSF photometry.
Estimates operator()(const ImageVariant &image) const
Estimates EstimateScale(const ImageVariant &image) const
int SetReference(const ImageVariant &image)
void SetRejectionLimit(float r)
void EnableLocalModel(bool enable=true)
void SetPSFSearchTolerance(float t)
float PSFSearchTolerance() const
bool IsLocalModelEnabled() const
PSFScaleEstimator(const PSFScaleEstimator &)=default
void DisableLocalModel(bool disable=true)
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2278
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
Definition: Utility.h:190
constexpr const T & Max(const T &a, const T &b) noexcept
Definition: Utility.h:119
PCL root namespace.
Definition: AbstractImage.h:77
Structure to hold a PSF relative scale estimate.
local_model local
2-D model of local scale variations.