PCL
LocalNormalizationData.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/LocalNormalizationData.h - Released 2024-01-13T15:47:58Z
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 
148  LocalNormalizationData() = default;
149 
154 
159 
179  LocalNormalizationData( const String& filePath, bool ignoreNormalizationData = false )
180  {
181  Parse( filePath, ignoreNormalizationData );
182  }
183 
203  LocalNormalizationData( const XMLDocument& xml, bool ignoreNormalizationData = false )
204  {
205  Parse( xml, ignoreNormalizationData );
206  }
207 
227  LocalNormalizationData( const XMLElement& element, bool ignoreNormalizationData = false )
228  {
229  Parse( element, ignoreNormalizationData );
230  }
231 
236  {
237  }
238 
246  const String& ReferenceFilePath() const
247  {
248  return m_referenceFilePath;
249  }
250 
257  void SetReferenceFilePath( const String& filePath )
258  {
259  m_referenceFilePath = File::FullPath( filePath );
260  }
261 
276  const String& TargetFilePath() const
277  {
278  return m_targetFilePath;
279  }
280 
287  void SetTargetFilePath( const String& filePath )
288  {
289  m_targetFilePath = File::FullPath( filePath );
290  }
291 
300  int NormalizationScale() const
301  {
302  return m_scale;
303  }
304 
311  void SetNormalizationScale( int scale )
312  {
313  m_scale = scale;
314  }
315 
322  int ReferenceWidth() const
323  {
324  return m_referenceWidth;
325  }
326 
333  int ReferenceHeight() const
334  {
335  return m_referenceHeight;
336  }
337 
344  void SetReferenceDimensions( int width, int height )
345  {
346  m_referenceWidth = width;
347  m_referenceHeight = height;
348  }
349 
355  int NumberOfChannels() const
356  {
357  return m_A.NumberOfChannels();
358  }
359 
370  {
371  return m_B;
372  }
373 
384  {
385  return m_A;
386  }
387 
398  const Vector& Bias() const
399  {
400  return m_C;
401  }
402 
425  {
426  if ( A.Bounds() != B.Bounds() )
427  throw Error( "LocalNormalizationData::SetLocalNormalizationParameters(): Incompatible matrix dimensions." );
428  if ( A.NumberOfChannels() != B.NumberOfChannels() )
429  throw Error( "LocalNormalizationData::SetLocalNormalizationParameters(): Incompatible number of normalization matrices." );
430  m_A = A;
431  m_B = B;
432  if ( !C.IsEmpty() )
433  {
434  if ( C.Length() != A.NumberOfChannels() )
435  throw Error( "LocalNormalizationData::SetLocalNormalizationParameters(): Incompatible bias vector length." );
436  m_C = C;
437  }
438  }
439 
448  {
449  return m_Rc;
450  }
451 
460  {
461  return m_Rc;
462  }
463 
471  {
472  return m_S;
473  }
474 
496  void SetGlobalNormalizationParameters( const Vector& Rc, const Vector& Tc, const Vector& S )
497  {
498  if ( m_B.IsEmpty() )
499  throw Error( "LocalNormalizationData::SetGlobalNormalizationParameters(): No zero offset coefficient matrix has been defined." );
500  if ( Rc.Length() != m_B.NumberOfChannels() || Tc.Length() != m_B.NumberOfChannels() || S.Length() != m_B.NumberOfChannels() )
501  throw Error( "LocalNormalizationData::SetGlobalNormalizationParameters(): Incompatible vector lengths." );
502  m_Rc = Rc;
503  m_Tc = Tc;
504  m_S = S;
505  }
506 
511  {
512  return m_relScale;
513  }
514 
527  {
528  if ( m_B.IsEmpty() )
529  throw Error( "LocalNormalizationData::SetRelativeScaleFactors(): No zero offset coefficient matrix has been defined." );
530  if ( s.Length() != m_B.NumberOfChannels() )
531  throw Error( "LocalNormalizationData::SetRelativeScaleFactors(): Incompatible vector lengths." );
532  m_relScale = s;
533  }
534 
553  void InitInterpolations();
554 
559  bool HasInterpolations() const
560  {
561  return !m_UA.IsEmpty() && !m_UB.IsEmpty();
562  }
563 
587  double operator()( double z, int x, int y, int c = 0 ) const
588  {
589  double sx = m_sx*x;
590  double sy = m_sy*y;
591  if ( likely( m_S.IsEmpty() ) )
592  return m_UA[c]( sx, sy )*(z - m_C[c]) + m_UB[c]( sx, sy );
593  return (m_UA[c]( sx, sy )*(z - m_C[c]) + m_UB[c]( sx, sy ) - m_Tc[c])*m_S[c] + m_Rc[c];
594  }
595 
601  {
602  return m_creationTime;
603  }
604 
609  void Clear();
610 
631  void Parse( const String& filePath, bool ignoreNormalizationData = false );
632 
654  void Parse( const XMLDocument& xml, bool ignoreNormalizationData = false );
655 
677  void Parse( const XMLElement& element, bool ignoreNormalizationData = false );
678 
689  bool IsCompressionEnabled() const
690  {
691  return m_compressionEnabled;
692  }
693 
699  void EnableCompression( bool enable = true )
700  {
701  m_compressionEnabled = enable;
702  }
703 
709  void DisableCompression( bool disable = true )
710  {
711  EnableCompression( !disable );
712  }
713 
728  int Version() const
729  {
730  return m_version;
731  }
732 
737  void SetVersion( int version )
738  {
739  m_version = version;
740  }
741 
747  bool IsTaggedAsInvalid() const
748  {
749  return m_invalid;
750  }
751 
756  {
757  m_invalid = true;
758  }
759 
767  XMLDocument* Serialize() const;
768 
777  void SerializeToFile( const String& path ) const;
778 
779 private:
780 
781  String m_referenceFilePath; // path to the normalization reference image
782  String m_targetFilePath; // path to the normalization target image
783  int m_scale = -1; // normalization scale in px
784  int m_referenceWidth = -1; // reference image width in px
785  int m_referenceHeight = -1; // reference image height in px
786  normalization_matrices m_A; // scaling coefficients
787  normalization_matrices m_B; // zero offset coefficients
788  Vector m_C; // input bias
789  matrix_interpolations m_UA; // interpolators for m_A
790  matrix_interpolations m_UB; // interpolators for m_B
791  Vector m_Rc; // global normalization, reference center
792  Vector m_Tc; // global normalization, target center
793  Vector m_S; // global normalization, scale factor
794  Vector m_relScale; // relative scale factor
795  double m_sx; // coordinate scaling factor, X axis
796  double m_sy; // coordinate scaling factor, Y axis
797  TimePoint m_creationTime;
798  bool m_compressionEnabled = true;
799  int m_version = 0;
800  bool m_invalid = false;
801 
802  void ParseNormalizationMatrices( normalization_matrices&, const XMLElement& ) const;
803  void SerializeNormalizationMatrices( XMLElement*, const normalization_matrices& ) const;
804 };
805 
806 // ----------------------------------------------------------------------------
807 
808 } // pcl
809 
810 #endif // __PCL_LocalNormalizationData_h
811 
812 // ----------------------------------------------------------------------------
813 // EOF pcl/LocalNormalizationData.h - Released 2024-01-13T15:47:58Z
pcl::LocalNormalizationData::GlobalScalingFactors
const Vector & GlobalScalingFactors() const
Definition: LocalNormalizationData.h:470
pcl::LocalNormalizationData::SetLocalNormalizationParameters
void SetLocalNormalizationParameters(const normalization_matrices &A, const normalization_matrices &B, const Vector &C=Vector())
Definition: LocalNormalizationData.h:424
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::LocalNormalizationData::Bias
const Vector & Bias() const
Definition: LocalNormalizationData.h:398
BicubicInterpolation.h
TimePoint.h
pcl::LocalNormalizationData::SetReferenceDimensions
void SetReferenceDimensions(int width, int height)
Definition: LocalNormalizationData.h:344
pcl::String
Unicode (UTF-16) string.
Definition: String.h:8112
pcl::LocalNormalizationData::Scale
const normalization_matrices & Scale() const
Definition: LocalNormalizationData.h:383
pcl::XMLDocument
XML document parsing and generation
Definition: XML.h:2640
pcl::LocalNormalizationData::IsCompressionEnabled
bool IsCompressionEnabled() const
Definition: LocalNormalizationData.h:689
pcl::LocalNormalizationData::CreationTime
TimePoint CreationTime() const
Definition: LocalNormalizationData.h:600
pcl::LocalNormalizationData::ZeroOffset
const normalization_matrices & ZeroOffset() const
Definition: LocalNormalizationData.h:369
pcl::LocalNormalizationData::IsTaggedAsInvalid
bool IsTaggedAsInvalid() const
Definition: LocalNormalizationData.h:747
pcl::LocalNormalizationData::ReferenceHeight
int ReferenceHeight() const
Definition: LocalNormalizationData.h:333
pcl::LocalNormalizationData::~LocalNormalizationData
virtual ~LocalNormalizationData()
Definition: LocalNormalizationData.h:235
pcl::LocalNormalizationData::SetGlobalNormalizationParameters
void SetGlobalNormalizationParameters(const Vector &Rc, const Vector &Tc, const Vector &S)
Definition: LocalNormalizationData.h:496
pcl::LocalNormalizationData
Normalization data parser and generator.
Definition: LocalNormalizationData.h:120
pcl::GenericImage::sample
typename pixel_traits::sample sample
Definition: Image.h:305
pcl::LocalNormalizationData::NormalizationScale
int NormalizationScale() const
Definition: LocalNormalizationData.h:300
pcl::Error
A simple exception with an associated error message.
Definition: Exception.h:238
pcl::TimePoint
An instant in any timescale.
Definition: TimePoint.h:102
pcl::Array< matrix_interpolation >
pcl::LocalNormalizationData::SetReferenceFilePath
void SetReferenceFilePath(const String &filePath)
Definition: LocalNormalizationData.h:257
Image.h
pcl::LocalNormalizationData::SetTargetFilePath
void SetTargetFilePath(const String &filePath)
Definition: LocalNormalizationData.h:287
pcl::LocalNormalizationData::SetNormalizationScale
void SetNormalizationScale(int scale)
Definition: LocalNormalizationData.h:311
pcl::LocalNormalizationData::ReferenceWidth
int ReferenceWidth() const
Definition: LocalNormalizationData.h:322
pcl::LocalNormalizationData::ReferenceFilePath
const String & ReferenceFilePath() const
Definition: LocalNormalizationData.h:246
pcl::LocalNormalizationData::NumberOfChannels
int NumberOfChannels() const
Definition: LocalNormalizationData.h:355
pcl::LocalNormalizationData::HasInterpolations
bool HasInterpolations() const
Definition: LocalNormalizationData.h:559
pcl::File::FullPath
static String FullPath(const String &path)
pcl::LocalNormalizationData::LocalNormalizationData
LocalNormalizationData(const String &filePath, bool ignoreNormalizationData=false)
Definition: LocalNormalizationData.h:179
pcl::LocalNormalizationData::TagAsInvalid
void TagAsInvalid()
Definition: LocalNormalizationData.h:755
pcl::LocalNormalizationData::normalization_coefficient
normalization_matrices::sample normalization_coefficient
Definition: LocalNormalizationData.h:132
pcl::XMLElement
XML element
Definition: XML.h:1161
pcl::LocalNormalizationData::EnableCompression
void EnableCompression(bool enable=true)
Definition: LocalNormalizationData.h:699
pcl::GenericVector::Length
int Length() const noexcept
Definition: Vector.h:1784
pcl::LocalNormalizationData::SetRelativeScaleFactors
void SetRelativeScaleFactors(const Vector &s)
Definition: LocalNormalizationData.h:526
pcl::LocalNormalizationData::Version
int Version() const
Definition: LocalNormalizationData.h:728
pcl::LocalNormalizationData::SetVersion
void SetVersion(int version)
Definition: LocalNormalizationData.h:737
pcl::LocalNormalizationData::TargetFilePath
const String & TargetFilePath() const
Definition: LocalNormalizationData.h:276
pcl::LocalNormalizationData::GlobalTargetLocation
const Vector & GlobalTargetLocation() const
Definition: LocalNormalizationData.h:459
Defs.h
pcl::LocalNormalizationData::LocalNormalizationData
LocalNormalizationData(const XMLDocument &xml, bool ignoreNormalizationData=false)
Definition: LocalNormalizationData.h:203
pcl::LocalNormalizationData::operator()
double operator()(double z, int x, int y, int c=0) const
Definition: LocalNormalizationData.h:587
pcl::GenericVector< double >
File.h
pcl::BicubicBSplineInterpolation
Bicubic B-Spline Interpolation Algorithm.
Definition: BicubicInterpolation.h:677
pcl::LocalNormalizationData::LocalNormalizationData
LocalNormalizationData(const XMLElement &element, bool ignoreNormalizationData=false)
Definition: LocalNormalizationData.h:227
pcl::LocalNormalizationData::GlobalReferenceLocation
const Vector & GlobalReferenceLocation() const
Definition: LocalNormalizationData.h:447
pcl::LocalNormalizationData::DisableCompression
void DisableCompression(bool disable=true)
Definition: LocalNormalizationData.h:709
pcl::GenericImage
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:277
pcl::LocalNormalizationData::RelativeScaleFactors
const Vector & RelativeScaleFactors() const
Definition: LocalNormalizationData.h:510