39 namespace ex = pex::exceptions;
63 bool const haveDefault = !
std::isnan(defaultValue);
70 }
else if (haveDefault) {
80 template <
typename ImageT>
82 :
Background(img, bgCtrl), _statsImage(
image::MaskedImage<InternalPixelT>()) {
93 for (
int iX = 0; iX < nxSample; ++iX) {
94 for (
int iY = 0; iY < nySample; ++iY) {
102 im(iX, iY) = res.first;
103 var(iX, iY) = res.second;
108 :
Background(imageBBox, statsImage.getWidth(), statsImage.getHeight()), _statsImage(statsImage) {}
116 _gridColumns[iX].
resize(height);
126 cullNan(
_ycen, _grid, ycenTmp, gridTmp);
132 switch (undersampleStyle) {
137 if (gridTmp.
empty()) {
150 e,
"The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
154 "UndersampleStyle %d is not defined.") %
163 for (
int iY = 0; iY < height; ++iY) {
164 _gridColumns[iX][iY] = intobj->interpolate(ypix[iY]);
169 _statsImage += delta;
174 _statsImage -= delta;
179 (void)getImage<InternalPixelT>(interpStyle);
182 int const nxSample = _statsImage.
getWidth();
184 for (
int iX = 0; iX < nxSample; iX++) {
185 bg_x[iX] = _gridColumns[iX][y];
188 cullNan(
_xcen, bg_x, xcenTmp, bgTmp);
192 return static_cast<double>(intobj->interpolate(x));
198 template <
typename PixelT>
207 str(boost::format(
"BBox (%d:%d,%d:%d) out of range (%d:%d,%d:%d)") % bbox.
getMinX() %
211 int const nxSample = _statsImage.
getWidth();
212 int const nySample = _statsImage.
getHeight();
231 switch (undersampleStyle) {
233 if (isXundersampled && isYundersampled) {
236 "nxSample and nySample have too few points for requested interpolation style.");
237 }
else if (isXundersampled) {
239 "nxSample has too few points for requested interpolation style.");
240 }
else if (isYundersampled) {
242 "nySample has too few points for requested interpolation style.");
246 if (isXundersampled || isYundersampled) {
249 interpStyle = (nxSample < nySample) ? xStyle : yStyle;
254 if (isXundersampled || isYundersampled) {
257 "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
262 str(boost::format(
"The selected BackgroundControl " 263 "UndersampleStyle %d is not defined.") %
281 for (
int iY = 0; iY < height; ++iY) {
285 _gridColumns.
resize(width);
286 for (
int iX = 0; iX < nxSample; ++iX) {
287 _setGridColumns(interpStyle, undersampleStyle, iX, ypix);
306 for (
int y = 0, iY = bboxOff.getY(); y < bbox.
getHeight(); ++y, ++iY) {
309 for (
int iX = 0; iX < nxSample; iX++) {
310 bg_x[iX] =
static_cast<double>(_gridColumns[iX][iY]);
312 cullNan(
_xcen, bg_x, xcenTmp, bgTmp, defaultValue);
318 switch (undersampleStyle) {
320 LSST_EXCEPT_ADD(e, str(boost::format(
"Interpolating in y (iY = %d)") % iY));
336 "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
340 "UndersampleStyle %d is not defined.") %
345 LSST_EXCEPT_ADD(e, str(boost::format(
"Interpolating in y (iY = %d)") % iY));
350 for (
int iX = bboxOff.getX(),
x = 0;
x < bbox.
getWidth(); ++iX, ++
x) {
351 (*bg)(
x, y) = static_cast<PixelT>(intobj->interpolate(iX));
354 bg->setXY0(bbox.
getMin());
359 template <
typename PixelT>
373 #define CREATE_BACKGROUND(m, v, TYPE) \ 374 template BackgroundMI::BackgroundMI(image::Image<TYPE> const& img, BackgroundControl const& bgCtrl); \ 375 template BackgroundMI::BackgroundMI(image::MaskedImage<TYPE> const& img, \ 376 BackgroundControl const& bgCtrl); \ 377 std::shared_ptr<image::Image<TYPE>> BackgroundMI::_getImage( \ 378 geom::Box2I const& bbox, Interpolate::Style const interpStyle, \ 379 UndersampleStyle const undersampleStyle, \ 382 return BackgroundMI::doGetImage<TYPE>(bbox, interpStyle, undersampleStyle); \ 385 #define CREATE_getApproximate(m, v, TYPE) \ 386 std::shared_ptr<Approximate<TYPE>> BackgroundMI::_getApproximate( \ 387 ApproximateControl const& actrl, \ 388 UndersampleStyle const undersampleStyle, \ 391 return BackgroundMI::doGetApproximate<TYPE>(actrl, undersampleStyle); \ std::vector< int > _xsize
x size of sub images
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
Point2I const getMin() const
std::vector< double > _xcen
x center pix coords of sub images
std::vector< int > _yorig
y origin ...
Property getStatisticsProperty() const
BackgroundMI(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for BackgroundMI.
std::shared_ptr< Interpolate > makeInterpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=Interpolate::AKIMA_SPLINE)
A factory function to make Interpolate objects.
geom::Box2I _imgBBox
size and origin of input image
#define LSST_makeBackground_getApproximate_types
std::vector< double > _ycen
y center ...
std::shared_ptr< Approximate< PixelT > > makeApproximate(std::vector< double > const &x, std::vector< double > const &y, image::MaskedImage< PixelT > const &im, geom::Box2I const &bbox, ApproximateControl const &ctrl)
Construct a new Approximate object, inferring the type from the type of the given MaskedImage...
Include errors of requested quantities.
Pass parameters to a Background object.
A virtual base class to evaluate image background levels.
An integer coordinate rectangle.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
std::shared_ptr< lsst::afw::image::Image< PixelT > > getImage() const
Method to interpolate and return the background for entire image.
y_iterator col_begin(int x) const
Return an y_iterator to the start of the y'th row.
Control how to make an approximation.
int getHeight() const
Return the number of rows in the image.
Interpolate::Style _asUsedInterpStyle
the style we actually used
A base class for image defects.
std::shared_ptr< StatisticsControl > getStatisticsControl()
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)
y_iterator col_end(int x) const
Return an y_iterator to the start of the y'th row.
bool contains(Point2I const &point) const
Return true if the box contains the point.
#define LSST_makeBackground_getImage_types
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for 'n' points.
int lookupMinInterpPoints(Interpolate::Style const style)
Get the minimum number of points needed to use the requested interpolation style. ...
#define LSST_EXCEPT(type,...)
std::vector< int > _xorig
x origin pix coords of sub images
Extent2I const getDimensions() const
std::shared_ptr< BackgroundControl > _bctrl
control info set by user.
std::vector< int > _ysize
y size ...
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
virtual BackgroundMI & operator+=(float const delta)
Add a scalar to the Background (equivalent to adding a constant to the original image) ...
int getWidth() const
Return the number of columns in the image.
A class to evaluate image background levels.
virtual BackgroundMI & operator-=(float const delta)
Subtract a scalar from the Background (equivalent to subtracting a constant from the original image) ...
#define LSST_EXCEPT_ADD(e, m)
A class to represent a 2-dimensional array of pixels.
double getPixel(Interpolate::Style const style, int const x, int const y) const
Method to retrieve the background level at a pixel coord.