#include <cmath>
#include <iostream>
#include <limits>
#include <memory>
using ImgStat = math::Statistics;
using MaskedVectorF = math::MaskedVector<float>;
template <typename Image>
void printStats(Image &img, math::StatisticsControl const &sctrl) {
ImgStat stats = math::makeStatistics(
img,
math::NPOINT | math::STDEV | math::MEAN | math::VARIANCE | math::ERRORS | math::MIN | math::MAX |
math::VARIANCECLIP | math::MEANCLIP | math::MEDIAN | math::IQRANGE | math::STDEVCLIP,
sctrl);
double const npoint = stats.getValue(math::NPOINT);
double const mean = stats.getValue(math::MEAN);
double const var = stats.getValue(math::VARIANCE);
double const dmean = stats.getError(math::MEAN);
double const sd = stats.getValue(math::STDEV);
double const min = stats.getValue(math::MIN);
double const max = stats.getValue(math::MAX);
double const meanclip = stats.getValue(math::MEANCLIP);
double const varclip = stats.getValue(math::VARIANCECLIP);
double const stdevclip = stats.getValue(math::STDEVCLIP);
double const median = stats.getValue(math::MEDIAN);
double const iqrange = stats.getValue(math::IQRANGE);
}
int main() {
int const wid = 1024;
MaskedImageF mimg(img.getDimensions());
MaskedVectorF mv(wid * wid);
for (int j = 0; j != img.getHeight(); ++j) {
int k = 0;
MaskedImageF::x_iterator mip = mimg.row_begin(j);
for (ImageF::x_iterator ip = img.row_begin(j); ip != img.row_end(j); ++ip) {
double const xUniform =
M_PI *
static_cast<ImageF::Pixel
>(
std::rand()) / RAND_MAX;
double xLorentz = xUniform;
if (
static_cast<double>(
std::rand()) / RAND_MAX < 0.01) {
xLorentz = NAN;
}
*ip = xLorentz;
*mip = MaskedImageF::Pixel(xLorentz, (k % 2) ? 0x1 : 0x0, (k % 2) ? 1.0e99 : 1.0);
v.push_back(xLorentz);
++k;
++mip;
}
}
int j = 0;
for (MaskedVectorF::iterator mvp = mv.begin(); mvp != mv.end(); ++mvp) {
*mvp = MaskedVectorF::Pixel(v[j], (j % 2) ? 0x1 : 0x0, 10.0);
++j;
}
math::StatisticsControl sctrl;
sctrl.setNumIter(3);
sctrl.setNumSigmaClip(5.0);
sctrl.setAndMask(0x1);
sctrl.setNanSafe(true);
printStats(img, sctrl);
printStats(mimg, sctrl);
printStats(v, sctrl);
printStats(mv, sctrl);
printStats(*vF, sctrl);
sctrl.setWeighted(true);
sctrl.setAndMask(0x0);
printStats(mimg, sctrl);
math::Statistics mskstat =
makeStatistics(*mimg.getMask(), (math::NPOINT | math::SUM), sctrl);
std::cout << mskstat.getValue(math::NPOINT) <<
" " << mskstat.getValue(math::SUM) <<
std::endl;
return 0;
}
A class to represent a 2-dimensional array of pixels.
A class to manipulate images, masks, and variance as a single object.
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)