25 #if !defined(LSST_AFW_MATH_STATISTICS_H)
26 #define LSST_AFW_MATH_STATISTICS_H
40 #include "boost/iterator/iterator_adaptor.hpp"
41 #include "boost/tuple/tuple.hpp"
51 template <
typename,
typename,
typename>
99 bool isNanSafe =
true,
103 : _numSigmaClip(numSigmaClip),
106 _noGoodPixelsMask(0x0),
107 _isNanSafe(isNanSafe),
108 _useWeights(useWeights),
109 _calcErrorFromInputVariance(false),
110 _maskPropagationThresholds() {
113 }
catch (lsst::pex::exceptions::InvalidParameterError) {
117 assert(_numSigmaClip > 0);
118 assert(_numIter > 0);
141 assert(numSigmaClip > 0);
142 _numSigmaClip = numSigmaClip;
153 _calcErrorFromInputVariance = calcErrorFromInputVariance;
159 double _numSigmaClip;
162 int _noGoodPixelsMask;
165 bool _calcErrorFromInputVariance;
166 std::vector<double> _maskPropagationThresholds;
216 typedef std::pair<double, double>
Value;
230 template <
typename ImageT,
typename MaskT,
typename VarianceT>
231 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
int const flags,
242 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
243 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
293 bool _weightsAreMultiplicative;
303 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
304 void doStatistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
313 template <
typename ValueT>
314 class infinite_iterator :
public boost::iterator_adaptor<infinite_iterator<ValueT>, const ValueT *,
315 const ValueT, boost::forward_traversal_tag> {
322 void increment() { ; }
328 template <
typename ValueT>
343 template <
typename Pixel>
348 return Statistics(img, msk, var, flags, sctrl);
355 template <
typename ImageT,
typename MaskT,
typename VarianceT>
358 return Statistics(img, msk, var, flags, sctrl);
365 template <
typename Pixel>
368 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
380 template <
typename Pixel>
384 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() ||
385 (!sctrl.getWeightedIsSet() && (weights.
getWidth() != 0 && weights.
getHeight() != 0))) {
403 StatisticsControl
const &sctrl = StatisticsControl());
409 template <
typename Pixel>
418 return Statistics(img, msk, var, flags, sctrl);
425 template <
typename ValueT>
429 typedef typename std::vector<ValueT>::const_iterator
x_iterator;
445 bool empty()
const {
return _v.empty(); }
448 std::vector<ValueT>
const &_v;
449 std::vector<ValueT>
const &_getVector()
const {
return _v; }
456 template <
typename EntryT>
464 return Statistics(img, msk, var, flags, sctrl);
471 template <
typename EntryT>
473 std::vector<WeightPixel>
const &vweights,
483 return Statistics(img, msk, var, weights, flags, sctrl);
490 template <
typename EntryT>
495 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
507 template <
typename EntryT>
509 std::vector<WeightPixel>
const &vweights,
515 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
ImageImposter(ImageImposter< ValueT > const &img)
double getNumSigmaClip() const
lsst::afw::image::MaskPixel getOrMask() const
std::vector< ValueT >::const_iterator x_iterator
MaskImposter(ValueT val=0)
lsst::afw::image::VariancePixel WeightPixel
get the or-mask of all pixels used.
void setNumSigmaClip(double numSigmaClip)
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
afw::geom::Extent2I getDimensions() const
x_iterator row_begin(int) const
estimate sample standard deviation
find mean value of square of pixel values
Extent< int, 2 > Extent2I
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
void setMaskPropagationThreshold(int bit, double threshold)
When pixels with the given bit are rejected, we count what fraction the rejected pixels would have co...
void setNoGoodPixelsMask(int noGoodPixelsMask)
We don't want anything.
bool getCalcErrorFromInputVariance() const
Include errors of requested quantities.
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
A class to evaluate image statistics.
Statistics(ImageT const &img, MaskT const &msk, VarianceT const &var, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Constructor for Statistics object.
x_iterator row_end(int) const
std::vector< ValueT >::const_iterator fast_iterator
lsst::afw::image::MaskedImage< EntryT >::VariancePtr getVariance() const
void setCalcErrorFromInputVariance(bool calcErrorFromInputVariance)
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
std::pair< double, double > Value
The type used to report (value, error) for desired statistics.
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
infinite_iterator< ValueT > x_iterator
void setNumIter(int numIter)
StatisticsControl(double numSigmaClip=3.0, int numIter=3, lsst::afw::image::MaskPixel andMask=0x0, bool isNanSafe=true, WeightsBoolean useWeights=WEIGHTS_NONE)
Pass parameters to a Statistics object.
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
x_iterator row_begin(int) const
Represent a 2-dimensional array of bitmask pixels.
estimate sample N-sigma clipped variance (N set in StatisticsControl, default=3)
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
A Mask wrapper to provide an infinite_iterator for Mask::row_begin().
A class to manipulate images, masks, and variance as a single object.
int getHeight() const
Return the number of rows in the image.
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR'd together.
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
void setWeighted(bool useWeights)
This iterator will never increment.
lsst::afw::image::MaskedImage< EntryT >::MaskPtr getMask() const
infinite_iterator(const ValueT *p)
Value getResult(Property const prop=NOTHING) const
Return the value and error in the specified statistic (e.g.
estimate sample inter-quartile range
void setNanSafe(bool isNanSafe)
double getError(Property const prop=NOTHING) const
Return the error in the desired property (if specified in the constructor)
double getMaskPropagationThreshold(int bit) const
When pixels with the given bit are rejected, we count what fraction the rejected pixels would have co...
A vector wrapper to provide a vector with the necessary methods and typedefs to be processed by Stati...
int getNoGoodPixelsMask() const
find sum of pixels in the image
lsst::afw::image::MaskedImage< EntryT >::ImagePtr getImage() const
float VariancePixel
default type for MaskedImage variance images
Property
control what is calculated
int getWidth() const
Return the number of columns in the image.
friend class boost::iterator_core_access
ImageImposter(std::vector< ValueT > const &v)
bool getWeightedIsSet() const
void setAndMask(int andMask)