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) {
95 ImageT subimg = ImageT(img,
103 im(iX, iY) = res.first;
104 var(iX, iY) = res.second;
110 :
Background(imageBBox, statsImage.getWidth(), statsImage.getHeight()), _statsImage(statsImage) {}
118 _gridColumns[iX].
resize(height);
128 cullNan(
_ycen, _grid, ycenTmp, gridTmp);
134 switch (undersampleStyle) {
139 if (gridTmp.
empty()) {
152 e,
"The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
156 "UndersampleStyle %d is not defined.") %
165 for (
int iY = 0; iY < height; ++iY) {
166 _gridColumns[iX][iY] = intobj->interpolate(ypix[iY]);
171 _statsImage += delta;
176 _statsImage -= delta;
181 (void)getImage<InternalPixelT>(interpStyle);
184 int const nxSample = _statsImage.
getWidth();
186 for (
int iX = 0; iX < nxSample; iX++) {
187 bg_x[iX] = _gridColumns[iX][
y];
190 cullNan(
_xcen, bg_x, xcenTmp, bgTmp);
194 return static_cast<double>(intobj->interpolate(x));
200 template <
typename PixelT>
213 int const nxSample = _statsImage.
getWidth();
214 int const nySample = _statsImage.
getHeight();
233 switch (undersampleStyle) {
235 if (isXundersampled && isYundersampled) {
238 "nxSample and nySample have too few points for requested interpolation style.");
239 }
else if (isXundersampled) {
241 "nxSample has too few points for requested interpolation style.");
242 }
else if (isYundersampled) {
244 "nySample has too few points for requested interpolation style.");
248 if (isXundersampled || isYundersampled) {
251 interpStyle = (nxSample < nySample) ? xStyle : yStyle;
256 if (isXundersampled || isYundersampled) {
259 "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
265 "UndersampleStyle %d is not defined.") %
283 for (
int iY = 0; iY < height; ++iY) {
287 _gridColumns.
resize(width);
288 for (
int iX = 0; iX < nxSample; ++iX) {
289 _setGridColumns(interpStyle, undersampleStyle, iX, ypix);
308 for (
int y = 0, iY = bboxOff.getY();
y < bbox.
getHeight(); ++
y, ++iY) {
311 for (
int iX = 0; iX < nxSample; iX++) {
312 bg_x[iX] =
static_cast<double>(_gridColumns[iX][iY]);
314 cullNan(
_xcen, bg_x, xcenTmp, bgTmp, defaultValue);
320 switch (undersampleStyle) {
338 "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
342 "UndersampleStyle %d is not defined.") %
352 for (
int iX = bboxOff.getX(),
x = 0;
x < bbox.
getWidth(); ++iX, ++
x) {
353 (*bg)(
x,
y) = static_cast<PixelT>(intobj->interpolate(iX));
356 bg->setXY0(bbox.
getMin());
361 template <
typename PixelT>
375 #define CREATE_BACKGROUND(m, v, TYPE) \ 376 template BackgroundMI::BackgroundMI(image::Image<TYPE> const& img, BackgroundControl const& bgCtrl); \ 377 template BackgroundMI::BackgroundMI(image::MaskedImage<TYPE> const& img, \ 378 BackgroundControl const& bgCtrl); \ 379 std::shared_ptr<image::Image<TYPE>> BackgroundMI::_getImage( \ 380 lsst::geom::Box2I const& bbox, \ 381 Interpolate::Style const interpStyle, \ 382 UndersampleStyle const undersampleStyle, \ 385 return BackgroundMI::doGetImage<TYPE>(bbox, interpStyle, undersampleStyle); \ 388 #define CREATE_getApproximate(m, v, TYPE) \ 389 std::shared_ptr<Approximate<TYPE>> BackgroundMI::_getApproximate( \ 390 ApproximateControl const& actrl, \ 391 UndersampleStyle const undersampleStyle, \ 394 return BackgroundMI::doGetApproximate<TYPE>(actrl, undersampleStyle); \ Extent2I const getDimensions() const noexcept
std::vector< int > _xsize
x size of sub images
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
std::vector< double > _xcen
x center pix coords of sub images
std::vector< int > _yorig
y origin ...
int getHeight() const noexcept
lsst::geom::Box2I _imgBBox
size and origin of input image
Property getStatisticsProperty() const
BackgroundMI(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for BackgroundMI.
Reports attempts to exceed implementation-defined length limits for some classes. ...
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.
#define LSST_makeBackground_getApproximate_types
std::vector< double > _ycen
y center ...
Provides consistent interface for LSST exceptions.
BackgroundMI & operator+=(float const delta) override
Add a scalar to the Background (equivalent to adding a constant to the original image) ...
std::shared_ptr< Approximate< PixelT > > makeApproximate(std::vector< double > const &x, std::vector< double > const &y, image::MaskedImage< PixelT > const &im, lsst::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.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
Point2I const getMin() const noexcept
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.
int getMaxY() const noexcept
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)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
int getWidth() const noexcept
y_iterator col_end(int x) const
Return an y_iterator to the start of the y'th row.
int getMaxX() const noexcept
#define LSST_makeBackground_getImage_types
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for 'n' points.
int getMinX() const noexcept
int lookupMinInterpPoints(Interpolate::Style const style)
Get the minimum number of points needed to use the requested interpolation style. ...
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Reports attempts to access elements outside a valid range of indices.
std::vector< int > _xorig
x origin pix coords of sub images
BackgroundMI & operator-=(float const delta) override
Subtract a scalar from the Background (equivalent to subtracting a constant from the original image) ...
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
std::shared_ptr< BackgroundControl > _bctrl
control info set by user.
std::vector< int > _ysize
y size ...
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
Reports invalid arguments.
int getWidth() const
Return the number of columns in the image.
A class to evaluate image background levels.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it...
An integer coordinate rectangle.
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.
int getMinY() const noexcept