LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
binImage.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
28 #include <cstdint>
29 
30 #include "lsst/pex/exceptions.h"
32 
33 namespace pexExcept = lsst::pex::exceptions;
34 namespace afwImage = lsst::afw::image;
35 
36 namespace lsst {
37 namespace afw {
38 namespace math {
39 
40 template<typename ImageT>
41 PTR(ImageT) binImage(ImageT const& in,
42  int const binsize,
43  lsst::afw::math::Property const flags
44  )
45 {
46  return binImage(in, binsize, binsize, flags);
47 }
48 
49 template<typename ImageT>
50 PTR(ImageT) binImage(ImageT const& in,
51  int const binX,
52  int const binY,
53  lsst::afw::math::Property const flags
54  )
55 {
56  if (flags != lsst::afw::math::MEAN) {
57  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
58  (boost::format("Only afwMath::MEAN is supported, saw 0x%x") % flags).str());
59  }
60  if (binX <= 0 || binY <= 0) {
61  throw LSST_EXCEPT(pexExcept::DomainError,
62  (boost::format("Binning must be >= 0, saw %dx%d") % binX % binY).str());
63  }
64 
65  int const outWidth = in.getWidth()/binX;
66  int const outHeight = in.getHeight()/binY;
67 
68  typename ImageT::Ptr out = typename ImageT::Ptr(
69  new ImageT(geom::Extent2I(outWidth, outHeight))
70  );
71  out->setXY0(in.getXY0());
72  *out = typename ImageT::SinglePixel(0);
73 
74  for (int oy = 0, iy = 0; oy < out->getHeight(); ++oy) {
75  for (int i = 0; i != binY; ++i, ++iy) {
76  typename ImageT::x_iterator optr = out->row_begin(oy);
77  for (typename ImageT::x_iterator iptr = in.row_begin(iy), iend = iptr + binX*outWidth;
78  iptr < iend; ) {
79  typename ImageT::SinglePixel val = *iptr; ++iptr;
80  for (int j = 1; j != binX; ++j, ++iptr) {
81  val += *iptr;
82  }
83  *optr += val; ++optr;
84  }
85  }
86  for (typename ImageT::x_iterator ptr = out->row_begin(oy), end = out->row_end(oy); ptr != end; ++ptr) {
87  *ptr /= binX*binY;
88  }
89  }
90 
91  return out;
92 }
93 
94 /************************************************************************************************************/
95 //
96 // Explicit instantiations
97 //
99 #define INSTANTIATE(TYPE) \
100  template afwImage::Image<TYPE>::Ptr \
101  binImage(afwImage::Image<TYPE> const&, int, lsst::afw::math::Property const); \
102  template afwImage::Image<TYPE>::Ptr \
103  binImage(afwImage::Image<TYPE> const&, int, int, lsst::afw::math::Property const); \
104  template afwImage::MaskedImage<TYPE>::Ptr \
105  binImage(afwImage::MaskedImage<TYPE> const&, int, lsst::afw::math::Property const); \
106  template afwImage::MaskedImage<TYPE>::Ptr \
107  binImage(afwImage::MaskedImage<TYPE> const&, int, int, lsst::afw::math::Property const); \
108 
109 INSTANTIATE(std::uint16_t)
110 INSTANTIATE(int)
111 INSTANTIATE(float)
112 INSTANTIATE(double)
114 
115 }}}
Include files required for standard LSST Exception handling.
#define INSTANTIATE(T)
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
#define PTR(...)
Definition: base.h:41
estimate sample mean
Definition: Statistics.h:67
Property
control what is calculated
Definition: Statistics.h:63
ImageT val
Definition: CR.cc:159
boost::shared_ptr< ImageT > binImage(ImageT const &in, int const binsize, lsst::afw::math::Property const flags)
Definition: binImage.cc:41