36 #include "lsst/pex/exceptions.h" 42 namespace pexExceptions = lsst::pex::exceptions;
49 double const NaN = std::numeric_limits<double>::quiet_NaN();
51 double const IQ_TO_STDEV = 0.741301109252802;
57 bool operator()(T)
const {
60 template <
typename Ta,
typename Tb>
61 bool operator()(Ta, Tb)
const {
64 template <
typename Ta,
typename Tb,
typename Tc>
65 bool operator()(Ta, Tb, Tc)
const {
74 bool operator()(T)
const {
77 template <
typename Ta,
typename Tb>
78 bool operator()(Ta, Tb)
const {
81 template <
typename Ta,
typename Tb,
typename Tc>
82 bool operator()(Ta, Tb, Tc)
const {
91 bool operator()(T val)
const {
92 return std::isfinite(static_cast<float>(val));
97 class CheckValueLtMin {
99 template <
typename Tval,
typename Tmin>
100 bool operator()(Tval val, Tmin
min)
const {
101 return (static_cast<Tmin>(val) < min);
106 class CheckValueGtMax {
108 template <
typename Tval,
typename Tmax>
109 bool operator()(Tval val, Tmax
max)
const {
110 return (static_cast<Tmax>(val) > max);
115 class CheckClipRange {
117 template <
typename Tval,
typename Tcen,
typename Tmax>
118 bool operator()(Tval val, Tcen center, Tmax cliplimit)
const {
119 Tmax tmp = fabs(val - center);
120 return (tmp <= cliplimit);
125 typedef CheckFinite ChkFin;
126 typedef CheckValueLtMin ChkMin;
127 typedef CheckValueGtMax ChkMax;
128 typedef CheckClipRange ChkClip;
129 typedef AlwaysTrue AlwaysT;
130 typedef AlwaysFalse AlwaysF;
135 inline double varianceError(
double const variance,
int const n) {
136 return 2 * (n - 1) * variance * variance / static_cast<double>(n * n);
140 typedef std::tuple<int,
163 template <
typename IsFinite,
typename HasValueLtMin,
typename HasValueGtMax,
typename InClipRange,
164 bool useWeights,
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
165 StandardReturn processPixels(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
166 WeightT
const &weights,
int const,
int const nCrude,
int const stride,
167 double const meanCrude,
double const cliplimit,
168 bool const weightsAreMultiplicative,
int const andMask,
169 bool const calcErrorFromInputVariance,
170 std::vector<double>
const &maskPropagationThresholds) {
179 double min = (nCrude) ? meanCrude : MAX_DOUBLE;
180 double max = (nCrude) ? meanCrude : -MAX_DOUBLE;
184 std::vector<double> rejectedWeightsByBit(maskPropagationThresholds.size(), 0.0);
186 for (
int iY = 0; iY < img.getHeight(); iY += stride) {
187 typename MaskT::x_iterator mptr = msk.row_begin(iY);
188 typename VarianceT::x_iterator vptr = var.row_begin(iY);
189 typename WeightT::x_iterator wptr = weights.row_begin(iY);
191 for (
typename ImageT::x_iterator ptr = img.row_begin(iY),
end = ptr + img.getWidth(); ptr !=
end;
192 ++ptr, ++mptr, ++vptr, ++wptr) {
193 if (IsFinite()(*ptr) && !(*mptr & andMask) &&
194 InClipRange()(*ptr, meanCrude, cliplimit)) {
196 double const delta = (*ptr - meanCrude);
199 double weight = *wptr;
200 if (weightsAreMultiplicative) {
210 sumw2 += weight * weight;
211 sumx += weight * delta;
212 sumx2 += weight * delta * delta;
214 if (calcErrorFromInputVariance) {
215 double const var = *vptr;
216 sumvw2 += var * weight * weight;
220 sumx2 += delta * delta;
222 if (calcErrorFromInputVariance) {
223 double const var = *vptr;
228 allPixelOrMask |= *mptr;
230 if (HasValueLtMin()(*ptr,
min)) {
233 if (HasValueGtMax()(*ptr,
max)) {
238 for (
int bit = 0, nBits = maskPropagationThresholds.size(); bit < nBits; ++bit) {
244 if (!weightsAreMultiplicative) {
248 weight = 1.0 / weight;
251 rejectedWeightsByBit[bit] += weight;
268 for (
int bit = 0, nBits = maskPropagationThresholds.size(); bit < nBits; ++bit) {
269 double hypotheticalTotalWeight = sumw + rejectedWeightsByBit[bit];
270 rejectedWeightsByBit[bit] /= hypotheticalTotalWeight;
271 if (rejectedWeightsByBit[bit] > maskPropagationThresholds[bit]) {
272 allPixelOrMask |= (1 << bit);
280 variance = sumx2 / sumw - ::pow(mean, 2);
281 variance *= sumw * sumw / (sumw * sumw - sumw2);
284 if (calcErrorFromInputVariance) {
285 meanVar = sumvw2 / (sumw * sumw);
287 meanVar = variance * sumw2 / (sumw * sumw);
290 double varVar = varianceError(variance, n);
292 sumx += sumw * meanCrude;
295 return StandardReturn(n, sumx, Statistics::Value(mean, meanVar), Statistics::Value(variance, varVar), min,
296 max, allPixelOrMask);
299 template <
typename IsFinite,
typename HasValueLtMin,
typename HasValueGtMax,
typename InClipRange,
300 bool useWeights,
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
301 StandardReturn processPixels(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
302 WeightT
const &weights,
int const flags,
int const nCrude,
int const stride,
303 double const meanCrude,
double const cliplimit,
304 bool const weightsAreMultiplicative,
int const andMask,
305 bool const calcErrorFromInputVariance,
bool doGetWeighted,
306 std::vector<double>
const &maskPropagationThresholds) {
308 return processPixels<IsFinite, HasValueLtMin, HasValueGtMax, InClipRange, true>(
309 img, msk, var, weights, flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative,
310 andMask, calcErrorFromInputVariance, maskPropagationThresholds);
312 return processPixels<IsFinite, HasValueLtMin, HasValueGtMax, InClipRange, false>(
313 img, msk, var, weights, flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative,
314 andMask, calcErrorFromInputVariance, maskPropagationThresholds);
318 template <
typename IsFinite,
typename HasValueLtMin,
typename HasValueGtMax,
typename InClipRange,
319 bool useWeights,
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
320 StandardReturn processPixels(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
321 WeightT
const &weights,
int const flags,
int const nCrude,
int const stride,
322 double const meanCrude,
double const cliplimit,
323 bool const weightsAreMultiplicative,
int const andMask,
324 bool const calcErrorFromInputVariance,
bool doCheckFinite,
bool doGetWeighted,
325 std::vector<double>
const &maskPropagationThresholds) {
327 return processPixels<CheckFinite, HasValueLtMin, HasValueGtMax, InClipRange, useWeights>(
328 img, msk, var, weights, flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative,
329 andMask, calcErrorFromInputVariance, doGetWeighted, maskPropagationThresholds);
331 return processPixels<AlwaysTrue, HasValueLtMin, HasValueGtMax, InClipRange, useWeights>(
332 img, msk, var, weights, flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative,
333 andMask, calcErrorFromInputVariance, doGetWeighted, maskPropagationThresholds);
354 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
355 StandardReturn getStandard(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
356 int const flags,
bool const weightsAreMultiplicative,
int const andMask,
357 bool const calcErrorFromInputVariance,
bool doCheckFinite,
bool doGetWeighted,
358 std::vector<double>
const &maskPropagationThresholds) {
362 double meanCrude = 0.0;
365 int const nPix = img.getWidth() * img.getHeight();
373 double cliplimit = -1;
374 StandardReturn values = processPixels<ChkFin, AlwaysF, AlwaysF, AlwaysT, true>(
375 img, msk, var, weights, flags, nCrude, strideCrude, meanCrude, cliplimit,
376 weightsAreMultiplicative, andMask, calcErrorFromInputVariance, doCheckFinite, doGetWeighted,
377 maskPropagationThresholds);
378 nCrude = std::get<0>(values);
379 double sumCrude = std::get<1>(values);
383 meanCrude = sumCrude / nCrude;
390 if (flags & (
MIN |
MAX)) {
391 return processPixels<ChkFin, ChkMin, ChkMax, AlwaysT, true>(
392 img, msk, var, weights, flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative,
393 andMask, calcErrorFromInputVariance,
true, doGetWeighted, maskPropagationThresholds);
395 return processPixels<ChkFin, AlwaysF, AlwaysF, AlwaysT, true>(
396 img, msk, var, weights, flags, nCrude, 1, meanCrude, cliplimit, weightsAreMultiplicative,
397 andMask, calcErrorFromInputVariance, doCheckFinite, doGetWeighted, maskPropagationThresholds);
419 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
420 StandardReturn getStandard(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
421 int const flags, std::pair<double, double>
const clipinfo,
423 bool const weightsAreMultiplicative,
int const andMask,
424 bool const calcErrorFromInputVariance,
bool doCheckFinite,
bool doGetWeighted,
425 std::vector<double>
const &maskPropagationThresholds) {
426 double const center = clipinfo.first;
427 double const cliplimit = clipinfo.second;
429 if (std::isnan(center) || std::isnan(cliplimit)) {
430 return StandardReturn(0, NaN, Statistics::Value(NaN, NaN), Statistics::Value(NaN, NaN), NaN, NaN,
436 int const stride = 1;
439 if (flags & (
MIN |
MAX)) {
440 return processPixels<ChkFin, ChkMin, ChkMax, ChkClip, true>(
441 img, msk, var, weights, flags, nCrude, stride, center, cliplimit, weightsAreMultiplicative,
442 andMask, calcErrorFromInputVariance,
true, doGetWeighted, maskPropagationThresholds);
444 return processPixels<ChkFin, AlwaysF, AlwaysF, ChkClip, true>(
445 img, msk, var, weights, flags, nCrude, stride, center, cliplimit, weightsAreMultiplicative,
446 andMask, calcErrorFromInputVariance, doCheckFinite, doGetWeighted, maskPropagationThresholds);
457 template <
typename Pixel>
458 double percentile(std::vector<Pixel> &img,
double const fraction) {
459 assert(fraction >= 0.0 && fraction <= 1.0);
461 int const n = img.size();
464 double const idx = fraction * (n - 1);
472 int const q1 =
static_cast<int>(idx);
473 int const q2 = q1 + 1;
475 typename std::vector<Pixel>::iterator mid1 = img.begin() + q1;
476 typename std::vector<Pixel>::iterator mid2 = img.begin() + q2;
477 if (fraction > 0.5) {
478 std::nth_element(img.begin(), mid1, img.end());
479 std::nth_element(mid1, mid2, img.end());
481 std::nth_element(img.begin(), mid2, img.end());
482 std::nth_element(img.begin(), mid1, mid2);
485 double val1 =
static_cast<double>(*mid1);
486 double val2 =
static_cast<double>(*mid2);
487 double w1 = (
static_cast<double>(q2) - idx);
488 double w2 = (idx -
static_cast<double>(q1));
489 return w1 * val1 + w2 * val2;
498 typedef std::tuple<double, double, double> MedianQuartileReturn;
505 template <
typename Pixel>
506 MedianQuartileReturn medianAndQuartiles(std::vector<Pixel> &img) {
507 int const n = img.size();
510 double const idx50 = 0.50 * (n - 1);
511 double const idx25 = 0.25 * (n - 1);
512 double const idx75 = 0.75 * (n - 1);
519 int const q50a =
static_cast<int>(idx50);
520 int const q50b = q50a + 1;
521 int const q25a =
static_cast<int>(idx25);
522 int const q25b = q25a + 1;
523 int const q75a =
static_cast<int>(idx75);
524 int const q75b = q75a + 1;
526 typename std::vector<Pixel>::iterator mid50a = img.begin() + q50a;
527 typename std::vector<Pixel>::iterator mid50b = img.begin() + q50b;
528 typename std::vector<Pixel>::iterator mid25a = img.begin() + q25a;
529 typename std::vector<Pixel>::iterator mid25b = img.begin() + q25b;
530 typename std::vector<Pixel>::iterator mid75a = img.begin() + q75a;
531 typename std::vector<Pixel>::iterator mid75b = img.begin() + q75b;
534 std::nth_element(img.begin(), mid50a, img.end());
535 std::nth_element(mid50a, mid75a, img.end());
536 std::nth_element(img.begin(), mid25a, mid50a);
539 std::nth_element(mid50a, mid50b, mid75a);
540 std::nth_element(mid25a, mid25b, mid50a);
541 std::nth_element(mid75a, mid75b, img.end());
544 double val50a =
static_cast<double>(*mid50a);
545 double val50b =
static_cast<double>(*mid50b);
546 double w50a = (
static_cast<double>(q50b) - idx50);
547 double w50b = (idx50 -
static_cast<double>(q50a));
548 double median = w50a * val50a + w50b * val50b;
550 double val25a =
static_cast<double>(*mid25a);
551 double val25b =
static_cast<double>(*mid25b);
552 double w25a = (
static_cast<double>(q25b) - idx25);
553 double w25b = (idx25 -
static_cast<double>(q25a));
554 double q1 = w25a * val25a + w25b * val25b;
556 double val75a =
static_cast<double>(*mid75a);
557 double val75b =
static_cast<double>(*mid75b);
558 double w75a = (
static_cast<double>(q75b) - idx75);
559 double w75b = (idx75 -
static_cast<double>(q75a));
560 double q3 = w75a * val75a + w75b * val75b;
562 return MedianQuartileReturn(median, q1, q3);
564 return MedianQuartileReturn(img[0], img[0], img[0]);
566 return MedianQuartileReturn(NaN, NaN, NaN);
577 template <
typename IsFinite,
typename ImageT,
typename MaskT,
typename VarianceT>
578 std::shared_ptr<std::vector<typename ImageT::Pixel> > makeVectorCopy(ImageT
const &img, MaskT
const &msk,
579 VarianceT
const &,
int const andMask) {
582 std::shared_ptr<std::vector<typename ImageT::Pixel> > imgcp(
new std::vector<typename ImageT::Pixel>(0));
584 for (
int i_y = 0; i_y < img.getHeight(); ++i_y) {
585 typename MaskT::x_iterator mptr = msk.row_begin(i_y);
586 for (
typename ImageT::x_iterator ptr = img.row_begin(i_y),
end = img.row_end(i_y); ptr !=
end;
588 if (IsFinite()(*ptr) && !(*mptr & andMask)) {
589 imgcp->push_back(*ptr);
599 double StatisticsControl::getMaskPropagationThreshold(
int bit)
const {
600 int oldSize = _maskPropagationThresholds.size();
604 return _maskPropagationThresholds[bit];
607 void StatisticsControl::setMaskPropagationThreshold(
int bit,
double threshold) {
608 int oldSize = _maskPropagationThresholds.size();
609 if (oldSize <= bit) {
610 int newSize = bit + 1;
611 _maskPropagationThresholds.resize(newSize);
612 for (
int i = oldSize; i < bit; ++i) {
613 _maskPropagationThresholds[i] = 1.0;
616 _maskPropagationThresholds[bit] = threshold;
620 static std::map<std::string, Property> statisticsProperty;
621 if (statisticsProperty.size() == 0) {
622 statisticsProperty[
"NOTHING"] =
NOTHING;
623 statisticsProperty[
"ERRORS"] =
ERRORS;
624 statisticsProperty[
"NPOINT"] =
NPOINT;
625 statisticsProperty[
"MEAN"] =
MEAN;
626 statisticsProperty[
"STDEV"] =
STDEV;
627 statisticsProperty[
"VARIANCE"] =
VARIANCE;
628 statisticsProperty[
"MEDIAN"] =
MEDIAN;
629 statisticsProperty[
"IQRANGE"] =
IQRANGE;
630 statisticsProperty[
"MEANCLIP"] =
MEANCLIP;
631 statisticsProperty[
"STDEVCLIP"] =
STDEVCLIP;
633 statisticsProperty[
"MIN"] =
MIN;
634 statisticsProperty[
"MAX"] =
MAX;
635 statisticsProperty[
"SUM"] =
SUM;
636 statisticsProperty[
"MEANSQUARE"] =
MEANSQUARE;
637 statisticsProperty[
"ORMASK"] =
ORMASK;
639 return statisticsProperty[property];
642 template <
typename ImageT,
typename MaskT,
typename VarianceT>
643 Statistics::Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
int const flags,
652 _varianceclip(NaN, NaN),
656 _weightsAreMultiplicative(false) {
657 doStatistics(img, msk, var, var, _flags, _sctrl);
661 template <
typename T>
662 bool isEmpty(T
const &t) {
666 template <
typename T>
672 template <
typename ImageT1,
typename ImageT2>
673 void checkDimensions(ImageT1
const &image1, ImageT2
const &image2) {
674 if (image1.getDimensions() != image2.getDimensions()) {
675 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
676 (boost::format(
"Image sizes don't match: %s vs %s") % image1.getDimensions() %
677 image2.getDimensions())
683 template <
typename ImageT,
typename PixelT>
685 template <
typename ImageT,
typename PixelT>
689 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
699 _varianceclip(NaN, NaN),
703 _weightsAreMultiplicative(true) {
704 if (!isEmpty(weights)) {
706 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
707 "You must use the weights if you provide them");
712 doStatistics(img, msk, var, weights, _flags, _sctrl);
715 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
716 void Statistics::doStatistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
718 _n = img.getWidth() * img.getHeight();
720 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Image contains no pixels");
722 checkDimensions(img, msk);
723 checkDimensions(img, var);
725 checkDimensions(img, weights);
732 StandardReturn standard =
733 getStandard(img, msk, var, weights, flags, _weightsAreMultiplicative, _sctrl.
getAndMask(),
735 _sctrl._maskPropagationThresholds);
737 _n = std::get<0>(standard);
738 _sum = std::get<1>(standard);
739 _mean = std::get<2>(standard);
740 _variance = std::get<3>(standard);
741 _min = std::get<4>(standard);
742 _max = std::get<5>(standard);
743 _allPixelOrMask = std::get<6>(standard);
751 std::shared_ptr<std::vector<typename ImageT::Pixel> > imgcp;
753 imgcp = makeVectorCopy<ChkFin>(img, msk, var, _sctrl.
getAndMask());
755 imgcp = makeVectorCopy<AlwaysT>(img, msk, var, _sctrl.
getAndMask());
760 _median =
Value(percentile(*imgcp, 0.5), NaN);
762 MedianQuartileReturn mq = medianAndQuartiles(*imgcp);
763 _median =
Value(std::get<0>(mq), NaN);
764 _iqrange = std::get<2>(mq) - std::get<1>(mq);
768 for (
int i_i = 0; i_i < _sctrl.
getNumIter(); ++i_i) {
769 double const center = ((i_i > 0) ? _meanclip : _median).first;
770 double const hwidth = (i_i > 0 && _n > 1)
773 std::pair<double, double>
const clipinfo(center, hwidth);
775 StandardReturn clipped = getStandard(
776 img, msk, var, weights, flags, clipinfo, _weightsAreMultiplicative,
778 _sctrl.
getWeighted(), _sctrl._maskPropagationThresholds);
780 int const nClip = std::get<0>(clipped);
781 _meanclip = std::get<2>(clipped);
782 double const varClip = std::get<3>(clipped).
first;
784 _varianceclip =
Value(varClip, varianceError(varClip, nClip));
795 if (!(prop & _flags)) {
796 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
797 (boost::format(
"You didn't ask me to calculate %d") % prop).str());
803 ret.first =
static_cast<double>(_n);
810 ret.first =
static_cast<double>(_sum);
811 if (_flags & ERRORS) {
818 ret.first = _mean.first;
819 if (_flags & ERRORS) {
820 ret.second = ::sqrt(_mean.second);
824 ret.first = _meanclip.first;
825 if (_flags & ERRORS) {
826 ret.second = ::sqrt(_meanclip.second);
832 ret.first = _variance.first;
833 if (_flags & ERRORS) {
834 ret.second = ::sqrt(_variance.second);
838 ret.first = sqrt(_variance.first);
839 if (_flags & ERRORS) {
840 ret.second = 0.5 * ::sqrt(_variance.second) / ret.first;
844 ret.first = _varianceclip.first;
845 if (_flags & ERRORS) {
846 ret.second = ret.second;
850 ret.first = sqrt(_varianceclip.first);
851 if (_flags & ERRORS) {
852 ret.second = 0.5 * ::sqrt(_varianceclip.second) / ret.first;
857 ret.first = (_n - 1) / static_cast<double>(_n) * _variance.first + ::pow(_mean.first, 2);
858 if (_flags & ERRORS) {
859 ret.second = ::sqrt(2 * ::pow(ret.first / _n, 2));
866 if (_flags & ERRORS) {
872 if (_flags & ERRORS) {
877 ret.first = _median.first;
878 if (_flags & ERRORS) {
883 ret.first = _iqrange;
884 if (_flags & ERRORS) {
895 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
896 "getValue() may only be called without a parameter" 897 " if you asked for only one statistic");
925 _varianceclip(NaN, NaN),
930 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
931 "Statistics<Mask> only supports NPOINT and SUM");
938 throw LSST_EXCEPT(pexExceptions::InvalidParameterError,
"Image contains no pixels");
945 for (
int y = 0; y != msk.
getHeight(); ++y) {
960 return Statistics(msk, msk, msk, flags, sctrl);
971 #define STAT Statistics 975 #define INSTANTIATE_MASKEDIMAGE_STATISTICS(TYPE) \ 976 template STAT::Statistics(image::Image<TYPE> const &img, image::Mask<image::MaskPixel> const &msk, \ 977 image::Image<VPixel> const &var, int const flags, \ 978 StatisticsControl const &sctrl); \ 979 template STAT::Statistics(image::Image<TYPE> const &img, image::Mask<image::MaskPixel> const &msk, \ 980 image::Image<VPixel> const &var, image::Image<VPixel> const &weights, \ 981 int const flags, StatisticsControl const &sctrl); \ 982 template STAT::Statistics(image::Image<TYPE> const &img, image::Mask<image::MaskPixel> const &msk, \ 983 image::Image<VPixel> const &var, ImageImposter<VPixel> const &weights, \ 984 int const flags, StatisticsControl const &sctrl) 986 #define INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_MASK(TYPE) \ 987 template STAT::Statistics(image::Image<TYPE> const &img, MaskImposter<image::MaskPixel> const &msk, \ 988 image::Image<VPixel> const &var, int const flags, \ 989 StatisticsControl const &sctrl); \ 990 template STAT::Statistics(image::Image<TYPE> const &img, MaskImposter<image::MaskPixel> const &msk, \ 991 image::Image<VPixel> const &var, image::Image<VPixel> const &weights, \ 992 int const flags, StatisticsControl const &sctrl) 994 #define INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_VAR(TYPE) \ 995 template STAT::Statistics(image::Image<TYPE> const &img, image::Mask<image::MaskPixel> const &msk, \ 996 MaskImposter<VPixel> const &var, int const flags, \ 997 StatisticsControl const &sctrl); \ 998 template STAT::Statistics(image::Image<TYPE> const &img, image::Mask<image::MaskPixel> const &msk, \ 999 MaskImposter<VPixel> const &var, image::Image<VPixel> const &weights, \ 1000 int const flags, StatisticsControl const &sctrl); \ 1001 template STAT::Statistics(image::Image<TYPE> const &img, image::Mask<image::MaskPixel> const &msk, \ 1002 MaskImposter<VPixel> const &var, ImageImposter<VPixel> const &weights, \ 1003 int const flags, StatisticsControl const &sctrl) 1005 #define INSTANTIATE_REGULARIMAGE_STATISTICS(TYPE) \ 1006 template STAT::Statistics(image::Image<TYPE> const &img, MaskImposter<image::MaskPixel> const &msk, \ 1007 MaskImposter<VPixel> const &var, int const flags, \ 1008 StatisticsControl const &sctrl) 1010 #define INSTANTIATE_VECTOR_STATISTICS(TYPE) \ 1011 template STAT::Statistics(ImageImposter<TYPE> const &img, MaskImposter<image::MaskPixel> const &msk, \ 1012 MaskImposter<VPixel> const &var, int const flags, \ 1013 StatisticsControl const &sctrl); \ 1014 template STAT::Statistics(ImageImposter<TYPE> const &img, MaskImposter<image::MaskPixel> const &msk, \ 1015 MaskImposter<VPixel> const &var, ImageImposter<VPixel> const &weights, \ 1016 int const flags, StatisticsControl const &sctrl) 1018 #define INSTANTIATE_IMAGE_STATISTICS(T) \ 1019 INSTANTIATE_MASKEDIMAGE_STATISTICS(T); \ 1020 INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_VAR(T); \ 1021 INSTANTIATE_MASKEDIMAGE_STATISTICS_NO_MASK(T); \ 1022 INSTANTIATE_REGULARIMAGE_STATISTICS(T); \ 1023 INSTANTIATE_VECTOR_STATISTICS(T) 1025 INSTANTIATE_IMAGE_STATISTICS(
double);
1026 INSTANTIATE_IMAGE_STATISTICS(
float);
1027 INSTANTIATE_IMAGE_STATISTICS(
int);
1028 INSTANTIATE_IMAGE_STATISTICS(std::uint16_t);
1029 INSTANTIATE_IMAGE_STATISTICS(std::uint64_t);
Value getResult(Property const prop=NOTHING) const
Return the value and error in the specified statistic (e.g.
get the or-mask of all pixels used.
double getError(Property const prop=NOTHING) const
Return the error in the desired property (if specified in the constructor)
int getHeight() const
Return the number of rows in the image.
estimate sample standard deviation
find mean value of square of pixel values
We don't want anything.
bool getCalcErrorFromInputVariance() const
Include errors of requested quantities.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
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.
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
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)
Pass parameters to a Statistics object.
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
estimate sample N-sigma clipped variance (N set in StatisticsControl, default=3)
A Mask wrapper to provide an infinite_iterator for Mask::row_begin().
bool getWeightedIsSet() const
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
void setWeighted(bool useWeights)
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
estimate sample inter-quartile range
int getWidth() const
Return the number of columns in the image.
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
find sum of pixels in the image
double getNumSigmaClip() const
float VariancePixel
default type for MaskedImage variance images
Property
control what is calculated
A class to represent a 2-dimensional array of pixels.
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)