27 #include "lsst/afw/math.h"
28 #include "lsst/afw/math/Statistics.h"
31 namespace lsst {
namespace ip {
namespace isr {
33 template <
typename PixelT>
34 size_t maskNans(afw::image::MaskedImage<PixelT>
const& mi, afw::image::MaskPixel maskVal,
35 afw::image::MaskPixel allow)
37 typedef typename afw::image::MaskedImage<PixelT>::x_iterator x_iterator;
39 for (
int y = 0; y != mi.getHeight(); ++y) {
40 for (x_iterator ptr = mi.row_begin(y), end = mi.row_end(y); ptr != end; ++ptr) {
41 if (!(ptr.mask() & allow) && (!std::isfinite(ptr.image()) ||
42 !std::isfinite(ptr.variance()))) {
44 ptr.mask() |= maskVal;
51 template<
typename ImagePixelT,
typename FunctionT>
53 std::shared_ptr< afw::math::Function1<FunctionT> > &overscanFunction,
54 afw::image::MaskedImage<ImagePixelT>
const& overscan,
58 typedef afw::image::MaskedImage<ImagePixelT> MaskedImage;
61 const int height = overscan.getHeight();
62 const int width = overscan.getWidth();
63 std::vector<double> values(height);
64 std::vector<double> errors(height);
65 std::vector<double> positions(height);
67 std::vector<double> parameters(overscanFunction->getNParameters(), 0.);
68 std::vector<double> stepsize(overscanFunction->getNParameters(), ssize);
70 for (
int y = 0; y < height; ++y) {
77 afw::geom::Box2I bbox = afw::geom::Box2I(afw::geom::Point2I(0,y), afw::geom::Point2I(width,y));
78 MaskedImage mi = MaskedImage(overscan, bbox);
79 afw::math::Statistics stats = afw::math::makeStatistics(*(mi.getImage()), afw::math::MEAN | afw::math::STDEV);
81 values[y] = stats.getValue(afw::math::MEAN);
82 errors[y] = stats.getValue(afw::math::STDEV);
86 afw::math::FitResults fitResults = afw::math::minimize(
96 overscanFunction->setParameters(fitResults.parameterList);
99 std::string
between(std::string &s,
char ldelim,
char rdelim) {
100 std::string::iterator b(s.begin());
101 std::string::iterator e(s.end());
102 std::string::iterator lp;
103 std::string::iterator rp;
107 if((lp = std::find(b, e, ldelim)) != e)
108 if((rp = std::find(++lp, e, rdelim)) != e)
109 result = std::string(lp, rp);
118 std::shared_ptr<afw::math::Function1<double> > &overscanFunction,
119 afw::image::MaskedImage<float>
const& overscan,
125 std::shared_ptr<afw::math::Function1<double> > &overscanFunction,
126 afw::image::MaskedImage<double>
const& overscan,
130 template class CountMaskedPixels<float>;
131 template class CountMaskedPixels<double>;
134 template size_t maskNans<float>(afw::image::MaskedImage<float>
const&, afw::image::MaskPixel,
135 afw::image::MaskPixel);
136 template size_t maskNans<double>(afw::image::MaskedImage<double>
const&, afw::image::MaskPixel,
137 afw::image::MaskPixel);
std::string between(std::string &s, char ldelim, char rdelim)
void fitOverscanImage(std::shared_ptr< lsst::afw::math::Function1< FunctionT > > &overscanFunction, lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, double ssize=1., int sigma=1)
template size_t maskNans< float >(afw::image::MaskedImage< float > const &, afw::image::MaskPixel, afw::image::MaskPixel)
Implementation of the templated Instrument Signature Removal stage of the nightly LSST Image Processi...
size_t maskNans(afw::image::MaskedImage< PixelT > const &mi, afw::image::MaskPixel maskVal, afw::image::MaskPixel allow=0)
Mask NANs in an image.
template size_t maskNans< double >(afw::image::MaskedImage< double > const &, afw::image::MaskPixel, afw::image::MaskPixel)