28 #include "lsst/pex/exceptions.h"
31 namespace pexExcept = lsst::pex::exceptions;
37 template <
typename ImageT>
39 return binImage(in, binsize, binsize, flags);
42 template <
typename ImageT>
43 std::shared_ptr<ImageT>
binImage(ImageT
const& in,
int const binX,
int const binY,
46 throw LSST_EXCEPT(pexExcept::InvalidParameterError,
47 (boost::format(
"Only afwMath::MEAN is supported, saw 0x%x") % flags).str());
49 if (binX <= 0 || binY <= 0) {
50 throw LSST_EXCEPT(pexExcept::DomainError,
51 (boost::format(
"Binning must be >= 0, saw %dx%d") % binX % binY).str());
54 int const outWidth = in.getWidth() / binX;
55 int const outHeight = in.getHeight() / binY;
57 std::shared_ptr<ImageT> out = std::shared_ptr<ImageT>(
new ImageT(
geom::Extent2I(outWidth, outHeight)));
58 out->setXY0(in.getXY0());
59 *out =
typename ImageT::SinglePixel(0);
61 for (
int oy = 0, iy = 0; oy < out->getHeight(); ++oy) {
62 for (
int i = 0; i != binY; ++i, ++iy) {
63 typename ImageT::x_iterator optr = out->row_begin(oy);
64 for (
typename ImageT::x_iterator iptr = in.row_begin(iy), iend = iptr + binX * outWidth;
66 typename ImageT::SinglePixel val = *iptr;
68 for (
int j = 1; j != binX; ++j, ++iptr) {
75 for (
typename ImageT::x_iterator ptr = out->row_begin(oy), end = out->row_end(oy); ptr != end;
88 #define INSTANTIATE(TYPE) \
89 template std::shared_ptr<image::Image<TYPE>> binImage(image::Image<TYPE> const&, int, \
90 lsst::afw::math::Property const); \
91 template std::shared_ptr<image::Image<TYPE>> binImage(image::Image<TYPE> const&, int, int, \
92 lsst::afw::math::Property const); \
93 template std::shared_ptr<image::MaskedImage<TYPE>> binImage(image::MaskedImage<TYPE> const&, int, \
94 lsst::afw::math::Property const); \
95 template std::shared_ptr<image::MaskedImage<TYPE>> binImage(image::MaskedImage<TYPE> const&, int, int, \
96 lsst::afw::math::Property const);
Property
control what is calculated
std::shared_ptr< ImageT > binImage(ImageT const &inImage, int const binX, int const binY, lsst::afw::math::Property const flags=lsst::afw::math::MEAN)