LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lsst::afw::math::BackgroundMI Class Reference

A class to evaluate image background levels. More...

#include <Background.h>

Inheritance diagram for lsst::afw::math::BackgroundMI:
lsst::afw::math::Background lsst::daf::base::Citizen

Public Member Functions

template<typename ImageT >
 BackgroundMI (ImageT const &img, BackgroundControl const &bgCtrl)
 Constructor for BackgroundMI. More...
 
 BackgroundMI (geom::Box2I const imageDimensions, image::MaskedImage< InternalPixelT > const &statsImage)
 
virtual void operator+= (float const delta)
 Add a scalar to the Background (equivalent to adding a constant to the original image) More...
 
virtual void operator-= (float const delta)
 Subtract a scalar from the Background (equivalent to subtracting a constant from the original image) More...
 
double getPixel (Interpolate::Style const style, int const x, int const y) const
 Method to retrieve the background level at a pixel coord. More...
 
double getPixel (int const x, int const y) const
 Return the background value at a point. More...
 
lsst::afw::image::MaskedImage
< InternalPixelT
getStatsImage () const
 Return the image of statistical quantities extracted from the image. More...
 
- Public Member Functions inherited from lsst::afw::math::Background
template<typename PixelT >
boost::shared_ptr
< lsst::afw::image::Image
< PixelT > > 
getImage (Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle=THROW_EXCEPTION) const
 Method to interpolate and return the background for entire image. More...
 
template<typename PixelT >
boost::shared_ptr
< lsst::afw::image::Image
< PixelT > > 
getImage (std::string const &interpStyle, std::string const &undersampleStyle="THROW_EXCEPTION") const
 Method to interpolate and return the background for entire image. More...
 
template<typename PixelT >
boost::shared_ptr
< lsst::afw::image::Image
< PixelT > > 
getImage (lsst::afw::geom::Box2I const &bbox, Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle=THROW_EXCEPTION) const
 
template<typename PixelT >
boost::shared_ptr
< lsst::afw::image::Image
< PixelT > > 
getImage (lsst::afw::geom::Box2I const &bbox, std::string const &interpStyle, std::string const &undersampleStyle="THROW_EXCEPTION") const
 
template<typename PixelT >
boost::shared_ptr
< lsst::afw::image::Image
< PixelT > > 
getImage () const
 Method to interpolate and return the background for entire image. More...
 
Interpolate::Style getAsUsedInterpStyle () const
 
UndersampleStyle getAsUsedUndersampleStyle () const
 
boost::shared_ptr
< math::Approximate
< InternalPixelT > > 
getApproximate (ApproximateControl const &actrl, UndersampleStyle const undersampleStyle=THROW_EXCEPTION) const
 Method to return an approximation to the background. More...
 
geom::Box2I getImageBBox () const
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 

Private Member Functions

void _setGridColumns (Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle, int const iX, std::vector< int > const &ypix) const
 
template<typename PixelT >
boost::shared_ptr
< image::Image< PixelT > > 
doGetImage (geom::Box2I const &bbox, Interpolate::Style const interpStyle_, UndersampleStyle const undersampleStyle) const
 
template<typename PixelT >
boost::shared_ptr< Approximate
< PixelT > > 
doGetApproximate (ApproximateControl const &actrl, UndersampleStyle const undersampleStyle) const
 

Private Attributes

lsst::afw::image::MaskedImage
< InternalPixelT
_statsImage
 
std::vector< std::vector
< double > > 
_gridColumns
 

Additional Inherited Members

- Public Types inherited from lsst::afw::math::Background
typedef float InternalPixelT
 type used for any internal images, and returned by getApproximate More...
 
- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 
- Protected Member Functions inherited from lsst::afw::math::Background
template<typename ImageT >
 Background (ImageT const &img, BackgroundControl const &bgCtrl)
 Constructor for Background. More...
 
 Background (geom::Box2I const imageBBox, int const nx, int const ny)
 
virtual ~Background ()
 dtor More...
 
- Protected Attributes inherited from lsst::afw::math::Background
geom::Box2I _imgBBox
 size and origin of input image More...
 
BackgroundControl _bctrl
 control info set by user. More...
 
Interpolate::Style _asUsedInterpStyle
 the style we actually used More...
 
UndersampleStyle _asUsedUndersampleStyle
 the undersampleStyle we actually used More...
 
std::vector< double > _xcen
 x center pix coords of sub images More...
 
std::vector< double > _ycen
 y center ... More...
 
std::vector< int > _xorig
 x origin pix coords of sub images More...
 
std::vector< int > _yorig
 y origin ... More...
 
std::vector< int > _xsize
 x size of sub images More...
 
std::vector< int > _ysize
 y size ... More...
 

Detailed Description

A class to evaluate image background levels.

Break an image up into nx*ny sub-images and use a statistical to estimate the background levels in each square. Then use a user-specified or algorithm to estimate background at a given pixel coordinate.

Methods are available to return the background at a point (inefficiently), or an entire background image. BackgroundControl contains a public StatisticsControl member to allow user control of how the backgrounds are computed.

math::BackgroundControl bctrl(7, 7); // number of sub-image squares in {x,y}-dimensions
bctrl.sctrl.setNumSigmaClip(5.0); // use 5-sigma clipping for the sub-image means
PTR(math::Background) backobj = math::makeBackground(img, bctrl);
// get a whole background image
Image<PixelT> back = backobj->getImage<PixelT>(math::Interpolate::NATURAL_SPLINE);
*
Deprecated:
there is also
// get the background at a pixel at i_x,i_y
double someValue = backobj.getPixel(math::Interpolate::LINEAR, i_x, i_y);
*

Definition at line 382 of file Background.h.

Constructor & Destructor Documentation

template<typename ImageT >
lsst::afw::math::BackgroundMI::BackgroundMI ( ImageT const &  img,
BackgroundControl const &  bgCtrl 
)
explicit

Constructor for BackgroundMI.

Estimate the statistical properties of the Image in a grid of cells; we'll later call getImage() to interpolate those values, creating an image the same size as the original

Note
If there are heavily masked or Nan regions in the image we may not be able to estimate all the cells in the "statsImage". Interpolation will still work, but if you want to prevent the code wildly extrapolating, it may be better to set the values directly; e.g.
* defaultValue = 10
* statsImage = afwMath.cast_BackgroundMI(bkgd).getStatsImage()
* sim = statsImage.getImage().getArray()
* sim[np.isnan(sim)] = defaultValue # replace NaN by defaultValue
* bkgdImage = bkgd.getImageF(afwMath.Interpolate.NATURAL_SPLINE, afwMath.REDUCE_INTERP_ORDER)
*
There is a ticket (#2825) to allow getImage to specify a default value to use when interpolation fails
Deprecated:
The old and deprecated API specified the interpolation style as part of the BackgroundControl object passed to this ctor. This is still supported, but the work isn't done until the getImage() method is called
Parameters
imgImageT (or MaskedImage) whose properties we want
bgCtrlControl how the BackgroundMI is estimated

Definition at line 109 of file BackgroundMI.cc.

111  :
113 {
114  // =============================================================
115  // Loop over the cells in the image, computing statistical properties
116  // of each cell in turn and using them to set _statsImage
117  int const nxSample = bgCtrl.getNxSample();
118  int const nySample = bgCtrl.getNySample();
119  _statsImage = image::MaskedImage<InternalPixelT>(nxSample, nySample);
120 
123 
124  for (int iX = 0; iX < nxSample; ++iX) {
125  for (int iY = 0; iY < nySample; ++iY) {
126  ImageT subimg = ImageT(img, geom::Box2I(geom::Point2I(_xorig[iX], _yorig[iY]),
128 
129  std::pair<double, double> res = makeStatistics(subimg, bgCtrl.getStatisticsProperty() | ERRORS,
130  *bgCtrl.getStatisticsControl()).getResult();
131  im(iX, iY) = res.first;
132  var(iX, iY) = res.second;
133  }
134  }
135 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
std::vector< int > _xsize
x size of sub images
Definition: Background.h:319
std::vector< int > _yorig
y origin ...
Definition: Background.h:318
Background(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for Background.
Definition: Background.cc:59
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:869
Include errors of requested quantities.
Definition: Statistics.h:65
A coordinate class intended to represent absolute positions.
An integer coordinate rectangle.
Definition: Box.h:53
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:890
std::vector< int > _xorig
x origin pix coords of sub images
Definition: Background.h:317
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1023
std::vector< int > _ysize
y size ...
Definition: Background.h:320
lsst::afw::math::BackgroundMI::BackgroundMI ( geom::Box2I const  imageBBox,
image::MaskedImage< InternalPixelT > const &  statsImage 
)
explicit

Recreate a BackgroundMI from the statsImage and the original Image's BBox

Parameters
imageBBoxunbinned Image's BBox
statsImageInternal stats image

Definition at line 139 of file BackgroundMI.cc.

141  :
142  Background(imageBBox, statsImage.getWidth(), statsImage.getHeight()),
143  _statsImage(statsImage)
144 {
145 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
Background(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for Background.
Definition: Background.cc:59
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:903
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:901

Member Function Documentation

void lsst::afw::math::BackgroundMI::_setGridColumns ( Interpolate::Style const  interpStyle,
UndersampleStyle const  undersampleStyle,
int const  iX,
std::vector< int > const &  ypix 
) const
private

Definition at line 147 of file BackgroundMI.cc.

150 {
152 
153  int const height = _imgBBox.getHeight();
154  _gridColumns[iX].resize(height);
155 
156  // Set _grid as a transitional measure
157  std::vector<double> _grid(_statsImage.getHeight());
158  std::copy(im.col_begin(iX), im.col_end(iX), _grid.begin());
159 
160  // remove nan from the grid values before computing columns
161  // if we do it here (ie. in _setGridColumns), it should
162  // take care of all future occurrences, so we don't need to do this elsewhere
163  std::vector<double> ycenTmp, gridTmp;
164  cullNan(_ycen, _grid, ycenTmp, gridTmp);
165 
166  PTR(Interpolate) intobj;
167  try {
168  intobj = makeInterpolate(ycenTmp, gridTmp, interpStyle);
169  } catch(pex::exceptions::OutOfRangeError &e) {
170  switch (undersampleStyle) {
171  case THROW_EXCEPTION:
172  LSST_EXCEPT_ADD(e, "setting _gridcolumns");
173  throw;
174  case REDUCE_INTERP_ORDER:
175  {
176  if (gridTmp.empty()) {
177  // Set the column to NaN. We'll deal with this properly when interpolating in x
178  ycenTmp.push_back(0);
179  gridTmp.push_back(std::numeric_limits<double>::quiet_NaN());
180 
181  intobj = makeInterpolate(ycenTmp, gridTmp, Interpolate::CONSTANT);
182  break;
183  } else {
184  return _setGridColumns(lookupMaxInterpStyle(gridTmp.size()), undersampleStyle, iX, ypix);
185  }
186  }
187  case INCREASE_NXNYSAMPLE:
188  LSST_EXCEPT_ADD(e, "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
189  throw;
190  default:
191  LSST_EXCEPT_ADD(e, str(boost::format("The selected BackgroundControl "
192  "UndersampleStyle %d is not defined.") % undersampleStyle));
193  throw;
194  }
195  } catch(ex::Exception &e) {
196  LSST_EXCEPT_ADD(e, "setting _gridcolumns");
197  throw;
198  }
199 
200  for (int iY = 0; iY < height; ++iY) {
201  _gridColumns[iX][iY] = intobj->interpolate(ypix[iY]);
202  }
203 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
#define PTR(...)
Definition: base.h:41
std::vector< std::vector< double > > _gridColumns
Definition: Background.h:414
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:903
boost::shared_ptr< Interpolate > makeInterpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=Interpolate::AKIMA_SPLINE)
Definition: Interpolate.cc:355
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:310
std::vector< double > _ycen
y center ...
Definition: Background.h:316
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:869
void _setGridColumns(Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle, int const iX, std::vector< int > const &ypix) const
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
y_iterator col_end(int x) const
Return an y_iterator to the end of the image.
Definition: MaskedImage.cc:725
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for &#39;n&#39; points.
Definition: Interpolate.cc:287
int getHeight() const
Definition: Box.h:155
y_iterator col_begin(int x) const
Return an y_iterator to the start of the image.
Definition: MaskedImage.cc:715
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
template<typename PixelT >
boost::shared_ptr< Approximate< PixelT > > lsst::afw::math::BackgroundMI::doGetApproximate ( ApproximateControl const &  actrl,
UndersampleStyle const  undersampleStyle 
) const
private

Definition at line 414 of file BackgroundMI.cc.

418 {
419  return makeApproximate(_xcen, _ycen, _statsImage, _imgBBox, actrl);
420 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:315
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:310
std::vector< double > _ycen
y center ...
Definition: Background.h:316
boost::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...
Definition: Approximate.cc:289
template<typename PixelT >
boost::shared_ptr< image::Image< PixelT > > lsst::afw::math::BackgroundMI::doGetImage ( geom::Box2I const &  bbox,
Interpolate::Style const  interpStyle_,
UndersampleStyle const  undersampleStyle 
) const
private

Definition at line 259 of file BackgroundMI.cc.

264 {
265  if (!_imgBBox.contains(bbox)) {
266  throw LSST_EXCEPT(ex::LengthError,
267  str(boost::format("BBox (%d:%d,%d:%d) out of range (%d:%d,%d:%d)") %
268  bbox.getMinX() % bbox.getMaxX() % bbox.getMinY() % bbox.getMaxY() %
271  }
272  int const nxSample = _statsImage.getWidth();
273  int const nySample = _statsImage.getHeight();
274  Interpolate::Style interpStyle = interpStyle_; // not const -- may be modified if REDUCE_INTERP_ORDER
275 
276  /*
277  * Save the as-used interpStyle and undersampleStyle.
278  *
279  * N.b. The undersampleStyle may actually be overridden for some columns of the statsImage if they
280  * have too few good values. This doesn't prevent you reproducing the results of getImage() by
281  * calling getImage(getInterpStyle(), getUndersampleStyle())
282  */
283  _asUsedInterpStyle = interpStyle;
284  _asUsedUndersampleStyle = undersampleStyle;
285  /*
286  * Check if the requested nx,ny are sufficient for the requested interpolation style,
287  * making suitable adjustments
288  */
289  bool const isXundersampled = (nxSample < lookupMinInterpPoints(interpStyle));
290  bool const isYundersampled = (nySample < lookupMinInterpPoints(interpStyle));
291 
292  switch (undersampleStyle) {
293  case THROW_EXCEPTION:
294  if (isXundersampled && isYundersampled) {
295  throw LSST_EXCEPT(ex::InvalidParameterError,
296  "nxSample and nySample have too few points for requested interpolation style.");
297  } else if (isXundersampled) {
298  throw LSST_EXCEPT(ex::InvalidParameterError,
299  "nxSample has too few points for requested interpolation style.");
300  } else if (isYundersampled) {
301  throw LSST_EXCEPT(ex::InvalidParameterError,
302  "nySample has too few points for requested interpolation style.");
303  }
304  break;
305  case REDUCE_INTERP_ORDER:
306  if (isXundersampled || isYundersampled) {
307  Interpolate::Style const xStyle = lookupMaxInterpStyle(nxSample);
308  Interpolate::Style const yStyle = lookupMaxInterpStyle(nySample);
309  interpStyle = (nxSample < nySample) ? xStyle : yStyle;
310  _asUsedInterpStyle = interpStyle;
311  }
312  break;
313  case INCREASE_NXNYSAMPLE:
314  if (isXundersampled || isYundersampled) {
315  throw LSST_EXCEPT(ex::InvalidParameterError,
316  "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
317  }
318  break;
319  default:
320  throw LSST_EXCEPT(ex::InvalidParameterError,
321  str(boost::format("The selected BackgroundControl "
322  "UndersampleStyle %d is not defined.") % undersampleStyle));
323  }
324 
325  // =============================================================
326  // --> We'll store nxSample fully-interpolated columns to interpolate the rows over
327  // make a vector containing the y pixel coords for the column
328  int const width = _imgBBox.getWidth();
329  int const height = _imgBBox.getHeight();
330  int const x0 = bbox.getMinX();
331  int const y0 = bbox.getMinY();
332 
333  std::vector<int> ypix(height);
334  for (int iY = 0; iY < height; ++iY) {
335  ypix[iY] = iY;
336  }
337 
338  _gridColumns.resize(width);
339  for (int iX = 0; iX < nxSample; ++iX) {
340  _setGridColumns(interpStyle, undersampleStyle, iX, ypix);
341  }
342 
343  // create a shared_ptr to put the background image in and return to caller
345  PTR(image::Image<PixelT>)(new image::Image<PixelT>(bbox.getDimensions()));
346 
347  // go through row by row
348  // - interpolate on the gridcolumns that were pre-computed by the constructor
349  // - copy the values to an ImageT to return to the caller.
350  std::vector<double> xcenTmp, bgTmp;
351 
352  // N.b. There's no API to set defaultValue to other than NaN (due to issues with persistence
353  // that I don't feel like fixing; #2825). If we want to address this, this is the place
354  // to start, but note that NaN is treated specially -- it means, "Interpolate" so to allow
355  // us to put a NaN into the outputs some changes will be needed
356  double defaultValue = std::numeric_limits<double>::quiet_NaN();
357 
358  for (int iY = y0; iY <= bbox.getMaxY(); ++iY) {
359  // build an interp object for this row
360  std::vector<double> bg_x(nxSample);
361  for (int iX = 0; iX < nxSample; iX++) {
362  bg_x[iX] = static_cast<double>(_gridColumns[iX][iY]);
363  }
364  cullNan(_xcen, bg_x, xcenTmp, bgTmp, defaultValue);
365 
366  PTR(Interpolate) intobj;
367  try {
368  intobj = makeInterpolate(xcenTmp, bgTmp, interpStyle);
369  } catch(pex::exceptions::OutOfRangeError &e) {
370  switch (undersampleStyle) {
371  case THROW_EXCEPTION:
372  LSST_EXCEPT_ADD(e, str(boost::format("Interpolating in y (iY = %d)") % iY));
373  throw;
374  case REDUCE_INTERP_ORDER:
375  {
376  if (bgTmp.empty()) {
377  xcenTmp.push_back(0);
378  bgTmp.push_back(defaultValue);
379 
380  intobj = makeInterpolate(xcenTmp, bgTmp, Interpolate::CONSTANT);
381  break;
382  } else {
383  intobj = makeInterpolate(xcenTmp, bgTmp, lookupMaxInterpStyle(bgTmp.size()));
384  }
385  }
386  break;
387  case INCREASE_NXNYSAMPLE:
388  LSST_EXCEPT_ADD(e, "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
389  throw;
390  default:
391  LSST_EXCEPT_ADD(e, str(boost::format("The selected BackgroundControl "
392  "UndersampleStyle %d is not defined.") % undersampleStyle));
393  throw;
394  }
395  } catch(ex::Exception &e) {
396  LSST_EXCEPT_ADD(e, str(boost::format("Interpolating in y (iY = %d)") % iY));
397  throw;
398  }
399 
400  // fill the image with interpolated values
401  int const y = iY - y0;
402  for (int iX = x0, x = 0; iX <= bbox.getMaxX(); ++iX, ++x) {
403  (*bg)(x, y) = static_cast<PixelT>(intobj->interpolate(iX));
404  }
405  }
406  bg->setXY0(x0, y0);
407 
408  return bg;
409 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:315
int getMaxY() const
Definition: Box.h:129
#define PTR(...)
Definition: base.h:41
bool contains(Point2I const &point) const
Return true if the box contains the point.
std::vector< std::vector< double > > _gridColumns
Definition: Background.h:414
int y
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:903
boost::shared_ptr< Interpolate > makeInterpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=Interpolate::AKIMA_SPLINE)
Definition: Interpolate.cc:355
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:310
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
Interpolate::Style _asUsedInterpStyle
the style we actually used
Definition: Background.h:312
void _setGridColumns(Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle, int const iX, std::vector< int > const &ypix) const
int x
int getMinY() const
Definition: Box.h:125
int getMinX() const
Definition: Box.h:124
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for &#39;n&#39; points.
Definition: Interpolate.cc:287
int getWidth() const
Definition: Box.h:154
int lookupMinInterpPoints(Interpolate::Style const style)
Get the minimum number of points needed to use the requested interpolation style. ...
Definition: Interpolate.cc:311
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getHeight() const
Definition: Box.h:155
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:901
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
Definition: Background.h:313
int getMaxX() const
Definition: Box.h:128
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
double lsst::afw::math::BackgroundMI::getPixel ( Interpolate::Style const  interpStyle,
int const  x,
int const  y 
) const

Method to retrieve the background level at a pixel coord.

Returns
an estimated background at x,y (double)
Deprecated:
Don't call this image (not even in test code). This can be a very costly function to get a single pixel. If you want an image, use the getImage() method.
Parameters
interpStyleHow to interpolate
xx-pixel coordinate (column)
yy-pixel coordinate (row)

Definition at line 231 of file BackgroundMI.cc.

235 {
236  (void)getImage<double>(interpStyle); // setup the interpolation
237 
238  // build an interpobj along the row y and get the x'th value
239  int const nxSample = _statsImage.getWidth();
240  std::vector<double> bg_x(nxSample);
241  for (int iX = 0; iX < nxSample; iX++) {
242  bg_x[iX] = _gridColumns[iX][y];
243  }
244  std::vector<double> xcenTmp, bgTmp;
245  cullNan(_xcen, bg_x, xcenTmp, bgTmp);
246 
247  try {
248  PTR(Interpolate) intobj = makeInterpolate(xcenTmp, bgTmp, interpStyle);
249  return static_cast<double>(intobj->interpolate(x));
250  } catch(ex::Exception &e) {
251  LSST_EXCEPT_ADD(e, "in getPixel()");
252  throw;
253  }
254 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:315
#define PTR(...)
Definition: base.h:41
std::vector< std::vector< double > > _gridColumns
Definition: Background.h:414
int y
boost::shared_ptr< Interpolate > makeInterpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=Interpolate::AKIMA_SPLINE)
Definition: Interpolate.cc:355
int x
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:901
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
double lsst::afw::math::BackgroundMI::getPixel ( int const  x,
int const  y 
) const
inline

Return the background value at a point.

Warning
This is very inefficient – only use it for debugging, if then.
Deprecated:
New code should specify the interpolation style in getPixel, not the ctor

Definition at line 402 of file Background.h.

402  {
403  return getPixel(_bctrl.getInterpStyle(), x, y);
404  }
int y
double getPixel(Interpolate::Style const style, int const x, int const y) const
Method to retrieve the background level at a pixel coord.
int x
Interpolate::Style getInterpStyle() const
Definition: Background.h:185
BackgroundControl _bctrl
control info set by user.
Definition: Background.h:311
lsst::afw::image::MaskedImage<InternalPixelT> lsst::afw::math::BackgroundMI::getStatsImage ( ) const
inline

Return the image of statistical quantities extracted from the image.

Definition at line 408 of file Background.h.

408  {
409  return _statsImage;
410  }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
void lsst::afw::math::BackgroundMI::operator+= ( float const  delta)
virtual

Add a scalar to the Background (equivalent to adding a constant to the original image)

Parameters
deltaValue to add

Implements lsst::afw::math::Background.

Definition at line 208 of file BackgroundMI.cc.

210 {
211  _statsImage += delta;
212 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413
void lsst::afw::math::BackgroundMI::operator-= ( float const  delta)
virtual

Subtract a scalar from the Background (equivalent to subtracting a constant from the original image)

Parameters
deltaValue to subtract

Implements lsst::afw::math::Background.

Definition at line 217 of file BackgroundMI.cc.

219 {
220  _statsImage -= delta;
221 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:413

Member Data Documentation

std::vector<std::vector<double> > lsst::afw::math::BackgroundMI::_gridColumns
mutableprivate

Definition at line 414 of file Background.h.

lsst::afw::image::MaskedImage<InternalPixelT> lsst::afw::math::BackgroundMI::_statsImage
private

Definition at line 413 of file Background.h.


The documentation for this class was generated from the following files: