ImageStatistics.h

Go to the documentation of this file.
00001 //# ImageStatistics.h: generate statistics from an image
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef IMAGES_IMAGESTATISTICS_H
00029 #define IMAGES_IMAGESTATISTICS_H
00030 
00031 
00032 //# Includes
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/casa/BasicSL/String.h>
00035 #include <casacore/casa/Utilities/DataType.h>
00036 #include <casacore/casa/Logging/LogIO.h>
00037 #include <casacore/lattices/LatticeMath/LatticeStatistics.h>
00038 #include <casacore/scimath/Mathematics/NumericTraits.h>
00039 #include <casacore/casa/iosstrfwd.h>
00040 
00041 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00042 
00043 //# Forward Declarations
00044 template <class T> class ImageInterface;
00045 class IPosition;
00046 
00047 // <summary>
00048 // Displays various statistics from an image.
00049 // </summary>
00050 
00051 // <use visibility=export>
00052 
00053 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00054 // </reviewed>
00055 
00056 // <prerequisite>
00057 //   <li> <linkto class=LatticeStatistics>LatticeStatistics</linkto> (base class)
00058 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00059 // </prerequisite>
00060 
00061 // <etymology>
00062 // This is a class designed to display and retrieve statistics from images
00063 // </etymology>
00064 
00065 // <synopsis>
00066 // This class enable you to display and/or retrieve statistics evaluated over 
00067 // specified regions from an image.  The dimension of the region is arbitrary, but 
00068 // the size of each dimension is always the size of the corresponding image axis.
00069 // The statistics are displayed as a function of location of the axes not
00070 // used to evaluate the statistics over.  The axes which you evaluate the statistics
00071 // over are called the cursor axes, the others are called the display axes.
00072 //
00073 // This class is derived from the class LatticeStatistics which does all
00074 // the work.  This class only adds some extra capability in terms of
00075 // logging world (rather than pixel) coordinates and computing the
00076 // synthesized beam area, if there is one.  There are just a few virtual
00077 // functions for you to over-ride.  These are rather specialized, they
00078 // are not part of a general polymorphic interface, just a way to
00079 // separate the Lattice and Image functionality out.
00080 //
00081 // See LatticeStatistics for details and examples.
00082 // </synopsis>
00083 //
00084 // <motivation>
00085 // The generation of statistical information from an image is a basic 
00086 // and necessary capability.
00087 // </motivation>
00088 
00089 // <todo asof="1996/11/26">
00090 //   <li> Deal with complex images at least for statistics retrieval if not
00091 //        plotting.
00092 //   <li> Retrieve statistics at specified location of display axes
00093 //   <li> Standard errors on statistical quantities
00094 //   <li> Median, other more exotic statistics. Life made difficult by
00095 //        accumulation image approach
00096 // </todo>
00097 
00098 
00099 template <class T> class ImageStatistics : public LatticeStatistics<T>
00100 {
00101 public:
00102 
00103 // Constructor takes the image and a <src>LogIO</src> object for logging.
00104 // You can specify whether you want to see progress meters or not.
00105 // You can force the storage image to be disk based, otherwise
00106 // the decision for core or disk is taken for you.
00107    ImageStatistics (const ImageInterface<T>& image, 
00108                     LogIO& os,
00109                     Bool showProgress=True,
00110                     Bool forceDisk=False);
00111 
00112 // Constructor takes the image only. In the absence of a logger you get no messages.
00113 // This includes error messages and potential listing of the statistics.
00114 // You can specify whether you want to see progress meters or not.
00115 // You can force the storage image to be disk based, otherwise
00116 // the decision for core or disk is taken for you.
00117    ImageStatistics (const ImageInterface<T>& image,
00118                     Bool showProgress=True,
00119                     Bool forceDisk=False);
00120 
00121 // Copy constructor.  Copy semantics are followed.  Therefore any storage image 
00122 // that has already been created for <src>other</src> is copied to <src>*this</src>
00123    ImageStatistics(const ImageStatistics<T> &other);
00124 
00125 // Destructor
00126    virtual ~ImageStatistics ();
00127 
00128 // Assignment operator.  Deletes any storage image associated with
00129 // the object being assigned to and copies any storage image that has
00130 // already been created for "other".
00131    ImageStatistics<T> &operator=(const ImageStatistics<T> &other);
00132 
00133 // Set a new ImageInterface object.  A return value of <src>False</src> indicates the 
00134 // image had an invalid type or that the internal state of the class is bad.
00135    Bool setNewImage (const ImageInterface<T>& image);
00136 
00137    void setPrecision(Int precision);
00138 
00139    void setBlc(const IPosition& blc);
00140 
00141    IPosition getBlc() const;
00142 
00143    Int getPrecision() const;
00144 
00145    // list robust statistics? Should be called before display()
00146    void showRobust(const Bool show);
00147 
00148    inline void recordMessages(const Bool rm) { _recordMessages = rm; }
00149 
00150    inline vector<String> getMessages() { return _messages; }
00151 
00152    inline void clearMessages() { _messages.resize(0); }
00153 
00154     void setListStats(Bool b) { _listStats = b; }
00155 protected:
00156 
00157    typedef typename NumericTraits<T>::PrecisionType AccumType;
00158 
00159    virtual Bool _canDoFlux() const;
00160 
00161 
00162 
00163 private:
00164 // Data
00165 
00166    LogIO os_p;
00167    const ImageInterface<T>* pInImage_p;
00168    IPosition blc_;
00169    Int precision_;
00170    Bool _showRobust, _recordMessages, _listStats;
00171    mutable vector<String> _messages;
00172 
00173 // Virtual functions.  See LatticeStatistics for more information
00174 // about these, or see the implementation.
00175 
00176 // Get label for higher order axes
00177    virtual void getLabels(String& higherOrder, String& xAxis, const IPosition& dPos) const;
00178 
00179     // Get beam area in pixels if possible. Return False if the beam area could not be
00180     // calculated.
00181     virtual Bool _getBeamArea(
00182         Array<Double>& beamArea, String& msg
00183     ) const;
00184 
00185 // List min and max with world coordinates
00186    virtual void listMinMax (ostringstream& osMin,
00187                             ostringstream& osMax,
00188                             Int oWidth, DataType type);
00189 
00190 // List the statistics
00191    virtual Bool listStats (Bool hasBeam, const IPosition& dPos,
00192                            const Matrix<AccumType>& ord);
00193 
00194    virtual void displayStats(
00195                    AccumType nPts, AccumType sum, AccumType median,
00196            AccumType medAbsDevMed, AccumType quartile,
00197            AccumType sumSq, AccumType mean, AccumType var,
00198            AccumType rms, AccumType sigma, AccumType dMin,
00199            AccumType dMax, AccumType q1, AccumType q3
00200    );
00201 
00202 
00203    // If <src>isFluxDensity</src> is False, then the computed value is
00204    // a flux (ie flux density integrated over a spectral extent)
00205    Quantum<AccumType> _flux(
00206                    Bool& isFluxDensity, AccumType sum, Double beamAreaInPixels
00207    ) const;
00208 
00209    Bool _computeFlux(
00210                    Array<AccumType>& flux, const Array<AccumType>& npts,
00211                    const Array<AccumType>& sum
00212    );
00213 
00214    Bool _computeFlux(
00215                    Quantum<AccumType>& flux, AccumType sum, const IPosition& pos,
00216                    Bool posInLattice
00217    );
00218   //# Make members of parent class known.
00219 protected:
00220   using LatticeStatistics<T>::locInLattice;
00221   using LatticeStatistics<T>::setStream;
00222   using LatticeStatistics<T>::error_p;
00223   using LatticeStatistics<T>::goodParameterStatus_p;
00224   using LatticeStatistics<T>::haveLogger_p;
00225   using LatticeStatistics<T>::displayAxes_p;
00226   using LatticeStatistics<T>::cursorAxes_p;
00227   using LatticeStatistics<T>::doRobust_p;
00228   using LatticeStatistics<T>::doList_p;
00229   using LatticeStatistics<T>::fixedMinMax_p;
00230   using LatticeStatistics<T>::minPos_p;
00231   using LatticeStatistics<T>::maxPos_p;
00232   using LatticeStatistics<T>::blcParent_p;
00233 public:
00234   using LatticeStatistics<T>::NPTS;
00235   using LatticeStatistics<T>::SUM;
00236   using LatticeStatistics<T>::FLUX;
00237   using LatticeStatistics<T>::MEAN;
00238   using LatticeStatistics<T>::MEDIAN;
00239   using LatticeStatistics<T>::RMS;
00240   using LatticeStatistics<T>::SIGMA;
00241   using LatticeStatistics<T>::MIN;
00242   using LatticeStatistics<T>::MAX;
00243 };
00244 
00245 //# Declare extern templates for often used types.
00246 #ifdef AIPS_CXX11
00247   extern template class ImageStatistics<Float>;
00248 #endif
00249 
00250 
00251 } //# NAMESPACE CASACORE - END
00252 
00253 #ifndef CASACORE_NO_AUTO_TEMPLATES
00254 #include <casacore/images/Images/ImageStatistics.tcc>
00255 #endif //# CASACORE_NO_AUTO_TEMPLATES
00256 #endif
00257 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1