48void cullNan(std::vector<double>
const& values, std::vector<double>
const& refs,
49 std::vector<double>& culledValues, std::vector<double>& culledRefs,
62 bool const haveDefault = !
std::isnan(defaultValue);
64 for (std::vector<double>::const_iterator pVal = values.
begin(), pRef =
refs.begin(); pRef !=
refs.end();
69 }
else if (haveDefault) {
79template <
typename ImageT>
92 for (
int iX = 0; iX < nxSample; ++iX) {
93 for (
int iY = 0; iY < nySample; ++iY) {
94 ImageT subimg = ImageT(img,
102 im(iX, iY) = res.first;
103 var(iX, iY) = res.second;
109 :
Background(imageBBox, statsImage.getWidth(), statsImage.getHeight()), _statsImage(statsImage) {}
117 _gridColumns[iX].
resize(height);
127 cullNan(
_ycen, _grid, ycenTmp, gridTmp);
133 switch (undersampleStyle) {
138 if (gridTmp.
empty()) {
151 e,
"The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
155 "UndersampleStyle %d is not defined.") %
159 }
catch (ex::Exception& e) {
164 for (
int iY = 0; iY < height; ++iY) {
165 _gridColumns[iX][iY] = intobj->interpolate(ypix[iY]);
170 _statsImage += delta;
175 _statsImage -= delta;
180 ndarray::Array<double, 1, 1> result = ndarray::allocate(
_xcen.size());
182 result.deep() +=
_imgBBox.getMinX();
187 ndarray::Array<double, 1, 1> result = ndarray::allocate(
_ycen.size());
189 result.deep() +=
_imgBBox.getMinY();
193template <
typename PixelT>
202 str(boost::format(
"BBox (%d:%d,%d:%d) out of range (%d:%d,%d:%d)") % bbox.getMinX() %
203 bbox.getMaxX() % bbox.getMinY() % bbox.getMaxY() %
_imgBBox.
getMinX() %
206 int const nxSample = _statsImage.
getWidth();
207 int const nySample = _statsImage.
getHeight();
226 switch (undersampleStyle) {
228 if (isXundersampled && isYundersampled) {
230 ex::InvalidParameterError,
231 "nxSample and nySample have too few points for requested interpolation style.");
232 }
else if (isXundersampled) {
234 "nxSample has too few points for requested interpolation style.");
235 }
else if (isYundersampled) {
237 "nySample has too few points for requested interpolation style.");
241 if (isXundersampled || isYundersampled) {
244 interpStyle = (nxSample < nySample) ? xStyle : yStyle;
249 if (isXundersampled || isYundersampled) {
251 ex::InvalidParameterError,
252 "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
257 str(boost::format(
"The selected BackgroundControl "
258 "UndersampleStyle %d is not defined.") %
271 int const width =
_imgBBox.getWidth();
272 int const height =
_imgBBox.getHeight();
275 std::vector<int> ypix(height);
276 for (
int iY = 0; iY < height; ++iY) {
280 _gridColumns.resize(width);
281 for (
int iX = 0; iX < nxSample; ++iX) {
282 _setGridColumns(interpStyle, undersampleStyle, iX, ypix);
287 std::shared_ptr<image::Image<PixelT>> bg =
288 std::shared_ptr<image::Image<PixelT>>(
new image::Image<PixelT>(
bbox.getDimensions()));
293 std::vector<double> xcenTmp, bgTmp;
301 for (
int y = 0, iY = bboxOff.getY(); y <
bbox.getHeight(); ++y, ++iY) {
303 std::vector<double> bg_x(nxSample);
304 for (
int iX = 0; iX < nxSample; iX++) {
305 bg_x[iX] =
static_cast<double>(_gridColumns[iX][iY]);
307 cullNan(
_xcen, bg_x, xcenTmp, bgTmp, defaultValue);
309 std::shared_ptr<Interpolate> intobj;
312 }
catch (pex::exceptions::OutOfRangeError& e) {
313 switch (undersampleStyle) {
319 xcenTmp.push_back(0);
320 bgTmp.push_back(defaultValue);
331 "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
335 "UndersampleStyle %d is not defined.") %
339 }
catch (ex::Exception& e) {
345 for (
int iX = bboxOff.getX(), x = 0; x <
bbox.getWidth(); ++iX, ++x) {
346 (*bg)(
x,
y) =
static_cast<PixelT>(intobj->interpolate(iX));
349 bg->setXY0(
bbox.getMin());
354template <
typename PixelT>
355std::shared_ptr<Approximate<PixelT>> BackgroundMI::doGetApproximate(
368#define CREATE_BACKGROUND(m, v, TYPE) \
369 template BackgroundMI::BackgroundMI(image::Image<TYPE> const& img, BackgroundControl const& bgCtrl); \
370 template BackgroundMI::BackgroundMI(image::MaskedImage<TYPE> const& img, \
371 BackgroundControl const& bgCtrl); \
372 std::shared_ptr<image::Image<TYPE>> BackgroundMI::_getImage( \
373 lsst::geom::Box2I const& bbox, \
374 Interpolate::Style const interpStyle, \
375 UndersampleStyle const undersampleStyle, \
378 return BackgroundMI::doGetImage<TYPE>(bbox, interpStyle, undersampleStyle); \
381#define CREATE_getApproximate(m, v, TYPE) \
382 std::shared_ptr<Approximate<TYPE>> BackgroundMI::_getApproximate( \
383 ApproximateControl const& actrl, \
384 UndersampleStyle const undersampleStyle, \
387 return BackgroundMI::doGetApproximate<TYPE>(actrl, undersampleStyle); \
#define LSST_makeBackground_getApproximate_types
#define LSST_makeBackground_getImage_types
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
y_iterator col_begin(int x) const
Return an y_iterator to the start of the y'th row.
y_iterator col_end(int x) const
Return an y_iterator to the start of the y'th row.
A class to manipulate images, masks, and variance as a single object.
lsst::afw::image::Image< VariancePixelT > Variance
int getHeight() const
Return the number of rows in the image.
int getWidth() const
Return the number of columns in the image.
lsst::afw::image::Image< ImagePixelT > Image
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
Control how to make an approximation.
Pass parameters to a Background object.
std::shared_ptr< StatisticsControl > getStatisticsControl()
Property getStatisticsProperty() const
std::vector< double > _ycen
y center ...
std::vector< double > _xcen
x center pix coords of sub images
Background(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for Background.
std::vector< int > _xsize
x size of sub images
lsst::geom::Box2I _imgBBox
size and origin of input image
std::vector< int > _xorig
x origin pix coords of sub images
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
std::vector< int > _ysize
y size ...
float InternalPixelT
type used for any internal images, and returned by getApproximate
std::vector< int > _yorig
y origin ...
Interpolate::Style _asUsedInterpStyle
the style we actually used
std::shared_ptr< BackgroundControl > _bctrl
control info set by user.
ndarray::Array< double, 1, 1 > getBinCentersY() const
Return the y-coordinate centers of the bins.
BackgroundMI & operator-=(float const delta) override
Subtract a scalar from the Background (equivalent to subtracting a constant from the original image)
ndarray::Array< double, 1, 1 > getBinCentersX() const
Return the x-coordinate centers of the bins.
BackgroundMI & operator+=(float const delta) override
Add a scalar to the Background (equivalent to adding a constant to the original image)
BackgroundMI(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for BackgroundMI.
Value getResult(Property const prop=NOTHING) const
Return the value and error in the specified statistic (e.g.
An integer coordinate rectangle.
int getMinY() const noexcept
int getHeight() const noexcept
int getMinX() const noexcept
int getMaxX() const noexcept
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
int getMaxY() const noexcept
Reports attempts to access elements outside a valid range of indices.
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for 'n' points.
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)
@ ERRORS
Include errors of requested quantities.
int lookupMinInterpPoints(Interpolate::Style const style)
Get the minimum number of points needed to use the requested interpolation style.
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.
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.
BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_COLUMNVIEW_SCALAR, _, BOOST_PP_TUPLE_TO_SEQ(AFW_TABLE_SCALAR_FIELD_TYPE_N, AFW_TABLE_SCALAR_FIELD_TYPE_TUPLE)) BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_COLUMNVIEW_ARRAY
Extent< int, 2 > Extent2I