casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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: ImageStatistics.h 20652 2009-07-06 05:04:32Z Malte.Marquarding $
00027 
00028 #ifndef IMAGES_IMAGESTATISTICS_H
00029 #define IMAGES_IMAGESTATISTICS_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/Utilities/DataType.h>
00036 #include <casa/Logging/LogIO.h>
00037 #include <lattices/Lattices/LatticeStatistics.h>
00038 #include <scimath/Mathematics/NumericTraits.h>
00039 #include <casa/iosstrfwd.h>
00040 
00041 namespace casa { //# NAMESPACE CASA - 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 private:
00154 
00155 // Data
00156 
00157    LogIO os_p;
00158    const ImageInterface<T>* pInImage_p;
00159    IPosition blc_;
00160    Int precision_;
00161    Bool _showRobust, _recordMessages;
00162    vector<String> _messages;
00163 
00164 // Virtual functions.  See LatticeStatistics for more information
00165 // about these, or see the implementation.
00166 
00167 // Get label for higher order axes
00168    virtual void getLabels(String& higherOrder, String& xAxis, const IPosition& dPos) const;
00169 
00170     // Get beam volume if possible. Return False if the beam area could not be
00171     // calculated.
00172     virtual Bool _getBeamArea(
00173         Array<Double>& beamArea
00174     ) const;
00175 
00176 // List min and max with world coordinates
00177    virtual void listMinMax (ostringstream& osMin,
00178                             ostringstream& osMax,
00179                             Int oWidth, DataType type);
00180 
00181 // List the statistics
00182    typedef typename NumericTraits<T>::PrecisionType AccumType;
00183    virtual Bool listStats (Bool hasBeam, const IPosition& dPos,
00184                            const Matrix<AccumType>& ord);
00185 
00186    virtual void displayStats(
00187                    AccumType nPts, AccumType sum, AccumType median,
00188            AccumType medAbsDevMed, AccumType quartile,
00189            AccumType sumSq, AccumType mean, AccumType var,
00190            AccumType rms, AccumType sigma, AccumType dMin,
00191            AccumType dMax
00192    );
00193 
00194 
00195   //# Make members of parent class known.
00196 protected:
00197   using LatticeStatistics<T>::locInLattice;
00198   using LatticeStatistics<T>::setStream;
00199   using LatticeStatistics<T>::error_p;
00200   using LatticeStatistics<T>::goodParameterStatus_p;
00201   using LatticeStatistics<T>::haveLogger_p;
00202   using LatticeStatistics<T>::displayAxes_p;
00203   using LatticeStatistics<T>::cursorAxes_p;
00204   using LatticeStatistics<T>::doRobust_p;
00205   using LatticeStatistics<T>::doList_p;
00206   using LatticeStatistics<T>::fixedMinMax_p;
00207   using LatticeStatistics<T>::minPos_p;
00208   using LatticeStatistics<T>::maxPos_p;
00209   using LatticeStatistics<T>::blcParent_p;
00210 public:
00211   using LatticeStatistics<T>::NPTS;
00212   using LatticeStatistics<T>::SUM;
00213   using LatticeStatistics<T>::FLUX;
00214   using LatticeStatistics<T>::MEAN;
00215   using LatticeStatistics<T>::MEDIAN;
00216   using LatticeStatistics<T>::RMS;
00217   using LatticeStatistics<T>::SIGMA;
00218   using LatticeStatistics<T>::MIN;
00219   using LatticeStatistics<T>::MAX;
00220 };
00221 
00222 
00223 
00224 } //# NAMESPACE CASA - END
00225 
00226 #ifndef CASACORE_NO_AUTO_TEMPLATES
00227 #include <images/Images/ImageStatistics.tcc>
00228 #endif //# CASACORE_NO_AUTO_TEMPLATES
00229 #endif
00230