PCL
LocalNormalizationData.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.4
6 // ----------------------------------------------------------------------------
7 // pcl/LocalNormalizationData.h - Released 2024-12-23T11:32:56Z
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_LocalNormalizationData_h
53 #define __PCL_LocalNormalizationData_h
54 
56 
57 #include <pcl/Defs.h>
58 
60 #include <pcl/File.h>
61 #include <pcl/Image.h>
62 #include <pcl/TimePoint.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
69 class PCL_CLASS XMLDocument;
70 class PCL_CLASS XMLElement;
71 
120 class PCL_CLASS LocalNormalizationData
121 {
122 public:
123 
128 
133 
139 
144 
149 
154 
159 
163  LocalNormalizationData& operator =( const LocalNormalizationData& ) = default;
164 
168  LocalNormalizationData& operator =( LocalNormalizationData&& ) = default;
169 
189  LocalNormalizationData( const String& filePath, bool ignoreNormalizationData = false )
190  {
191  Parse( filePath, ignoreNormalizationData );
192  }
193 
213  LocalNormalizationData( const XMLDocument& xml, bool ignoreNormalizationData = false )
214  {
215  Parse( xml, ignoreNormalizationData );
216  }
217 
237  LocalNormalizationData( const XMLElement& element, bool ignoreNormalizationData = false )
238  {
239  Parse( element, ignoreNormalizationData );
240  }
241 
246  {
247  }
248 
256  const String& ReferenceFilePath() const
257  {
258  return m_referenceFilePath;
259  }
260 
267  void SetReferenceFilePath( const String& filePath )
268  {
269  m_referenceFilePath = File::FullPath( filePath );
270  }
271 
286  const String& TargetFilePath() const
287  {
288  return m_targetFilePath;
289  }
290 
297  void SetTargetFilePath( const String& filePath )
298  {
299  m_targetFilePath = File::FullPath( filePath );
300  }
301 
310  int NormalizationScale() const
311  {
312  return m_scale;
313  }
314 
321  void SetNormalizationScale( int scale )
322  {
323  m_scale = scale;
324  }
325 
332  int ReferenceWidth() const
333  {
334  return m_referenceWidth;
335  }
336 
343  int ReferenceHeight() const
344  {
345  return m_referenceHeight;
346  }
347 
354  void SetReferenceDimensions( int width, int height )
355  {
356  m_referenceWidth = width;
357  m_referenceHeight = height;
358  }
359 
365  int NumberOfChannels() const
366  {
367  return m_A.NumberOfChannels();
368  }
369 
380  {
381  return m_B;
382  }
383 
394  {
395  return m_A;
396  }
397 
408  const Vector& Bias() const
409  {
410  return m_C;
411  }
412 
435  {
436  if ( A.Bounds() != B.Bounds() )
437  throw Error( "LocalNormalizationData::SetLocalNormalizationParameters(): Incompatible matrix dimensions." );
438  if ( A.NumberOfChannels() != B.NumberOfChannels() )
439  throw Error( "LocalNormalizationData::SetLocalNormalizationParameters(): Incompatible number of normalization matrices." );
440  m_A = A;
441  m_B = B;
442  if ( !C.IsEmpty() )
443  {
444  if ( C.Length() != A.NumberOfChannels() )
445  throw Error( "LocalNormalizationData::SetLocalNormalizationParameters(): Incompatible bias vector length." );
446  m_C = C;
447  }
448  }
449 
458  {
459  return m_Rc;
460  }
461 
470  {
471  return m_Rc;
472  }
473 
481  {
482  return m_S;
483  }
484 
506  void SetGlobalNormalizationParameters( const Vector& Rc, const Vector& Tc, const Vector& S )
507  {
508  if ( m_B.IsEmpty() )
509  throw Error( "LocalNormalizationData::SetGlobalNormalizationParameters(): No zero offset coefficient matrix has been defined." );
510  if ( Rc.Length() != m_B.NumberOfChannels() || Tc.Length() != m_B.NumberOfChannels() || S.Length() != m_B.NumberOfChannels() )
511  throw Error( "LocalNormalizationData::SetGlobalNormalizationParameters(): Incompatible vector lengths." );
512  m_Rc = Rc;
513  m_Tc = Tc;
514  m_S = S;
515  }
516 
521  {
522  return m_relScale;
523  }
524 
537  {
538  if ( m_B.IsEmpty() )
539  throw Error( "LocalNormalizationData::SetRelativeScaleFactors(): No zero offset coefficient matrix has been defined." );
540  if ( s.Length() != m_B.NumberOfChannels() )
541  throw Error( "LocalNormalizationData::SetRelativeScaleFactors(): Incompatible vector lengths." );
542  m_relScale = s;
543  }
544 
564 
569  bool HasInterpolations() const
570  {
571  return !m_UA.IsEmpty() && !m_UB.IsEmpty();
572  }
573 
597  double operator()( double z, int x, int y, int c = 0 ) const
598  {
599  double sx = m_sx*x;
600  double sy = m_sy*y;
601  if ( likely( m_S.IsEmpty() ) )
602  return m_UA[c]( sx, sy )*(z - m_C[c]) + m_UB[c]( sx, sy );
603  return (m_UA[c]( sx, sy )*(z - m_C[c]) + m_UB[c]( sx, sy ) - m_Tc[c])*m_S[c] + m_Rc[c];
604  }
605 
611  {
612  return m_creationTime;
613  }
614 
619  void Clear();
620 
641  void Parse( const String& filePath, bool ignoreNormalizationData = false );
642 
664  void Parse( const XMLDocument& xml, bool ignoreNormalizationData = false );
665 
687  void Parse( const XMLElement& element, bool ignoreNormalizationData = false );
688 
699  bool IsCompressionEnabled() const
700  {
701  return m_compressionEnabled;
702  }
703 
709  void EnableCompression( bool enable = true )
710  {
711  m_compressionEnabled = enable;
712  }
713 
719  void DisableCompression( bool disable = true )
720  {
721  EnableCompression( !disable );
722  }
723 
738  int Version() const
739  {
740  return m_version;
741  }
742 
747  void SetVersion( int version )
748  {
749  m_version = version;
750  }
751 
757  bool IsTaggedAsInvalid() const
758  {
759  return m_invalid;
760  }
761 
766  {
767  m_invalid = true;
768  }
769 
778 
787  void SerializeToFile( const String& path ) const;
788 
789 private:
790 
791  String m_referenceFilePath; // path to the normalization reference image
792  String m_targetFilePath; // path to the normalization target image
793  int m_scale = -1; // normalization scale in px
794  int m_referenceWidth = -1; // reference image width in px
795  int m_referenceHeight = -1; // reference image height in px
796  normalization_matrices m_A; // scaling coefficients
797  normalization_matrices m_B; // zero offset coefficients
798  Vector m_C; // input bias
799  matrix_interpolations m_UA; // interpolators for m_A
800  matrix_interpolations m_UB; // interpolators for m_B
801  Vector m_Rc; // global normalization, reference center
802  Vector m_Tc; // global normalization, target center
803  Vector m_S; // global normalization, scale factor
804  Vector m_relScale; // relative scale factor
805  double m_sx; // coordinate scaling factor, X axis
806  double m_sy; // coordinate scaling factor, Y axis
807  TimePoint m_creationTime;
808  bool m_compressionEnabled = true;
809  int m_version = 0;
810  bool m_invalid = false;
811 
812  void ParseNormalizationMatrices( normalization_matrices&, const XMLElement& ) const;
813  void SerializeNormalizationMatrices( XMLElement*, const normalization_matrices& ) const;
814 };
815 
816 // ----------------------------------------------------------------------------
817 
818 } // pcl
819 
820 #endif // __PCL_LocalNormalizationData_h
821 
822 // ----------------------------------------------------------------------------
823 // EOF pcl/LocalNormalizationData.h - Released 2024-12-23T11:32:56Z
Bicubic B-Spline Interpolation Algorithm.
A simple exception with an associated error message.
Definition: Exception.h:239
static String FullPath(const String &path)
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
typename pixel_traits::sample sample
Definition: Image.h:305
Generic vector of arbitrary length.
Definition: Vector.h:107
int Length() const noexcept
Definition: Vector.h:1802
Normalization data parser and generator.
LocalNormalizationData(const LocalNormalizationData &)=default
void SetReferenceDimensions(int width, int height)
const normalization_matrices & ZeroOffset() const
void SetRelativeScaleFactors(const Vector &s)
void EnableCompression(bool enable=true)
void SetGlobalNormalizationParameters(const Vector &Rc, const Vector &Tc, const Vector &S)
XMLDocument * Serialize() const
void SetReferenceFilePath(const String &filePath)
LocalNormalizationData(const XMLElement &element, bool ignoreNormalizationData=false)
const Vector & RelativeScaleFactors() const
void SetTargetFilePath(const String &filePath)
void DisableCompression(bool disable=true)
const Vector & GlobalTargetLocation() const
void Parse(const XMLDocument &xml, bool ignoreNormalizationData=false)
void Parse(const XMLElement &element, bool ignoreNormalizationData=false)
void SetLocalNormalizationParameters(const normalization_matrices &A, const normalization_matrices &B, const Vector &C=Vector())
const String & ReferenceFilePath() const
const normalization_matrices & Scale() const
const String & TargetFilePath() const
const Vector & GlobalScalingFactors() const
LocalNormalizationData(const String &filePath, bool ignoreNormalizationData=false)
void Parse(const String &filePath, bool ignoreNormalizationData=false)
LocalNormalizationData(LocalNormalizationData &&)=default
double operator()(double z, int x, int y, int c=0) const
normalization_matrices::sample normalization_coefficient
const Vector & GlobalReferenceLocation() const
LocalNormalizationData(const XMLDocument &xml, bool ignoreNormalizationData=false)
void SerializeToFile(const String &path) const
Unicode (UTF-16) string.
Definition: String.h:8146
An instant in any timescale.
Definition: TimePoint.h:103
XML document parsing and generation
Definition: XML.h:2745
XML element
Definition: XML.h:1177
PCL root namespace.
Definition: AbstractImage.h:77