casacore
Loading...
Searching...
No Matches
ImageStatistics.h
Go to the documentation of this file.
1//# ImageStatistics.h: generate statistics from an image
2//# Copyright (C) 1996,1997,1998,1999,2000,2001,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef IMAGES_IMAGESTATISTICS_H
27#define IMAGES_IMAGESTATISTICS_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/Utilities/DataType.h>
34#include <casacore/casa/Logging/LogIO.h>
35#include <casacore/lattices/LatticeMath/LatticeStatistics.h>
36#include <casacore/scimath/Mathematics/NumericTraits.h>
37#include <casacore/casa/iosstrfwd.h>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41//# Forward Declarations
42template <class T> class ImageInterface;
43class IPosition;
44
45// <summary>
46// Displays various statistics from an image.
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
52// </reviewed>
53
54// <prerequisite>
55// <li> <linkto class=LatticeStatistics>LatticeStatistics</linkto> (base class)
56// <li> <linkto class=ImageInterface>ImageInterface</linkto>
57// </prerequisite>
58
59// <etymology>
60// This is a class designed to display and retrieve statistics from images
61// </etymology>
62
63// <synopsis>
64// This class enable you to display and/or retrieve statistics evaluated over
65// specified regions from an image. The dimension of the region is arbitrary, but
66// the size of each dimension is always the size of the corresponding image axis.
67// The statistics are displayed as a function of location of the axes not
68// used to evaluate the statistics over. The axes which you evaluate the statistics
69// over are called the cursor axes, the others are called the display axes.
70//
71// This class is derived from the class LatticeStatistics which does all
72// the work. This class only adds some extra capability in terms of
73// logging world (rather than pixel) coordinates and computing the
74// synthesized beam area, if there is one. There are just a few virtual
75// functions for you to over-ride. These are rather specialized, they
76// are not part of a general polymorphic interface, just a way to
77// separate the Lattice and Image functionality out.
78//
79// See LatticeStatistics for details and examples.
80// </synopsis>
81//
82// <motivation>
83// The generation of statistical information from an image is a basic
84// and necessary capability.
85// </motivation>
86
87// <todo asof="1996/11/26">
88// <li> Deal with complex images at least for statistics retrieval if not
89// plotting.
90// <li> Retrieve statistics at specified location of display axes
91// <li> Standard errors on statistical quantities
92// <li> Median, other more exotic statistics. Life made difficult by
93// accumulation image approach
94// </todo>
95
96
97template <class T> class ImageStatistics : public LatticeStatistics<T>
98{
99public:
100
101// Constructor takes the image and a <src>LogIO</src> object for logging.
102// You can specify whether you want to see progress meters or not.
103// You can force the storage image to be disk based, otherwise
104// the decision for core or disk is taken for you.
105// If <src>clone</src> is True, the input image will be cloned, so the caller
106// can make changes to the input image, but the statistics will reflect the
107// image as it was at construction. If False, a reference to the input image
108// is used, and so the caller shouldn't make changes to the input image between
109// construction and calling statistics computation methods, unless it calls setNewImage()
110// to update the changed image. Obviously, cloning the image impacts performance
111// and memory usage.
113 LogIO& os,
114 Bool showProgress=True,
115 Bool forceDisk=False,
116 Bool clone=True);
117
118// Constructor takes the image only. In the absence of a logger you get no messages.
119// This includes error messages and potential listing of the statistics.
120// You can specify whether you want to see progress meters or not.
121// You can force the storage image to be disk based, otherwise
122// the decision for core or disk is taken for you.
124 Bool showProgress=True,
125 Bool forceDisk=False,
126 Bool clone=True);
127
128// Copy constructor. Copy semantics are followed. Therefore any storage image
129// that has already been created for <src>other</src> is copied to <src>*this</src>
131
132// Destructor
134
135// Assignment operator. Deletes any storage image associated with
136// the object being assigned to and copies any storage image that has
137// already been created for "other".
139
140// Set a new ImageInterface object. A return value of <src>False</src> indicates the
141// image had an invalid type or that the internal state of the class is bad.
142// If <src>clone</src> is True, the input image will be cloned, so the caller
143// can make changes to the input image, but the statistics will reflect the
144// image as it was at construction. If False, a reference to the input image
145// is used, and so the caller shouldn't make changes to the input image between
146// construction and calling statistics computation methods, unless it calls setNewImage()
147// to update the changed image. Obviously, cloning the image impacts performance
148// and memory usage.
150
151 void setPrecision(Int precision);
152
153 void setBlc(const IPosition& blc);
154
156
158
159 // list robust statistics? Should be called before display()
160 void showRobust(const Bool show);
161
162 inline void recordMessages(const Bool rm) { _recordMessages = rm; }
163
164 inline vector<String> getMessages() { return _messages; }
165
166 inline void clearMessages() { _messages.resize(0); }
167
168 void setListStats(Bool b) { _listStats = b; }
169protected:
170
172
173 virtual Bool _canDoFlux() const;
174
175private:
176// Data
177
180 std::shared_ptr<const ImageInterface<T>> _inImPtrMgr;
184 mutable vector<String> _messages;
185
186// Virtual functions. See LatticeStatistics for more information
187// about these, or see the implementation.
188
189// Get label for higher order axes
190 virtual void getLabels(String& higherOrder, String& xAxis, const IPosition& dPos) const;
191
192 // Get beam area in pixels if possible. Return False if the beam area could not be
193 // calculated.
195 Array<Double>& beamArea, String& msg
196 ) const;
197
198// List min and max with world coordinates
199 virtual void listMinMax (ostringstream& osMin,
200 ostringstream& osMax,
201 Int oWidth, DataType type);
202
203// List the statistics
204 virtual Bool listStats (Bool hasBeam, const IPosition& dPos,
205 const Matrix<AccumType>& ord);
206
207 virtual void displayStats(
209 AccumType medAbsDevMed, AccumType quartile,
210 AccumType sumSq, AccumType mean, AccumType var,
211 AccumType rms, AccumType sigma, AccumType dMin,
212 AccumType dMax, AccumType q1, AccumType q3
213 );
214
215
216 // If <src>isFluxDensity</src> is False, then the computed value is
217 // a flux (ie flux density integrated over a spectral extent)
219 Bool& isFluxDensity, AccumType sum, Double beamAreaInPixels
220 ) const;
221
223 Array<AccumType>& flux, const Array<AccumType>& npts,
224 const Array<AccumType>& sum
225 );
226
228 Quantum<AccumType>& flux, AccumType sum, const IPosition& pos,
229 Bool posInLattice
230 );
231 //# Make members of parent class known.
232protected:
246public:
248 using LatticeStatistics<T>::SUM;
252 using LatticeStatistics<T>::RMS;
254 using LatticeStatistics<T>::MIN;
255 using LatticeStatistics<T>::MAX;
256};
257
258//# Declare extern templates for often used types.
259 extern template class ImageStatistics<Float>;
260
261
262} //# NAMESPACE CASACORE - END
263
264#ifndef CASACORE_NO_AUTO_TEMPLATES
265#include <casacore/images/Images/ImageStatistics.tcc>
266#endif //# CASACORE_NO_AUTO_TEMPLATES
267#endif
268
ImageStatistics(const ImageInterface< T > &image, LogIO &os, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the image and a LogIO object for logging.
void recordMessages(const Bool rm)
virtual Bool _getBeamArea(Array< Double > &beamArea, String &msg) const
Get beam area in pixels if possible.
ImageStatistics(const ImageStatistics< T > &other)
Copy constructor.
virtual ~ImageStatistics()
Destructor.
Quantum< AccumType > _flux(Bool &isFluxDensity, AccumType sum, Double beamAreaInPixels) const
If isFluxDensity is False, then the computed value is a flux (ie flux density integrated over a spect...
virtual void displayStats(AccumType nPts, AccumType sum, AccumType median, AccumType medAbsDevMed, AccumType quartile, AccumType sumSq, AccumType mean, AccumType var, AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax, AccumType q1, AccumType q3)
const ImageInterface< T > * pInImage_p
void setBlc(const IPosition &blc)
virtual Bool listStats(Bool hasBeam, const IPosition &dPos, const Matrix< AccumType > &ord)
List the statistics.
virtual void listMinMax(ostringstream &osMin, ostringstream &osMax, Int oWidth, DataType type)
List min and max with world coordinates.
ImageStatistics(const ImageInterface< T > &image, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the image only.
Bool setNewImage(const ImageInterface< T > &image, Bool clone=True)
Set a new ImageInterface object.
virtual Bool _canDoFlux() const
Virtual Functions.
void setPrecision(Int precision)
Bool _computeFlux(Quantum< AccumType > &flux, AccumType sum, const IPosition &pos, Bool posInLattice)
Bool _computeFlux(Array< AccumType > &flux, const Array< AccumType > &npts, const Array< AccumType > &sum)
NumericTraits< T >::PrecisionType AccumType
vector< String > getMessages()
std::shared_ptr< const ImageInterface< T > > _inImPtrMgr
ImageStatistics< T > & operator=(const ImageStatistics< T > &other)
Assignment operator.
virtual void getLabels(String &higherOrder, String &xAxis, const IPosition &dPos) const
Virtual functions.
IPosition getBlc() const
void showRobust(const Bool show)
list robust statistics? Should be called before display()
Bool doRobust_p
doRobust means that when the storage lattice is generated, the robust statistics are generated as wel...
IPosition locInLattice(const IPosition &storagePosition, Bool relativeToParent=True) const
Given a location in the storage lattice, convert those locations on the non-statistics axis (the la...
void setStream(ostream &os, Int oPrec)
Non-virtual functions.
@ NPTS
The number of points.
@ MEDIAN
The median - the robust stats does not fit well into storage lattice approach.
@ SIGMA
The standard deviation about the mean.
@ FLUX
The flux density (can't always compute this - needs the beam)
Char PrecisionType
Higher precision type (Float->Double)
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
LatticeExprNode mean(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
LatticeExprNode median(const LatticeExprNode &expr)
TableExprNode rms(const TableExprNode &array)
Definition ExprNode.h:1684