lsst.afw  13.0-94-ga1c444047
Public Member Functions | 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

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)
 Recreate a BackgroundMI from the statsImage and the original Image's BBox. More...
 
virtual BackgroundMI & operator+= (float const delta)
 Add a scalar to the Background (equivalent to adding a constant to the original image) More...
 
virtual BackgroundMI & 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 >
std::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 >
std::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 >
std::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 >
std::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 >
std::shared_ptr< lsst::afw::image::Image< PixelT > > getImage () const
 Method to interpolate and return the background for entire image. More...
 
Interpolate::Style getAsUsedInterpStyle () const
 Return the Interpolate::Style that we actually used in the last call to getImage() More...
 
UndersampleStyle getAsUsedUndersampleStyle () const
 Return the UndersampleStyle that we actually used in the last call to getImage() More...
 
std::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
 Return the input image's (PARENT) bounding box. More...
 
std::shared_ptr< BackgroundControl > getBackgroundControl ()
 
std::shared_ptr< BackgroundControl const > getBackgroundControl () const
 

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...
 
- 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)
 Create a Background without any values in it. More...
 
virtual ~Background ()
 dtor More...
 
- Protected Attributes inherited from lsst::afw::math::Background
geom::Box2I _imgBBox
 size and origin of input image More...
 
std::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
std::shared_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 436 of file Background.h.

Constructor & Destructor Documentation

◆ BackgroundMI() [1/2]

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

Parameters
imgImageT (or MaskedImage) whose properties we want
bgCtrlControl how the BackgroundMI is estimated
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

Definition at line 81 of file BackgroundMI.cc.

◆ BackgroundMI() [2/2]

lsst::afw::math::BackgroundMI::BackgroundMI ( geom::Box2I const  imageDimensions,
image::MaskedImage< InternalPixelT > const &  statsImage 
)
explicit

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

Parameters
imageDimensionsunbinned Image's BBox
statsImageInternal stats image

Definition at line 107 of file BackgroundMI.cc.

Member Function Documentation

◆ getPixel() [1/2]

double lsst::afw::math::BackgroundMI::getPixel ( Interpolate::Style const  style,
int const  x,
int const  y 
) const

Method to retrieve the background level at a pixel coord.

Parameters
styleHow to interpolate
xx-pixel coordinate (column)
yy-pixel coordinate (row)
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.

Definition at line 178 of file BackgroundMI.cc.

◆ getPixel() [2/2]

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 508 of file Background.h.

◆ getStatsImage()

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 512 of file Background.h.

◆ operator+=()

BackgroundMI & 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 168 of file BackgroundMI.cc.

◆ operator-=()

BackgroundMI & 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 173 of file BackgroundMI.cc.


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