48 namespace afwMath = lsst::afw::math;
49 namespace afwGeom = lsst::afw::geom;
50 namespace pexExceptions = lsst::pex::exceptions;
53 double const NaN = std::numeric_limits<double>::quiet_NaN();
54 double const MAX_DOUBLE = std::numeric_limits<double>::max();
55 double const IQ_TO_STDEV = 0.741301109252802;
63 bool operator()(T)
const {
66 template<
typename Ta,
typename Tb>
67 bool operator()(Ta, Tb)
const {
70 template<
typename Ta,
typename Tb,
typename Tc>
71 bool operator()(Ta, Tb, Tc)
const {
82 bool operator()(T)
const {
85 template<
typename Ta,
typename Tb>
86 bool operator()(Ta, Tb)
const {
89 template<
typename Ta,
typename Tb,
typename Tc>
90 bool operator()(Ta, Tb, Tc)
const {
101 bool operator()(T
val)
const {
102 return std::isfinite(static_cast<float>(val));
109 class CheckValueLtMin {
111 template<
typename Tval,
typename Tmin>
112 bool operator()(Tval
val, Tmin min)
const {
113 return (static_cast<Tmin>(val) < min);
120 class CheckValueGtMax {
122 template<
typename Tval,
typename Tmax>
123 bool operator()(Tval val, Tmax max)
const {
124 return (static_cast<Tmax>(val) > max);
131 class CheckClipRange {
133 template<
typename Tval,
typename Tcen,
typename Tmax>
134 bool operator()(Tval val, Tcen center, Tmax cliplimit)
const {
135 Tmax tmp = fabs(val - center);
136 return (tmp <= cliplimit);
141 typedef CheckFinite ChkFin;
142 typedef CheckValueLtMin ChkMin;
143 typedef CheckValueGtMax ChkMax;
144 typedef CheckClipRange ChkClip;
145 typedef AlwaysTrue AlwaysT;
146 typedef AlwaysFalse AlwaysF;
150 inline double varianceError(
double const variance,
int const n)
152 return 2*(n - 1)*variance*variance/static_cast<double>(n*n);
157 typedef std::tuple<int,
179 template<
typename IsFinite,
180 typename HasValueLtMin,
181 typename HasValueGtMax,
182 typename InClipRange,
184 typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
185 StandardReturn processPixels(ImageT
const &img,
187 VarianceT
const &var,
188 WeightT
const &weights,
192 double const meanCrude,
193 double const cliplimit,
194 bool const weightsAreMultiplicative,
196 bool const calcErrorFromInputVariance,
197 std::vector<double>
const & maskPropagationThresholds
208 double min = (nCrude) ? meanCrude : MAX_DOUBLE;
209 double max = (nCrude) ? meanCrude : -MAX_DOUBLE;
213 std::vector<double> rejectedWeightsByBit(maskPropagationThresholds.size(), 0.0);
215 for (
int iY = 0; iY < img.getHeight(); iY += stride) {
217 typename MaskT::x_iterator mptr = msk.row_begin(iY);
218 typename VarianceT::x_iterator vptr = var.row_begin(iY);
219 typename WeightT::x_iterator wptr = weights.row_begin(iY);
221 for (
typename ImageT::x_iterator ptr = img.row_begin(iY), end = ptr + img.getWidth();
222 ptr != end; ++ptr, ++mptr, ++vptr, ++wptr) {
224 if (IsFinite()(*ptr) && !(*mptr & andMask) &&
225 InClipRange()(*ptr, meanCrude, cliplimit) ) {
227 double const delta = (*ptr - meanCrude);
231 if (weightsAreMultiplicative) {
242 sumx += weight*delta;
243 sumx2 += weight*delta*delta;
245 if (calcErrorFromInputVariance) {
246 double const var = *vptr;
247 sumvw2 += var*weight*
weight;
251 sumx2 += delta*delta;
253 if (calcErrorFromInputVariance) {
254 double const var = *vptr;
259 allPixelOrMask |= *mptr;
261 if (HasValueLtMin()(*ptr, min)) { min = *ptr; }
262 if (HasValueGtMax()(*ptr, max)) { max = *ptr; }
265 for (
int bit = 0, nBits=maskPropagationThresholds.size(); bit < nBits; ++bit) {
271 if (!weightsAreMultiplicative) {
278 rejectedWeightsByBit[bit] +=
weight;
290 double mean, variance;
295 for (
int bit = 0, nBits=maskPropagationThresholds.size(); bit < nBits; ++bit) {
296 double hypotheticalTotalWeight = sumw + rejectedWeightsByBit[bit];
297 rejectedWeightsByBit[bit] /= hypotheticalTotalWeight;
298 if (rejectedWeightsByBit[bit] > maskPropagationThresholds[bit]) {
299 allPixelOrMask |= (1 << bit);
308 variance = sumx2/sumw - ::pow(mean, 2);
309 variance *= sumw*sumw/(sumw*sumw - sumw2);
312 if (calcErrorFromInputVariance) {
313 meanVar = sumvw2/(sumw*sumw);
315 meanVar = variance*sumw2/(sumw*sumw);
318 double varVar = varianceError(variance, n);
320 sumx += sumw*meanCrude;
323 return StandardReturn(n, sumx,
328 template<
typename IsFinite,
329 typename HasValueLtMin,
330 typename HasValueGtMax,
331 typename InClipRange,
333 typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
334 StandardReturn processPixels(ImageT
const &img,
336 VarianceT
const &var,
337 WeightT
const &weights,
341 double const meanCrude,
342 double const cliplimit,
343 bool const weightsAreMultiplicative,
345 bool const calcErrorFromInputVariance,
347 std::vector<double>
const & maskPropagationThresholds
351 return processPixels<IsFinite, HasValueLtMin, HasValueGtMax, InClipRange, true>(
352 img, msk, var, weights,
353 flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative, andMask,
354 calcErrorFromInputVariance, maskPropagationThresholds);
356 return processPixels<IsFinite, HasValueLtMin, HasValueGtMax, InClipRange, false>(
357 img, msk, var, weights,
358 flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative, andMask,
359 calcErrorFromInputVariance, maskPropagationThresholds);
363 template<
typename IsFinite,
364 typename HasValueLtMin,
365 typename HasValueGtMax,
366 typename InClipRange,
368 typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
369 StandardReturn processPixels(ImageT
const &img,
371 VarianceT
const &var,
372 WeightT
const &weights,
376 double const meanCrude,
377 double const cliplimit,
378 bool const weightsAreMultiplicative,
380 bool const calcErrorFromInputVariance,
383 std::vector<double>
const & maskPropagationThresholds
387 return processPixels<CheckFinite, HasValueLtMin, HasValueGtMax, InClipRange, useWeights>(
388 img, msk, var, weights,
389 flags, nCrude, 1, meanCrude, cliplimit,
390 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
391 doGetWeighted, maskPropagationThresholds);
393 return processPixels<AlwaysTrue, HasValueLtMin, HasValueGtMax, InClipRange, useWeights>(
394 img, msk, var, weights,
395 flags, nCrude, 1, meanCrude, cliplimit,
396 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
397 doGetWeighted, maskPropagationThresholds);
409 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
410 StandardReturn getStandard(ImageT
const &img,
412 VarianceT
const &var,
413 WeightT
const &weights,
415 bool const weightsAreMultiplicative,
417 bool const calcErrorFromInputVariance,
420 std::vector<double>
const & maskPropagationThresholds
426 double meanCrude = 0.0;
429 int const nPix = img.getWidth()*img.getHeight();
437 double cliplimit = -1;
438 StandardReturn values = processPixels<ChkFin, AlwaysF, AlwaysF, AlwaysT, true>(
439 img, msk, var, weights,
440 flags, nCrude, strideCrude, meanCrude,
442 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
443 doCheckFinite, doGetWeighted,
444 maskPropagationThresholds);
445 nCrude = std::get<0>(values);
446 double sumCrude = std::get<1>(values);
450 meanCrude = sumCrude/nCrude;
458 return processPixels<ChkFin, ChkMin, ChkMax, AlwaysT, true>(
459 img, msk, var, weights,
460 flags, nCrude, 1, meanCrude,
462 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
463 true, doGetWeighted, maskPropagationThresholds);
465 return processPixels<ChkFin, AlwaysF, AlwaysF, AlwaysT,true>(
466 img, msk, var, weights,
467 flags, nCrude, 1, meanCrude,
469 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
470 doCheckFinite, doGetWeighted, maskPropagationThresholds);
479 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
480 StandardReturn getStandard(ImageT
const &img,
482 VarianceT
const &var,
483 WeightT
const &weights,
485 std::pair<double, double>
const clipinfo,
487 bool const weightsAreMultiplicative,
489 bool const calcErrorFromInputVariance,
492 std::vector<double>
const & maskPropagationThresholds
495 double const center = clipinfo.first;
496 double const cliplimit = clipinfo.second;
498 if (std::isnan(center) || std::isnan(cliplimit)) {
499 return StandardReturn(0,
NaN,
506 int const stride = 1;
510 return processPixels<ChkFin, ChkMin, ChkMax, ChkClip, true>(
511 img, msk, var, weights,
512 flags, nCrude, stride,
514 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
515 true, doGetWeighted, maskPropagationThresholds);
517 return processPixels<ChkFin, AlwaysF, AlwaysF, ChkClip, true>(
518 img, msk, var, weights,
519 flags, nCrude, stride,
521 weightsAreMultiplicative, andMask, calcErrorFromInputVariance,
522 doCheckFinite, doGetWeighted, maskPropagationThresholds);
534 template<
typename Pixel>
535 double percentile(std::vector<Pixel> &img,
536 double const fraction)
538 assert (fraction >= 0.0 && fraction <= 1.0);
540 int const n = img.size();
544 double const idx = fraction*(n - 1);
552 int const q1 =
static_cast<int>(idx);
553 int const q2 = q1 + 1;
555 typename std::vector<Pixel>::iterator mid1 = img.begin() + q1;
556 typename std::vector<Pixel>::iterator mid2 = img.begin() + q2;
557 if (fraction > 0.5) {
558 std::nth_element(img.begin(), mid1, img.end());
559 std::nth_element(mid1, mid2, img.end());
561 std::nth_element(img.begin(), mid2, img.end());
562 std::nth_element(img.begin(), mid1, mid2);
565 double val1 =
static_cast<double>(*mid1);
566 double val2 =
static_cast<double>(*mid2);
567 double w1 = (
static_cast<double>(q2) - idx);
568 double w2 = (idx -
static_cast<double>(q1));
569 return w1*val1 + w2*val2;
587 typedef std::tuple<double, double, double> MedianQuartileReturn;
589 template<
typename Pixel>
590 MedianQuartileReturn medianAndQuartiles(std::vector<Pixel> &img)
592 int const n = img.size();
596 double const idx50 = 0.50*(n - 1);
597 double const idx25 = 0.25*(n - 1);
598 double const idx75 = 0.75*(n - 1);
605 int const q50a =
static_cast<int>(idx50);
606 int const q50b = q50a + 1;
607 int const q25a =
static_cast<int>(idx25);
608 int const q25b = q25a + 1;
609 int const q75a =
static_cast<int>(idx75);
610 int const q75b = q75a + 1;
612 typename std::vector<Pixel>::iterator mid50a = img.begin() + q50a;
613 typename std::vector<Pixel>::iterator mid50b = img.begin() + q50b;
614 typename std::vector<Pixel>::iterator mid25a = img.begin() + q25a;
615 typename std::vector<Pixel>::iterator mid25b = img.begin() + q25b;
616 typename std::vector<Pixel>::iterator mid75a = img.begin() + q75a;
617 typename std::vector<Pixel>::iterator mid75b = img.begin() + q75b;
620 std::nth_element(img.begin(), mid50a, img.end());
621 std::nth_element(mid50a, mid75a, img.end());
622 std::nth_element(img.begin(), mid25a, mid50a);
625 std::nth_element(mid50a, mid50b, mid75a);
626 std::nth_element(mid25a, mid25b, mid50a);
627 std::nth_element(mid75a, mid75b, img.end());
630 double val50a =
static_cast<double>(*mid50a);
631 double val50b =
static_cast<double>(*mid50b);
632 double w50a = (
static_cast<double>(q50b) - idx50);
633 double w50b = (idx50 -
static_cast<double>(q50a));
634 double median = w50a*val50a + w50b*val50b;
636 double val25a =
static_cast<double>(*mid25a);
637 double val25b =
static_cast<double>(*mid25b);
638 double w25a = (
static_cast<double>(q25b) - idx25);
639 double w25b = (idx25 -
static_cast<double>(q25a));
640 double q1 = w25a*val25a + w25b*val25b;
642 double val75a =
static_cast<double>(*mid75a);
643 double val75b =
static_cast<double>(*mid75b);
644 double w75a = (
static_cast<double>(q75b) - idx75);
645 double w75b = (idx75 -
static_cast<double>(q75a));
646 double q3 = w75a*val75a + w75b*val75b;
648 return MedianQuartileReturn(median, q1, q3);
650 return MedianQuartileReturn(img[0], img[0], img[0]);
652 return MedianQuartileReturn(
NaN,
NaN,
NaN);
664 template<
typename IsFinite,
typename ImageT,
typename MaskT,
typename VarianceT>
665 std::shared_ptr<std::vector<typename ImageT::Pixel> > makeVectorCopy(ImageT
const &img,
673 std::shared_ptr<std::vector<typename ImageT::Pixel> >
674 imgcp(
new std::vector<typename ImageT::Pixel>(0));
676 for (
int i_y = 0; i_y < img.getHeight(); ++i_y) {
677 typename MaskT::x_iterator mptr = msk.row_begin(i_y);
678 for (
typename ImageT::x_iterator ptr = img.row_begin(i_y), end = img.row_end(i_y);
680 if (IsFinite()(*ptr) && !(*mptr & andMask)) {
681 imgcp->push_back(*ptr);
694 int oldSize = _maskPropagationThresholds.size();
698 return _maskPropagationThresholds[bit];
702 int oldSize = _maskPropagationThresholds.size();
703 if (oldSize <= bit) {
704 int newSize = bit + 1;
705 _maskPropagationThresholds.resize(newSize);
706 for (
int i = oldSize; i < bit; ++i) {
707 _maskPropagationThresholds[i] = 1.0;
710 _maskPropagationThresholds[bit] = threshold;
718 static std::map<std::string, Property> statisticsProperty;
719 if (statisticsProperty.size() == 0) {
720 statisticsProperty[
"NOTHING"] =
NOTHING;
721 statisticsProperty[
"ERRORS"] =
ERRORS;
722 statisticsProperty[
"NPOINT"] =
NPOINT;
723 statisticsProperty[
"MEAN"] =
MEAN;
724 statisticsProperty[
"STDEV"] =
STDEV;
725 statisticsProperty[
"VARIANCE"] =
VARIANCE;
726 statisticsProperty[
"MEDIAN"] =
MEDIAN;
727 statisticsProperty[
"IQRANGE"] =
IQRANGE;
728 statisticsProperty[
"MEANCLIP"] =
MEANCLIP;
729 statisticsProperty[
"STDEVCLIP"] =
STDEVCLIP;
731 statisticsProperty[
"MIN"] =
MIN;
732 statisticsProperty[
"MAX"] =
MAX;
733 statisticsProperty[
"SUM"] =
SUM;
734 statisticsProperty[
"MEANSQUARE"] =
MEANSQUARE;
735 statisticsProperty[
"ORMASK"] =
ORMASK;
737 return statisticsProperty[property];
747 template<
typename ImageT,
typename MaskT,
typename VarianceT>
751 VarianceT
const &var,
757 _sctrl(sctrl), _weightsAreMultiplicative(false)
764 bool isEmpty(T
const& t) {
return t.empty(); }
770 template<
typename ImageT1,
typename ImageT2>
771 void checkDimensions(ImageT1
const& image1, ImageT2
const& image2)
773 if (image1.getDimensions() != image2.getDimensions()) {
774 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
776 image1.getDimensions() % image2.getDimensions()).str());
781 template<
typename ImageT,
typename PixelT>
783 template<
typename ImageT,
typename PixelT>
788 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
792 VarianceT
const &var,
793 WeightT
const &weights,
799 _sctrl(sctrl), _weightsAreMultiplicative(true)
801 if (!isEmpty(weights)) {
803 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
804 "You must use the weights if you provide them");
812 template<
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
816 VarianceT
const &var,
817 WeightT
const &weights,
822 _n = img.getWidth()*img.getHeight();
824 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Image contains no pixels");
826 checkDimensions(img, msk);
827 checkDimensions(img, var);
829 checkDimensions(img, weights);
833 assert(img.getWidth()*
static_cast<double>(img.getHeight()) < std::numeric_limits<int>::max());
836 StandardReturn standard = getStandard(img, msk, var, weights, flags,
837 _weightsAreMultiplicative,
839 _sctrl.getCalcErrorFromInputVariance(),
840 _sctrl.getNanSafe(), _sctrl.getWeighted(),
841 _sctrl._maskPropagationThresholds);
843 _n = std::get<0>(standard);
844 _sum = std::get<1>(standard);
845 _mean = std::get<2>(standard);
846 _variance = std::get<3>(standard);
847 _min = std::get<4>(standard);
848 _max = std::get<5>(standard);
849 _allPixelOrMask = std::get<6>(standard);
858 std::shared_ptr<std::vector<typename ImageT::Pixel> > imgcp;
859 if (_sctrl.getNanSafe()) {
860 imgcp = makeVectorCopy<ChkFin>(img, msk, var, _sctrl.getAndMask());
862 imgcp = makeVectorCopy<AlwaysT>(img, msk, var, _sctrl.getAndMask());
867 _median =
Value(percentile(*imgcp, 0.5),
NaN);
869 MedianQuartileReturn mq = medianAndQuartiles(*imgcp);
870 _median =
Value(std::get<0>(mq),
NaN);
871 _iqrange = std::get<2>(mq) - std::get<1>(mq);
876 for (
int i_i = 0; i_i < _sctrl.getNumIter(); ++i_i) {
877 double const center = ((i_i > 0) ? _meanclip : _median).first;
878 double const hwidth = (i_i > 0 && _n > 1) ?
879 _sctrl.getNumSigmaClip()*std::sqrt(_varianceclip.first) :
880 _sctrl.getNumSigmaClip()*IQ_TO_STDEV*_iqrange;
881 std::pair<double, double>
const clipinfo(center, hwidth);
883 StandardReturn clipped = getStandard(img, msk, var, weights, flags, clipinfo,
884 _weightsAreMultiplicative,
886 _sctrl.getCalcErrorFromInputVariance(),
887 _sctrl.getNanSafe(), _sctrl.getWeighted(),
888 _sctrl._maskPropagationThresholds);
890 int const nClip = std::get<0>(clipped);
891 _meanclip = std::get<2>(clipped);
892 double const varClip = std::get<3>(clipped).first;
894 _varianceclip =
Value(varClip, varianceError(varClip, nClip));
923 if (!(prop & _flags)) {
924 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
925 (
boost::format(
"You didn't ask me to calculate %d") % prop).str());
933 ret.first =
static_cast<double>(
_n);
940 ret.first =
static_cast<double>(
_sum);
941 if (_flags & ERRORS) {
948 ret.first = _mean.first;
949 if (_flags & ERRORS) {
950 ret.second = ::sqrt(_mean.second);
954 ret.first = _meanclip.first;
955 if ( _flags & ERRORS ) {
956 ret.second = ::sqrt(_meanclip.second);
962 ret.first = _variance.first;
963 if (_flags & ERRORS) {
964 ret.second = ::sqrt(_variance.second);
968 ret.first = sqrt(_variance.first);
969 if (_flags & ERRORS) {
970 ret.second = 0.5*::sqrt(_variance.second)/ret.first;
974 ret.first = _varianceclip.first;
975 if (_flags & ERRORS) {
976 ret.second = ret.second;
980 ret.first = sqrt(_varianceclip.first);
981 if (_flags & ERRORS) {
982 ret.second = 0.5*::sqrt(_varianceclip.second)/ret.first;
987 ret.first = (
_n - 1)/static_cast<double>(
_n)*_variance.first + ::pow(_mean.first, 2);
988 if (_flags & ERRORS) {
989 ret.second = ::sqrt(2*::pow(ret.first/
_n, 2));
996 if ( _flags & ERRORS ) {
1002 if ( _flags & ERRORS ) {
1007 ret.first = _median.first;
1008 if ( _flags & ERRORS ) {
1013 ret.first = _iqrange;
1014 if ( _flags & ERRORS ) {
1024 assert (iProp == 0);
1025 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
1026 "getValue() may only be called without a parameter"
1027 " if you asked for only one statistic");
1039 return getResult(prop).first;
1051 return getResult(prop).second;
1078 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Statistics<Mask> only supports NPOINT and SUM");
1085 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Image contains no pixels");
1089 assert(msk.
getWidth()*
static_cast<double>(msk.
getHeight()) < std::numeric_limits<int>::max());
1093 for (Mask::x_iterator ptr = msk.
row_begin(
y), end = msk.
row_end(
y); ptr != end; ++ptr) {
1112 return Statistics(msk, msk, msk, flags, sctrl);
1126 #define STAT afwMath::Statistics
1130 #define INSTANTIATE_MASKEDIMAGE_STATISTICS(TYPE) \
1131 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1132 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1133 afwImage::Image<VPixel> const &var, \
1134 int const flags, StatisticsControl const& sctrl); \
1135 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1136 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1137 afwImage::Image<VPixel> const &var, \
1138 afwImage::Image<VPixel> const &weights, \
1139 int const flags, StatisticsControl const& sctrl); \
1140 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1141 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1142 afwImage::Image<VPixel> const &var, \
1143 afwMath::ImageImposter<VPixel> const &weights, \
1144 int const flags, StatisticsControl const& sctrl)
1146 #define INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_MASK(TYPE) \
1147 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1148 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1149 afwImage::Image<VPixel> const &var, \
1150 int const flags, StatisticsControl const& sctrl); \
1151 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1152 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1153 afwImage::Image<VPixel> const &var, \
1154 afwImage::Image<VPixel> const &weights, \
1155 int const flags, StatisticsControl const& sctrl)
1157 #define INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_VAR(TYPE) \
1158 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1159 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1160 afwMath::MaskImposter<VPixel> const &var, \
1161 int const flags, StatisticsControl const& sctrl); \
1162 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1163 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1164 afwMath::MaskImposter<VPixel> const &var, \
1165 afwImage::Image<VPixel> const &weights, \
1166 int const flags, StatisticsControl const& sctrl); \
1167 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1168 afwImage::Mask<afwImage::MaskPixel> const &msk, \
1169 afwMath::MaskImposter<VPixel> const &var, \
1170 afwMath::ImageImposter<VPixel> const &weights, \
1171 int const flags, StatisticsControl const& sctrl)
1173 #define INSTANTIATE_REGULARIMAGE_STATISTICS(TYPE) \
1174 template STAT::Statistics(afwImage::Image<TYPE> const &img, \
1175 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1176 afwMath::MaskImposter<VPixel> const &var, \
1177 int const flags, StatisticsControl const& sctrl)
1179 #define INSTANTIATE_VECTOR_STATISTICS(TYPE) \
1180 template STAT::Statistics(afwMath::ImageImposter<TYPE> const &img, \
1181 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1182 afwMath::MaskImposter<VPixel> const &var, \
1183 int const flags, StatisticsControl const& sctrl); \
1184 template STAT::Statistics(afwMath::ImageImposter<TYPE> const &img, \
1185 afwMath::MaskImposter<afwImage::MaskPixel> const &msk, \
1186 afwMath::MaskImposter<VPixel> const &var, \
1187 afwMath::ImageImposter<VPixel> const &weights, \
1188 int const flags, StatisticsControl const& sctrl)
1190 #define INSTANTIATE_IMAGE_STATISTICS(T) \
1191 INSTANTIATE_MASKEDIMAGE_STATISTICS(T); \
1192 INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_VAR(T); \
1193 INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_MASK(T); \
1194 INSTANTIATE_REGULARIMAGE_STATISTICS(T); \
1195 INSTANTIATE_VECTOR_STATISTICS(T)
1197 INSTANTIATE_IMAGE_STATISTICS(
double);
1198 INSTANTIATE_IMAGE_STATISTICS(
float);
1199 INSTANTIATE_IMAGE_STATISTICS(
int);
1200 INSTANTIATE_IMAGE_STATISTICS(std::uint16_t);
1201 INSTANTIATE_IMAGE_STATISTICS(std::uint64_t);
tbl::Key< double > weight
get the or-mask of all pixels used.
void doStatistics(ImageT const &img, MaskT const &msk, VarianceT const &var, WeightT const &weights, int const flags, StatisticsControl const &sctrl)
Include files required for standard LSST Exception handling.
estimate sample standard deviation
find mean value of square of pixel values
void setMaskPropagationThreshold(int bit, double threshold)
When pixels with the given bit are rejected, we count what fraction the rejected pixels would have co...
We don't want anything.
Include errors of requested quantities.
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.
table::Key< table::Array< Kernel::Pixel > > image
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.
metadata import lsst afw display as afwDisplay n
Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calc...
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Represent a 2-dimensional array of bitmask pixels.
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
estimate sample N-sigma clipped variance (N set in StatisticsControl, default=3)
A Mask wrapper to provide an infinite_iterator for Mask::row_begin().
int getHeight() const
Return the number of rows in the image.
void setWeighted(bool useWeights)
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Value getResult(Property const prop=NOTHING) const
Return the value and error in the specified statistic (e.g.
estimate sample inter-quartile range
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...
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Compute Image Statistics.
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
find sum of pixels in the image
float VariancePixel
! default type for Masks and MaskedImage Masks
Property
control what is calculated
int getWidth() const
Return the number of columns in the image.
A class to represent a 2-dimensional array of pixels.
bool getWeightedIsSet() const