PCL
ImageStatistics.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/ImageStatistics.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_ImageStatistics_h
53 #define __PCL_ImageStatistics_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/ImageVariant.h>
60 #include <pcl/ParallelProcess.h>
61 
62 namespace pcl
63 {
64 
65 // ----------------------------------------------------------------------------
66 
116 class PCL_CLASS ImageStatistics : public ParallelProcess
117 {
118 public:
119 
124  struct PCL_CLASS Data
125  {
126  size_type count = 0;
127  double mean = 0;
128  double sumOfSquares = 0;
129  double median = 0;
130  double variance = 0;
131  double stdDev = 0;
132  double avgDev = 0;
133  double MAD = 0;
134  double bwmv = 0;
135  double pbmv = 0;
136  double Sn = 0;
137  double Qn = 0;
138  double minimum = 0;
139  Point minPos = Point( 0 );
140  double maximum = 0;
141  Point maxPos = Point( 0 );
142  double low = 0;
143  double high = 0;
144  bool rejectLow = false;
145  bool rejectHigh = false;
146  bool noExtremes = false;
147  bool noMean = false;
148  bool noSumOfSquares = false;
149  bool noVariance = false;
150  bool noMedian = false;
151  bool noAvgDev = false;
152  bool noMAD = false;
153  bool noBWMV = false;
154  bool noPBMV = false;
155  bool noSn = true;
156  bool noQn = true;
157 
161  Data() = default;
162 
166  Data( const Data& ) = default;
167 
171  Data& operator =( const Data& ) = default;
172 
176  void Assign( const Data& x )
177  {
178  (void)operator =( x );
179  }
180 
185  void AssignStatisticalData( const Data& x )
186  {
187  count = x.count;
188  mean = x.mean;
189  sumOfSquares = x.sumOfSquares;
190  median = x.median;
191  variance = x.variance;
192  stdDev = x.stdDev;
193  avgDev = x.avgDev;
194  MAD = x.MAD;
195  bwmv = x.bwmv;
196  pbmv = x.pbmv;
197  Sn = x.Sn;
198  Qn = x.Qn;
199  minimum = x.minimum;
200  minPos = x.minPos;
201  maximum = x.maximum;
202  maxPos = x.maxPos;
203  }
204  };
205 
206  // -------------------------------------------------------------------------
207 
211  ImageStatistics() = default;
212 
216  ImageStatistics( const ImageStatistics& ) = default;
217 
221  ~ImageStatistics() override
222  {
223  }
224 
228  ImageStatistics& operator =( const ImageStatistics& ) = default;
229 
233  void Assign( const ImageStatistics& x )
234  {
235  (void)operator =( x );
236  }
237 
241  const Data& GetData() const
242  {
243  return m_data;
244  }
245 
249  size_type Count() const
250  {
251  return m_data.count;
252  }
253 
258  double Mean() const
259  {
260  return m_data.mean;
261  }
262 
267  double SumOfSquares() const
268  {
269  return m_data.sumOfSquares;
270  }
271 
276  double Median() const
277  {
278  return m_data.median;
279  }
280 
285  double Variance() const
286  {
287  return m_data.variance;
288  }
289 
296  double Var() const
297  {
298  return Variance();
299  }
300 
305  double StandardDeviation() const
306  {
307  return m_data.stdDev;
308  }
309 
316  double StdDev() const
317  {
318  return StandardDeviation();
319  }
320 
330  double AverageDeviation() const
331  {
332  return m_data.avgDev;
333  }
334 
341  double AvgDev() const
342  {
343  return AverageDeviation();
344  }
345 
352  double MAD() const
353  {
354  return m_data.MAD;
355  }
356 
366  double BiweightMidvariance() const
367  {
368  return m_data.bwmv;
369  }
370 
377  double BWMV() const
378  {
379  return m_data.bwmv;
380  }
381 
390  double BendMidvariance() const
391  {
392  return m_data.pbmv;
393  }
394 
401  double PBMV() const
402  {
403  return m_data.pbmv;
404  }
405 
417  double Sn() const
418  {
419  return m_data.Sn;
420  }
421 
433  double Qn() const
434  {
435  return m_data.Qn;
436  }
437 
441  double Minimum() const
442  {
443  return m_data.minimum;
444  }
445 
451  double Min() const
452  {
453  return Minimum();
454  }
455 
461  {
462  return m_data.minPos;
463  }
464 
471  Point MinPos() const
472  {
473  return MinimumPosition();
474  }
475 
479  double Maximum() const
480  {
481  return m_data.maximum;
482  }
483 
489  double Max() const
490  {
491  return Maximum();
492  }
493 
499  {
500  return m_data.maxPos;
501  }
502 
509  Point MaxPos() const
510  {
511  return MaximumPosition();
512  }
513 
521  double RejectionLow() const
522  {
523  return m_data.low;
524  }
525 
533  double RejectionHigh() const
534  {
535  return m_data.high;
536  }
537 
544  void SetRejectionLimits( double low, double high )
545  {
546  m_data.low = Range( low, 0.0, 1.0 );
547  m_data.high = Range( high, 0.0, 1.0 );
548  if ( m_data.high < m_data.low )
549  pcl::Swap( m_data.low, m_data.high );
550  }
551 
561  {
562  return m_data.rejectLow;
563  }
564 
574  {
575  return m_data.rejectHigh;
576  }
577 
585  void EnableRejection( bool enableLow = true, bool enableHigh = true )
586  {
587  m_data.rejectLow = enableLow;
588  m_data.rejectHigh = enableHigh;
589  }
590 
597  void DisableRejection( bool disableLow = true, bool disableHigh = true )
598  {
599  EnableRejection( !disableLow, !disableHigh );
600  }
601 
606  bool IsExtremesEnabled() const
607  {
608  return !m_data.noExtremes;
609  }
610 
615  void EnableExtremes( bool enable = true )
616  {
617  m_data.noExtremes = !enable;
618  }
619 
624  void DisableExtremes( bool disable = true )
625  {
626  m_data.noExtremes = disable;
627  }
628 
636  bool IsMeanEnabled() const
637  {
638  return !m_data.noMean;
639  }
640 
648  void EnableMean( bool enable = true )
649  {
650  m_data.noMean = !enable;
651  }
652 
660  void DisableMean( bool disable = true )
661  {
662  m_data.noMean = disable;
663  }
664 
670  {
671  return !m_data.noSumOfSquares;
672  }
673 
677  void EnableSumOfSquares( bool enable = true )
678  {
679  m_data.noSumOfSquares = !enable;
680  }
681 
685  void DisableSumOfSquares( bool disable = true )
686  {
687  m_data.noSumOfSquares = disable;
688  }
689 
694  bool IsVarianceEnabled() const
695  {
696  return !m_data.noVariance;
697  }
698 
702  void EnableVariance( bool enable = true )
703  {
704  m_data.noVariance = !enable;
705  }
706 
710  void DisableVariance( bool disable = true )
711  {
712  m_data.noVariance = disable;
713  }
714 
722  bool IsMedianEnabled() const
723  {
724  return !m_data.noMedian;
725  }
726 
733  void EnableMedian( bool enable = true )
734  {
735  m_data.noMedian = !enable;
736  }
737 
744  void DisableMedian( bool disable = true )
745  {
746  m_data.noMedian = disable;
747  }
748 
753  bool IsAvgDevEnabled() const
754  {
755  return !m_data.noAvgDev;
756  }
757 
762  void EnableAvgDev( bool enable = true )
763  {
764  m_data.noAvgDev = !enable;
765  }
766 
771  void DisableAvgDev( bool disable = true )
772  {
773  m_data.noAvgDev = disable;
774  }
775 
783  bool IsMADEnabled() const
784  {
785  return !m_data.noMAD;
786  }
787 
795  void EnableMAD( bool enable = true )
796  {
797  m_data.noMAD = !enable;
798  }
799 
807  void DisableMAD( bool disable = true )
808  {
809  m_data.noMAD = disable;
810  }
811 
816  bool IsBWMVEnabled() const
817  {
818  return !m_data.noBWMV;
819  }
820 
825  void EnableBWMV( bool enable = true )
826  {
827  m_data.noBWMV = !enable;
828  }
829 
834  void DisableBWMV( bool disable = true )
835  {
836  m_data.noBWMV = disable;
837  }
838 
843  bool IsPBMVEnabled() const
844  {
845  return !m_data.noPBMV;
846  }
847 
852  void EnablePBMV( bool enable = true )
853  {
854  m_data.noPBMV = !enable;
855  }
856 
861  void DisablePBMV( bool disable = true )
862  {
863  m_data.noPBMV = disable;
864  }
865 
872  bool IsSnEnabled() const
873  {
874  return !m_data.noSn;
875  }
876 
883  void EnableSn( bool enable = true )
884  {
885  m_data.noSn = !enable;
886  }
887 
894  void DisableSn( bool disable = true )
895  {
896  m_data.noSn = disable;
897  }
898 
905  bool IsQnEnabled() const
906  {
907  return !m_data.noQn;
908  }
909 
916  void EnableQn( bool enable = true )
917  {
918  m_data.noQn = !enable;
919  }
920 
927  void DisableQn( bool disable = true )
928  {
929  m_data.noQn = disable;
930  }
931 
936  const Image& operator <<( const Image& image );
937 
942  const DImage& operator <<( const DImage& image );
943 
948  const UInt8Image& operator <<( const UInt8Image& image );
949 
954  const UInt16Image& operator <<( const UInt16Image& image );
955 
960  const UInt32Image& operator <<( const UInt32Image& image );
961 
966  const ImageVariant& operator <<( const ImageVariant& image )
967  {
968  if ( image )
969  if ( !image.IsComplexSample() )
970  if ( image.IsFloatSample() )
971  switch ( image.BitsPerSample() )
972  {
973  case 32: *this << static_cast<const Image&>( *image ); break;
974  case 64: *this << static_cast<const DImage&>( *image ); break;
975  }
976  else
977  switch ( image.BitsPerSample() )
978  {
979  case 8: *this << static_cast<const UInt8Image&>( *image ); break;
980  case 16: *this << static_cast<const UInt16Image&>( *image ); break;
981  case 32: *this << static_cast<const UInt32Image&>( *image ); break;
982  }
983  return image;
984  }
985 
986 protected:
987 
988  Data m_data; // statistical data
989 
990  friend class View;
991 };
992 
993 // ----------------------------------------------------------------------------
994 
995 } // pcl
996 
997 #endif // __PCL_ImageStatistics_h
998 
999 // ----------------------------------------------------------------------------
1000 // EOF pcl/ImageStatistics.h - Released 2024-06-18T15:48:54Z
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
A generic point in the two-dimensional space.
Definition: Point.h:100
Descriptive image statistics.
void DisableQn(bool disable=true)
void EnableExtremes(bool enable=true)
double StdDev() const
ImageStatistics()=default
void EnableMean(bool enable=true)
Point MaximumPosition() const
bool IsPBMVEnabled() const
void DisableMAD(bool disable=true)
bool IsMADEnabled() const
void EnableMAD(bool enable=true)
bool IsMeanEnabled() const
void EnableQn(bool enable=true)
void DisableMean(bool disable=true)
void DisableVariance(bool disable=true)
Point MinimumPosition() const
bool IsHighRejectionEnabled() const
const Data & GetData() const
bool IsBWMVEnabled() const
void DisablePBMV(bool disable=true)
void EnableMedian(bool enable=true)
void EnableSumOfSquares(bool enable=true)
size_type Count() const
bool IsLowRejectionEnabled() const
double Variance() const
void EnableSn(bool enable=true)
void DisableRejection(bool disableLow=true, bool disableHigh=true)
bool IsQnEnabled() const
bool IsMedianEnabled() const
bool IsSnEnabled() const
double SumOfSquares() const
double BendMidvariance() const
double AvgDev() const
void DisableSumOfSquares(bool disable=true)
bool IsAvgDevEnabled() const
void Assign(const ImageStatistics &x)
void DisableAvgDev(bool disable=true)
double RejectionLow() const
double AverageDeviation() const
double StandardDeviation() const
void EnableRejection(bool enableLow=true, bool enableHigh=true)
double BiweightMidvariance() const
void DisableBWMV(bool disable=true)
void DisableMedian(bool disable=true)
double Maximum() const
void EnableBWMV(bool enable=true)
bool IsSumOfSquaresEnabled() const
void SetRejectionLimits(double low, double high)
void EnableAvgDev(bool enable=true)
double RejectionHigh() const
void DisableExtremes(bool disable=true)
bool IsExtremesEnabled() const
double Minimum() const
void DisableSn(bool disable=true)
ImageStatistics(const ImageStatistics &)=default
void EnablePBMV(bool enable=true)
void EnableVariance(bool enable=true)
double Median() const
bool IsVarianceEnabled() const
Acts like a union for all types of images in PCL, with optional class-wide ownership of transported i...
Definition: ImageVariant.h:322
bool IsFloatSample() const noexcept
Definition: ImageVariant.h:441
bool IsComplexSample() const noexcept
Definition: ImageVariant.h:449
int BitsPerSample() const noexcept
Definition: ImageVariant.h:458
A process using multiple concurrent execution threads.
High-level interface to a PixInsight view object.
Definition: View.h:213
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
Definition: Array.h:2295
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
Definition: Point.h:1459
size_t size_type
Definition: Defs.h:609
double Qn(T *__restrict__ x, T *__restrict__ xn)
Definition: Math.h:4170
double MAD(const T *__restrict__ i, const T *__restrict__ j, double center)
Definition: Math.h:3776
double Variance(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:2753
double Sn(T *__restrict__ x, T *__restrict__ xn)
Definition: Math.h:3924
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
Definition: Utility.h:190
PCL root namespace.
Definition: AbstractImage.h:77
Statistical data in the normalized [0,1] range.
double maximum
Maximum sample value.
double mean
Arithmetic mean.
double avgDev
Average deviation from the median.
Point minPos
Position of the minimum sample value.
double Sn
Sn scale estimator of Rousseeuw and Croux.
double Qn
Qn scale estimator of Rousseeuw and Croux.
double bwmv
Biweight midvariance.
double MAD
Median absolute deviation from the median.
void Assign(const Data &x)
double stdDev
Standard deviation (=Sqrt(variance)).
size_type count
Total number of evaluated samples.
void AssignStatisticalData(const Data &x)
double pbmv
Percentage bend midvariance.
double minimum
Minimum sample value.
double median
Median sample value.
double sumOfSquares
Sum of squared samples.
Point maxPos
Position of the maximum sample value.
double variance
Variance from the mean.
Data(const Data &)=default