LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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
 
boost::shared_ptr
< BackgroundControl
getBackgroundControl ()
 
boost::shared_ptr
< BackgroundControl const > 
getBackgroundControl () 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...
 
boost::shared_ptr
< 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 403 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:434
std::vector< int > _xsize
x size of sub images
Definition: Background.h:339
std::vector< int > _yorig
y origin ...
Definition: Background.h:338
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
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:337
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
std::vector< int > _ysize
y size ...
Definition: Background.h:340
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:434
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:434
std::vector< std::vector< double > > _gridColumns
Definition: Background.h:435
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:353
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:330
#define PTR(...)
Definition: base.h:41
std::vector< double > _ycen
y center ...
Definition: Background.h:336
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:774
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for &#39;n&#39; points.
Definition: Interpolate.cc:285
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:764
#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 418 of file BackgroundMI.cc.

422 {
423  auto const localBBox = afw::geom::Box2I(afw::geom::Point2I(0, 0), _imgBBox.getDimensions());
424  return makeApproximate(_xcen, _ycen, _statsImage, localBBox, actrl);
425 }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:434
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:335
Extent2I const getDimensions() const
Definition: Box.h:153
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:330
std::vector< double > _ycen
y center ...
Definition: Background.h:336
Point< int, 2 > Point2I
Definition: Point.h:283
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:295
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  // if we're approximating, don't bother with the rest of the interp-related work. Return from here.
326  if (_bctrl->getApproximateControl()->getStyle() != ApproximateControl::UNKNOWN) {
327  return doGetApproximate<PixelT>(*_bctrl->getApproximateControl(), _asUsedUndersampleStyle)->getImage();
328  }
329 
330  // =============================================================
331  // --> We'll store nxSample fully-interpolated columns to interpolate the rows over
332  // make a vector containing the y pixel coords for the column
333  int const width = _imgBBox.getWidth();
334  int const height = _imgBBox.getHeight();
335  auto const bboxOff = bbox.getMin() - _imgBBox.getMin();
336 
337  std::vector<int> ypix(height);
338  for (int iY = 0; iY < height; ++iY) {
339  ypix[iY] = iY;
340  }
341 
342  _gridColumns.resize(width);
343  for (int iX = 0; iX < nxSample; ++iX) {
344  _setGridColumns(interpStyle, undersampleStyle, iX, ypix);
345  }
346 
347  // create a shared_ptr to put the background image in and return to caller
348  // start with xy0 = 0 and set final xy0 later
350  PTR(image::Image<PixelT>)(new image::Image<PixelT>(bbox.getDimensions()));
351 
352  // go through row by row
353  // - interpolate on the gridcolumns that were pre-computed by the constructor
354  // - copy the values to an ImageT to return to the caller.
355  std::vector<double> xcenTmp, bgTmp;
356 
357  // N.b. There's no API to set defaultValue to other than NaN (due to issues with persistence
358  // that I don't feel like fixing; #2825). If we want to address this, this is the place
359  // to start, but note that NaN is treated specially -- it means, "Interpolate" so to allow
360  // us to put a NaN into the outputs some changes will be needed
361  double defaultValue = std::numeric_limits<double>::quiet_NaN();
362 
363  for (int y = 0, iY = bboxOff.getY(); y < bbox.getHeight(); ++y, ++iY) {
364  // build an interp object for this row
365  std::vector<double> bg_x(nxSample);
366  for (int iX = 0; iX < nxSample; iX++) {
367  bg_x[iX] = static_cast<double>(_gridColumns[iX][iY]);
368  }
369  cullNan(_xcen, bg_x, xcenTmp, bgTmp, defaultValue);
370 
371  PTR(Interpolate) intobj;
372  try {
373  intobj = makeInterpolate(xcenTmp, bgTmp, interpStyle);
374  } catch(pex::exceptions::OutOfRangeError &e) {
375  switch (undersampleStyle) {
376  case THROW_EXCEPTION:
377  LSST_EXCEPT_ADD(e, str(boost::format("Interpolating in y (iY = %d)") % iY));
378  throw;
379  case REDUCE_INTERP_ORDER:
380  {
381  if (bgTmp.empty()) {
382  xcenTmp.push_back(0);
383  bgTmp.push_back(defaultValue);
384 
385  intobj = makeInterpolate(xcenTmp, bgTmp, Interpolate::CONSTANT);
386  break;
387  } else {
388  intobj = makeInterpolate(xcenTmp, bgTmp, lookupMaxInterpStyle(bgTmp.size()));
389  }
390  }
391  break;
392  case INCREASE_NXNYSAMPLE:
393  LSST_EXCEPT_ADD(e, "The BackgroundControl UndersampleStyle INCREASE_NXNYSAMPLE is not supported.");
394  throw;
395  default:
396  LSST_EXCEPT_ADD(e, str(boost::format("The selected BackgroundControl "
397  "UndersampleStyle %d is not defined.") % undersampleStyle));
398  throw;
399  }
400  } catch(ex::Exception &e) {
401  LSST_EXCEPT_ADD(e, str(boost::format("Interpolating in y (iY = %d)") % iY));
402  throw;
403  }
404 
405  // fill the image with interpolated values
406  for (int iX = bboxOff.getX(), x = 0; x < bbox.getWidth(); ++iX, ++x) {
407  (*bg)(x, y) = static_cast<PixelT>(intobj->interpolate(iX));
408  }
409  }
410  bg->setXY0(bbox.getMin());
411 
412  return bg;
413 }
int y
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:434
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:335
int getMaxY() const
Definition: Box.h:129
for(FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
Definition: saturated.cc:82
bool contains(Point2I const &point) const
Return true if the box contains the point.
std::vector< std::vector< double > > _gridColumns
Definition: Background.h:435
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:353
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:330
#define PTR(...)
Definition: base.h:41
boost::shared_ptr< lsst::afw::image::Image< PixelT > > getImage() const
Method to interpolate and return the background for entire image.
Definition: Background.h:294
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
Interpolate::Style _asUsedInterpStyle
the style we actually used
Definition: Background.h:332
void _setGridColumns(Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle, int const iX, std::vector< int > const &ypix) const
int getMinY() const
Definition: Box.h:125
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
int getMinX() const
Definition: Box.h:124
double x
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for &#39;n&#39; points.
Definition: Interpolate.cc:285
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:309
#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:333
int getMaxX() const
Definition: Box.h:128
Point2I const getMin() const
Definition: Box.h:123
#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<InternalPixelT>(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 }
int y
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:434
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:335
std::vector< std::vector< double > > _gridColumns
Definition: Background.h:435
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:353
#define PTR(...)
Definition: base.h:41
double 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 423 of file Background.h.

423  {
424  return getPixel(_bctrl->getInterpStyle(), x, y);
425  }
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.
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
double x
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 429 of file Background.h.

429  {
430  return _statsImage;
431  }
lsst::afw::image::MaskedImage< InternalPixelT > _statsImage
Definition: Background.h:434
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:434
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:434

Member Data Documentation

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

Definition at line 435 of file Background.h.

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

Definition at line 434 of file Background.h.


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