37 #include "boost/shared_ptr.hpp"
46 namespace afwMath = lsst::afw::math;
47 namespace afwGeom = lsst::afw::geom;
48 namespace pexExceptions = lsst::pex::exceptions;
51 double const NaN = std::numeric_limits<double>::quiet_NaN();
52 double const MAX_DOUBLE = std::numeric_limits<double>::max();
53 double const IQ_TO_STDEV = 0.741301109252802;
61 bool operator()(T)
const {
64 template<
typename Ta,
typename Tb>
65 bool operator()(Ta, Tb)
const {
68 template<
typename Ta,
typename Tb,
typename Tc>
69 bool operator()(Ta, Tb, Tc)
const {
80 bool operator()(T)
const {
83 template<
typename Ta,
typename Tb>
84 bool operator()(Ta, Tb)
const {
87 template<
typename Ta,
typename Tb,
typename Tc>
88 bool operator()(Ta, Tb, Tc)
const {
99 bool operator()(T
val)
const {
107 class CheckValueLtMin {
109 template<
typename Tval,
typename Tmin>
110 bool operator()(Tval
val, Tmin min)
const {
111 return (static_cast<Tmin>(val) < min);
118 class CheckValueGtMax {
120 template<
typename Tval,
typename Tmax>
121 bool operator()(Tval val, Tmax max)
const {
122 return (static_cast<Tmax>(val) > max);
129 class CheckClipRange {
131 template<
typename Tval,
typename Tcen,
typename Tmax>
132 bool operator()(Tval val, Tcen center, Tmax cliplimit)
const {
133 Tmax tmp = fabs(val - center);
134 return (tmp <= cliplimit);
139 typedef CheckFinite ChkFin;
140 typedef CheckValueLtMin ChkMin;
141 typedef CheckValueGtMax ChkMax;
142 typedef CheckClipRange ChkClip;
143 typedef AlwaysTrue AlwaysT;
144 typedef AlwaysFalse AlwaysF;
148 inline double varianceError(
double const variance,
int const n)
150 return 2*(n - 1)*variance*variance/static_cast<double>(n*n);
155 typedef boost::tuple<int,
177 template<
typename IsFinite,
178 typename HasValueLtMin,
179 typename HasValueGtMax,
180 typename InClipRange,
182 typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
183 StandardReturn processPixels(ImageT
const &img,
185 VarianceT
const &var,
186 WeightT
const &weights,
190 double const meanCrude,
191 double const cliplimit,
192 bool const weightsAreMultiplicative,
194 bool const calcErrorFromInputVariance,
195 std::vector<double>
const & maskPropagationThresholds
206 double min = (nCrude) ? meanCrude : MAX_DOUBLE;
207 double max = (nCrude) ? meanCrude : -MAX_DOUBLE;
211 std::vector<double> rejectedWeightsByBit(maskPropagationThresholds.size(), 0.0);
213 for (
int iY = 0; iY < img.getHeight(); iY += stride) {
215 typename MaskT::x_iterator mptr = msk.row_begin(iY);
216 typename VarianceT::x_iterator vptr = var.row_begin(iY);
217 typename WeightT::x_iterator wptr = weights.row_begin(iY);
219 for (
typename ImageT::x_iterator ptr = img.row_begin(iY), end = ptr + img.getWidth();
220 ptr != end; ++ptr, ++mptr, ++vptr, ++wptr) {
222 if (IsFinite()(*ptr) && !(*mptr & andMask) &&
223 InClipRange()(*ptr, meanCrude, cliplimit) ) {
225 double const delta = (*ptr - meanCrude);
229 if (weightsAreMultiplicative) {
240 sumx += weight*delta;
241 sumx2 += weight*delta*delta;
243 if (calcErrorFromInputVariance) {
244 double const var = *vptr;
245 sumvw2 += var*weight*
weight;
249 sumx2 += delta*delta;
251 if (calcErrorFromInputVariance) {
252 double const var = *vptr;
257 allPixelOrMask |= *mptr;
259 if (HasValueLtMin()(*ptr, min)) { min = *ptr; }
260 if (HasValueGtMax()(*ptr, max)) { max = *ptr; }
263 for (
int bit = 0, nBits=maskPropagationThresholds.size(); bit < nBits; ++bit) {
269 if (!weightsAreMultiplicative) {
276 rejectedWeightsByBit[bit] +=
weight;
288 double mean, variance;
293 for (
int bit = 0, nBits=maskPropagationThresholds.size(); bit < nBits; ++bit) {
294 double hypotheticalTotalWeight = sumw + rejectedWeightsByBit[bit];
295 rejectedWeightsByBit[bit] /= hypotheticalTotalWeight;
296 if (rejectedWeightsByBit[bit] > maskPropagationThresholds[bit]) {
297 allPixelOrMask |= (1 << bit);
306 variance = sumx2/sumw - ::pow(mean, 2);
307 variance *= sumw*sumw/(sumw*sumw - sumw2);
310 if (calcErrorFromInputVariance) {
311 meanVar = sumvw2/(sumw*sumw);
313 meanVar = variance*sumw2/(sumw*sumw);
316 double varVar = varianceError(variance, n);
318 sumx += sumw*meanCrude;
321 return StandardReturn(n, sumx,
326 template<
typename IsFinite,
327 typename HasValueLtMin,
328 typename HasValueGtMax,
329 typename InClipRange,
331 typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
332 StandardReturn processPixels(ImageT
const &img,
334 VarianceT
const &var,
335 WeightT
const &weights,
339 double const meanCrude,
340 double const cliplimit,
341 bool const weightsAreMultiplicative,
343 bool const calcErrorFromInputVariance,
345 std::vector<double>
const & maskPropagationThresholds
349 return processPixels<IsFinite, HasValueLtMin, HasValueGtMax, InClipRange, true>(
350 img, msk, var, weights,
351 flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative, andMask,
352 calcErrorFromInputVariance, maskPropagationThresholds);
354 return processPixels<IsFinite, HasValueLtMin, HasValueGtMax, InClipRange, false>(
355 img, msk, var, weights,
356 flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative, andMask,
357 calcErrorFromInputVariance, maskPropagationThresholds);
361 template<
typename IsFinite,
362 typename HasValueLtMin,
363 typename HasValueGtMax,
364 typename InClipRange,
366 typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
367 StandardReturn processPixels(ImageT
const &img,
369 VarianceT
const &var,
370 WeightT
const &weights,
374 double const meanCrude,
375 double const cliplimit,
376 bool const weightsAreMultiplicative,
378 bool const calcErrorFromInputVariance,
381 std::vector<double>
const & maskPropagationThresholds
385 return processPixels<CheckFinite, HasValueLtMin, HasValueGtMax, InClipRange, useWeights>(
386 img, msk, var, weights,
387 flags, nCrude, 1, meanCrude, cliplimit,
388 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
389 doGetWeighted, maskPropagationThresholds);
391 return processPixels<AlwaysTrue, HasValueLtMin, HasValueGtMax, InClipRange, useWeights>(
392 img, msk, var, weights,
393 flags, nCrude, 1, meanCrude, cliplimit,
394 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
395 doGetWeighted, maskPropagationThresholds);
407 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
408 StandardReturn getStandard(ImageT
const &img,
410 VarianceT
const &var,
411 WeightT
const &weights,
413 bool const weightsAreMultiplicative,
415 bool const calcErrorFromInputVariance,
418 std::vector<double>
const & maskPropagationThresholds
424 double meanCrude = 0.0;
427 int const nPix = img.getWidth()*img.getHeight();
435 double cliplimit = -1;
436 StandardReturn values = processPixels<ChkFin, AlwaysF, AlwaysF, AlwaysT, true>(
437 img, msk, var, weights,
438 flags, nCrude, strideCrude, meanCrude,
440 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
441 doCheckFinite, doGetWeighted,
442 maskPropagationThresholds);
443 nCrude = values.get<0>();
444 double sumCrude = values.get<1>();
448 meanCrude = sumCrude/nCrude;
456 return processPixels<ChkFin, ChkMin, ChkMax, AlwaysT, true>(
457 img, msk, var, weights,
458 flags, nCrude, 1, meanCrude,
460 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
461 true, doGetWeighted, maskPropagationThresholds);
463 return processPixels<ChkFin, AlwaysF, AlwaysF, AlwaysT,true>(
464 img, msk, var, weights,
465 flags, nCrude, 1, meanCrude,
467 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
468 doCheckFinite, doGetWeighted, maskPropagationThresholds);
477 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
478 StandardReturn getStandard(ImageT
const &img,
480 VarianceT
const &var,
481 WeightT
const &weights,
483 std::pair<double, double>
const clipinfo,
485 bool const weightsAreMultiplicative,
487 bool const calcErrorFromInputVariance,
490 std::vector<double>
const & maskPropagationThresholds
493 double const center = clipinfo.first;
494 double const cliplimit = clipinfo.second;
497 return StandardReturn(0, NaN,
504 int const stride = 1;
508 return processPixels<ChkFin, ChkMin, ChkMax, ChkClip, true>(
509 img, msk, var, weights,
510 flags, nCrude, stride,
512 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
513 true, doGetWeighted, maskPropagationThresholds);
515 return processPixels<ChkFin, AlwaysF, AlwaysF, ChkClip, true>(
516 img, msk, var, weights,
517 flags, nCrude, stride,
519 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
520 doCheckFinite, doGetWeighted, maskPropagationThresholds);
532 template<
typename Pixel>
533 double percentile(std::vector<Pixel> &img,
534 double const fraction)
536 assert (fraction >= 0.0 && fraction <= 1.0);
538 int const n = img.size();
542 double const idx = fraction*(n - 1);
550 int const q1 =
static_cast<int>(idx);
551 int const q2 = q1 + 1;
553 typename std::vector<Pixel>::iterator mid1 = img.begin() + q1;
554 typename std::vector<Pixel>::iterator mid2 = img.begin() + q2;
555 if (fraction > 0.5) {
556 std::nth_element(img.begin(), mid1, img.end());
557 std::nth_element(mid1, mid2, img.end());
559 std::nth_element(img.begin(), mid2, img.end());
560 std::nth_element(img.begin(), mid1, mid2);
563 double val1 =
static_cast<double>(*mid1);
564 double val2 =
static_cast<double>(*mid2);
565 double w1 = (
static_cast<double>(q2) - idx);
566 double w2 = (idx -
static_cast<double>(q1));
567 return w1*val1 + w2*val2;
585 typedef boost::tuple<double, double, double> MedianQuartileReturn;
587 template<
typename Pixel>
588 MedianQuartileReturn medianAndQuartiles(std::vector<Pixel> &img)
590 int const n = img.size();
594 double const idx50 = 0.50*(n - 1);
595 double const idx25 = 0.25*(n - 1);
596 double const idx75 = 0.75*(n - 1);
603 int const q50a =
static_cast<int>(idx50);
604 int const q50b = q50a + 1;
605 int const q25a =
static_cast<int>(idx25);
606 int const q25b = q25a + 1;
607 int const q75a =
static_cast<int>(idx75);
608 int const q75b = q75a + 1;
610 typename std::vector<Pixel>::iterator mid50a = img.begin() + q50a;
611 typename std::vector<Pixel>::iterator mid50b = img.begin() + q50b;
612 typename std::vector<Pixel>::iterator mid25a = img.begin() + q25a;
613 typename std::vector<Pixel>::iterator mid25b = img.begin() + q25b;
614 typename std::vector<Pixel>::iterator mid75a = img.begin() + q75a;
615 typename std::vector<Pixel>::iterator mid75b = img.begin() + q75b;
618 std::nth_element(img.begin(), mid50a, img.end());
619 std::nth_element(mid50a, mid75a, img.end());
620 std::nth_element(img.begin(), mid25a, mid50a);
623 std::nth_element(mid50a, mid50b, mid75a);
624 std::nth_element(mid25a, mid25b, mid50a);
625 std::nth_element(mid75a, mid75b, img.end());
628 double val50a =
static_cast<double>(*mid50a);
629 double val50b =
static_cast<double>(*mid50b);
630 double w50a = (
static_cast<double>(q50b) - idx50);
631 double w50b = (idx50 -
static_cast<double>(q50a));
632 double median = w50a*val50a + w50b*val50b;
634 double val25a =
static_cast<double>(*mid25a);
635 double val25b =
static_cast<double>(*mid25b);
636 double w25a = (
static_cast<double>(q25b) - idx25);
637 double w25b = (idx25 -
static_cast<double>(q25a));
638 double q1 = w25a*val25a + w25b*val25b;
640 double val75a =
static_cast<double>(*mid75a);
641 double val75b =
static_cast<double>(*mid75b);
642 double w75a = (
static_cast<double>(q75b) - idx75);
643 double w75b = (idx75 -
static_cast<double>(q75a));
644 double q3 = w75a*val75a + w75b*val75b;
646 return MedianQuartileReturn(median, q1, q3);
648 return MedianQuartileReturn(img[0], img[0], img[0]);
650 return MedianQuartileReturn(NaN, NaN, NaN);
662 template<
typename IsFinite,
typename ImageT,
typename MaskT,
typename VarianceT>
663 boost::shared_ptr<std::vector<typename ImageT::Pixel> > makeVectorCopy(ImageT
const &img,
671 boost::shared_ptr<std::vector<typename ImageT::Pixel> >
672 imgcp(
new std::vector<typename ImageT::Pixel>(0));
674 for (
int i_y = 0; i_y < img.getHeight(); ++i_y) {
675 typename MaskT::x_iterator mptr = msk.row_begin(i_y);
676 for (
typename ImageT::x_iterator ptr = img.row_begin(i_y), end = img.row_end(i_y);
678 if (IsFinite()(*ptr) && !(*mptr & andMask)) {
679 imgcp->push_back(*ptr);
692 int oldSize = _maskPropagationThresholds.size();
696 return _maskPropagationThresholds[bit];
700 int oldSize = _maskPropagationThresholds.size();
701 if (oldSize <= bit) {
702 int newSize = bit + 1;
703 _maskPropagationThresholds.resize(newSize);
704 for (
int i = oldSize; i < bit; ++i) {
705 _maskPropagationThresholds[i] = 1.0;
708 _maskPropagationThresholds[bit] = threshold;
716 static std::map<std::string, Property> statisticsProperty;
717 if (statisticsProperty.size() == 0) {
718 statisticsProperty[
"NOTHING"] =
NOTHING;
719 statisticsProperty[
"ERRORS"] =
ERRORS;
720 statisticsProperty[
"NPOINT"] =
NPOINT;
721 statisticsProperty[
"MEAN"] =
MEAN;
722 statisticsProperty[
"STDEV"] =
STDEV;
723 statisticsProperty[
"VARIANCE"] =
VARIANCE;
724 statisticsProperty[
"MEDIAN"] =
MEDIAN;
725 statisticsProperty[
"IQRANGE"] =
IQRANGE;
726 statisticsProperty[
"MEANCLIP"] =
MEANCLIP;
727 statisticsProperty[
"STDEVCLIP"] =
STDEVCLIP;
729 statisticsProperty[
"MIN"] =
MIN;
730 statisticsProperty[
"MAX"] =
MAX;
731 statisticsProperty[
"SUM"] =
SUM;
732 statisticsProperty[
"MEANSQUARE"] =
MEANSQUARE;
733 statisticsProperty[
"ORMASK"] =
ORMASK;
735 return statisticsProperty[property];
745 template<
typename ImageT,
typename MaskT,
typename VarianceT>
749 VarianceT
const &var,
753 _flags(flags), _mean(NaN, NaN), _variance(NaN, NaN), _min(NaN), _max(NaN),
_sum(NaN),
754 _meanclip(NaN, NaN), _varianceclip(NaN, NaN), _median(NaN, NaN), _iqrange(NaN),
755 _sctrl(sctrl), _weightsAreMultiplicative(false)
762 bool isEmpty(T
const& t) {
return t.empty(); }
768 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
772 VarianceT
const &var,
773 WeightT
const &weights,
777 _flags(flags), _mean(NaN, NaN), _variance(NaN, NaN), _min(NaN), _max(NaN),
_sum(NaN),
778 _meanclip(NaN, NaN), _varianceclip(NaN, NaN), _median(NaN, NaN), _iqrange(NaN),
779 _sctrl(sctrl), _weightsAreMultiplicative(true)
781 if (!isEmpty(weights)) {
783 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
784 "You must use the weights if you provide them");
792 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
796 VarianceT
const &var,
797 WeightT
const &weights,
802 _n = img.getWidth()*img.getHeight();
804 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Image contains no pixels");
808 assert(img.getWidth()*
static_cast<double>(img.getHeight()) < std::numeric_limits<int>::max());
811 StandardReturn standard = getStandard(img, msk, var, weights, flags,
812 _weightsAreMultiplicative,
814 _sctrl.getCalcErrorFromInputVariance(),
815 _sctrl.getNanSafe(), _sctrl.getWeighted(),
816 _sctrl._maskPropagationThresholds);
818 _n = standard.get<0>();
819 _sum = standard.get<1>();
820 _mean = standard.get<2>();
821 _variance = standard.get<3>();
822 _min = standard.get<4>();
823 _max = standard.get<5>();
824 _allPixelOrMask = standard.get<6>();
833 boost::shared_ptr<std::vector<typename ImageT::Pixel> > imgcp;
834 if (_sctrl.getNanSafe()) {
835 imgcp = makeVectorCopy<ChkFin>(img, msk, var, _sctrl.getAndMask());
837 imgcp = makeVectorCopy<AlwaysT>(img, msk, var, _sctrl.getAndMask());
842 _median =
Value(percentile(*imgcp, 0.5), NaN);
844 MedianQuartileReturn mq = medianAndQuartiles(*imgcp);
845 _median =
Value(mq.get<0>(), NaN);
846 _iqrange = mq.get<2>() - mq.get<1>();
851 for (
int i_i = 0; i_i < _sctrl.getNumIter(); ++i_i) {
852 double const center = ((i_i > 0) ? _meanclip : _median).first;
853 double const hwidth = (i_i > 0 && _n > 1) ?
854 _sctrl.getNumSigmaClip()*std::sqrt(_varianceclip.first) :
855 _sctrl.getNumSigmaClip()*IQ_TO_STDEV*_iqrange;
856 std::pair<double, double>
const clipinfo(center, hwidth);
858 StandardReturn clipped = getStandard(img, msk, var, weights, flags, clipinfo,
859 _weightsAreMultiplicative,
861 _sctrl.getCalcErrorFromInputVariance(),
862 _sctrl.getNanSafe(), _sctrl.getWeighted(),
863 _sctrl._maskPropagationThresholds);
865 int const nClip = clipped.get<0>();
866 _meanclip = clipped.get<2>();
867 double const varClip = clipped.get<3>().first;
869 _varianceclip =
Value(varClip, varianceError(varClip, nClip));
898 if (!(prop & _flags)) {
899 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
900 (
boost::format(
"You didn't ask me to calculate %d") % prop).str());
908 ret.first =
static_cast<double>(
_n);
915 ret.first =
static_cast<double>(
_sum);
916 if (_flags & ERRORS) {
923 ret.first = _mean.first;
924 if (_flags & ERRORS) {
925 ret.second = ::sqrt(_mean.second);
929 ret.first = _meanclip.first;
930 if ( _flags & ERRORS ) {
931 ret.second = ::sqrt(_meanclip.second);
937 ret.first = _variance.first;
938 if (_flags & ERRORS) {
939 ret.second = ::sqrt(_variance.second);
943 ret.first = sqrt(_variance.first);
944 if (_flags & ERRORS) {
945 ret.second = 0.5*::sqrt(_variance.second)/ret.first;
949 ret.first = _varianceclip.first;
950 if (_flags & ERRORS) {
951 ret.second = ret.second;
955 ret.first = sqrt(_varianceclip.first);
956 if (_flags & ERRORS) {
957 ret.second = 0.5*::sqrt(_varianceclip.second)/ret.first;
962 ret.first = (
_n - 1)/static_cast<double>(
_n)*_variance.first + ::pow(_mean.first, 2);
963 if (_flags & ERRORS) {
964 ret.second = ::sqrt(2*::pow(ret.first/
_n, 2));
971 if ( _flags & ERRORS ) {
977 if ( _flags & ERRORS ) {
982 ret.first = _median.first;
983 if ( _flags & ERRORS ) {
988 ret.first = _iqrange;
989 if ( _flags & ERRORS ) {
1000 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
1001 "getValue() may only be called without a parameter"
1002 " if you asked for only one statistic");
1014 return getResult(prop).first;
1026 return getResult(prop).second;
1048 _mean(NaN, NaN), _variance(NaN, NaN), _min(NaN), _max(NaN),
1049 _meanclip(NaN, NaN), _varianceclip(NaN, NaN), _median(NaN, NaN), _iqrange(NaN),
1053 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Statistics<Mask> only supports NPOINT and SUM");
1060 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Image contains no pixels");
1064 assert(msk.
getWidth()*
static_cast<double>(msk.
getHeight()) < std::numeric_limits<int>::max());
1068 for (Mask::x_iterator ptr = msk.
row_begin(
y), end = msk.
row_end(
y); ptr != end; ++ptr) {
1087 return Statistics(msk, msk, msk, flags, sctrl);
1101 #define STAT afwMath::Statistics
1105 #define INSTANTIATE_MASKEDIMAGE_STATISTICS(TYPE) \
1106 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1107 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1108 afwImage::Image<VPixel> const &var, \
1109 int const flags, StatisticsControl const& sctrl); \
1110 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1111 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1112 afwImage::Image<VPixel> const &var, \
1113 afwImage::Image<VPixel> const &weights, \
1114 int const flags, StatisticsControl const& sctrl); \
1115 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1116 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1117 afwImage::Image<VPixel> const &var, \
1118 afwMath::ImageImposter<VPixel> const &weights, \
1119 int const flags, StatisticsControl const& sctrl)
1121 #define INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_MASK(TYPE) \
1122 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1123 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1124 afwImage::Image<VPixel> const &var, \
1125 int const flags, StatisticsControl const& sctrl); \
1126 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1127 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1128 afwImage::Image<VPixel> const &var, \
1129 afwImage::Image<VPixel> const &weights, \
1130 int const flags, StatisticsControl const& sctrl)
1132 #define INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_VAR(TYPE) \
1133 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1134 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1135 afwMath::MaskImposter<VPixel> const &var, \
1136 int const flags, StatisticsControl const& sctrl); \
1137 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1138 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1139 afwMath::MaskImposter<VPixel> const &var, \
1140 afwImage::Image<VPixel> const &weights, \
1141 int const flags, StatisticsControl const& sctrl); \
1142 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1143 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1144 afwMath::MaskImposter<VPixel> const &var, \
1145 afwMath::ImageImposter<VPixel> const &weights, \
1146 int const flags, StatisticsControl const& sctrl)
1148 #define INSTANTIATE_REGULARIMAGE_STATISTICS(TYPE) \
1149 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1150 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1151 afwMath::MaskImposter<VPixel> const &var, \
1152 int const flags, StatisticsControl const& sctrl)
1154 #define INSTANTIATE_VECTOR_STATISTICS(TYPE) \
1155 template STAT::Statistics(afwMath::ImageImposter<TYPE> const &img, \
1156 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1157 afwMath::MaskImposter<VPixel> const &var, \
1158 int const flags, StatisticsControl const& sctrl); \
1159 template STAT::Statistics(afwMath::ImageImposter<TYPE> const &img, \
1160 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1161 afwMath::MaskImposter<VPixel> const &var, \
1162 afwMath::ImageImposter<VPixel> const &weights, \
1163 int const flags, StatisticsControl const& sctrl)
1165 #define INSTANTIATE_IMAGE_STATISTICS(T) \
1166 INSTANTIATE_MASKEDIMAGE_STATISTICS(T); \
1167 INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_VAR(T); \
1168 INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_MASK(T); \
1169 INSTANTIATE_REGULARIMAGE_STATISTICS(T); \
1170 INSTANTIATE_VECTOR_STATISTICS(T)
1172 INSTANTIATE_IMAGE_STATISTICS(
double);
1173 INSTANTIATE_IMAGE_STATISTICS(
float);
1174 INSTANTIATE_IMAGE_STATISTICS(
int);
1175 INSTANTIATE_IMAGE_STATISTICS(boost::uint16_t);
1176 INSTANTIATE_IMAGE_STATISTICS(boost::uint64_t);
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
boost::uint16_t MaskPixel
double getMaskPropagationThreshold(int bit) const
std::pair< double, double > Value
The type used to report (value, error) for desired statistics.
x_iterator row_begin(int y) const
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
tbl::Key< double > weight
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
Statistics(ImageT const &img, MaskT const &msk, VarianceT const &var, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Constructor for Statistics object.
estimate sample standard deviation
find sum of pixels in the image
Value getResult(Property const prop=NOTHING) const
Return the value and error in the specified statistic (e.g. MEAN)
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
find mean value of square of pixel values
table::Key< table::Array< Kernel::Pixel > > image
Include errors of requested quantities.
We don't want anything.
int getWidth() const
Return the number of columns in the image.
Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calc...
void doStatistics(ImageT const &img, MaskT const &msk, VarianceT const &var, WeightT const &weights, int const flags, StatisticsControl const &sctrl)
Represent a 2-dimensional array of bitmask pixels.
bool getWeightedIsSet() const
float VariancePixel
! default type for Masks and MaskedImage Masks
double getError(Property const prop=NOTHING) const
Return the error in the desired property (if specified in the constructor)
#define LSST_EXCEPT(type,...)
void setMaskPropagationThreshold(int bit, double threshold)
void setWeighted(bool useWeights)
estimate sample inter-quartile range
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Compute Image Statistics.
get the or-mask of all pixels used.
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
int getHeight() const
Return the number of rows in the image.
Property
control what is calculated
A class to represent a 2-dimensional array of pixels.
Include files required for standard LSST Exception handling.