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 Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
lsst::afw::math::Background Class Referenceabstract

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

#include <Background.h>

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

Public Types

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)
 

Public Member Functions

virtual void operator+= (float const delta)=0
 Add a constant level to a background. More...
 
virtual void operator-= (float const delta)=0
 Subtract a constant level from a background. More...
 
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...
 

Protected Member Functions

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

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...
 

Private Member Functions

 Background (Background const &)
 
Backgroundoperator= (Background const &)
 
void _setCenOrigSize (int const width, int const height, int const nxSample, int const nySample)
 

Additional Inherited Members

- 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...
 

Detailed Description

A virtual base class to evaluate image background levels.

Definition at line 231 of file Background.h.

Member Typedef Documentation

type used for any internal images, and returned by getApproximate

Definition at line 240 of file Background.h.

Constructor & Destructor Documentation

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

Constructor for Background.

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
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 Background is estimated

Definition at line 59 of file Background.cc.

61  :
62  lsst::daf::base::Citizen(typeid(this)),
63  _imgBBox(img.getBBox()),
64  _bctrl(new BackgroundControl(bgCtrl)),
67  _xcen(0), _ycen(0), _xorig(0), _yorig(0), _xsize(0), _ysize(0)
68 {
69  if (_imgBBox.isEmpty()) {
70  throw LSST_EXCEPT(ex::InvalidParameterError, "Image contains no pixels");
71  }
72 
73  // Check that an int's large enough to hold the number of pixels
74  if (_imgBBox.getWidth()*static_cast<double>(_imgBBox.getHeight()) > std::numeric_limits<int>::max()) {
75  throw LSST_EXCEPT(lsst::pex::exceptions::OverflowError,
76  str(boost::format("Image %dx%d has more pixels than fit in an int (%d)")
77  % _imgBBox.getWidth() % _imgBBox.getHeight() % std::numeric_limits<int>::max()));
78  }
79 
80  _setCenOrigSize(_imgBBox.getWidth(), _imgBBox.getHeight(), bgCtrl.getNxSample(), bgCtrl.getNySample());
81 }
std::vector< int > _xsize
x size of sub images
Definition: Background.h:339
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:335
std::vector< int > _yorig
y origin ...
Definition: Background.h:338
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:330
std::vector< double > _ycen
y center ...
Definition: Background.h:336
Interpolate::Style _asUsedInterpStyle
the style we actually used
Definition: Background.h:332
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:166
int getWidth() const
Definition: Box.h:154
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getHeight() const
Definition: Box.h:155
std::vector< int > _xorig
x origin pix coords of sub images
Definition: Background.h:337
std::vector< int > _ysize
y size ...
Definition: Background.h:340
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
Definition: Background.h:333
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
void _setCenOrigSize(int const width, int const height, int const nxSample, int const nySample)
Definition: Background.cc:121
lsst::afw::math::Background::Background ( geom::Box2I const  imageBBox,
int const  nx,
int const  ny 
)
explicitprotected

Create a Background without any values in it

Note
This ctor is mostly used to create a Background given its sample values, and that (in turn) is mostly used to implement persistence.
Parameters
imageBBoxBounding box for image to be created by getImage()
nxNumber of samples in x-direction
nyNumber of samples in y-direction

Definition at line 90 of file Background.cc.

93  :
94  lsst::daf::base::Citizen(typeid(this)),
95  _imgBBox(imageBBox),
96  _bctrl(new BackgroundControl(nx, ny)),
99  _xcen(0), _ycen(0), _xorig(0), _yorig(0), _xsize(0), _ysize(0)
100 {
101  if (_imgBBox.isEmpty()) {
102  throw LSST_EXCEPT(ex::InvalidParameterError, "Image contains no pixels");
103  }
104 
105  // Check that an int's large enough to hold the number of pixels
106  if (_imgBBox.getWidth()*static_cast<double>(_imgBBox.getHeight()) > std::numeric_limits<int>::max()) {
107  throw LSST_EXCEPT(lsst::pex::exceptions::OverflowError,
108  str(boost::format("Image %dx%d has more pixels than fit in an int (%d)")
109  % _imgBBox.getWidth() % _imgBBox.getHeight() % std::numeric_limits<int>::max()));
110  }
111 
113 }
std::vector< int > _xsize
x size of sub images
Definition: Background.h:339
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:335
std::vector< int > _yorig
y origin ...
Definition: Background.h:338
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:330
std::vector< double > _ycen
y center ...
Definition: Background.h:336
Interpolate::Style _asUsedInterpStyle
the style we actually used
Definition: Background.h:332
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:166
int getWidth() const
Definition: Box.h:154
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getHeight() const
Definition: Box.h:155
std::vector< int > _xorig
x origin pix coords of sub images
Definition: Background.h:337
std::vector< int > _ysize
y size ...
Definition: Background.h:340
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
Definition: Background.h:333
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
void _setCenOrigSize(int const width, int const height, int const nxSample, int const nySample)
Definition: Background.cc:121
virtual lsst::afw::math::Background::~Background ( )
inlineprotectedvirtual

dtor

Definition at line 238 of file Background.h.

238 { }
lsst::afw::math::Background::Background ( Background const &  )
private

Member Function Documentation

void lsst::afw::math::Background::_setCenOrigSize ( int const  width,
int const  height,
int const  nxSample,
int const  nySample 
)
private

Compute the centers, origins, and sizes of the patches used to compute image statistics when estimating the Background

Definition at line 121 of file Background.cc.

123 {
124  _xcen.resize( nxSample); _ycen.resize(nySample);
125  _xorig.resize(nxSample); _yorig.resize(nySample);
126  _xsize.resize(nxSample), _ysize.resize(nySample);
127 
128  // Compute the centers and origins for the cells
129  for (int iX = 0; iX < nxSample; ++iX) {
130  const int endx = std::min(((iX+1)*width + nxSample/2)/nxSample, width);
131  _xorig[iX] = (iX == 0) ? 0 : _xorig[iX-1] + _xsize[iX-1];
132  _xsize[iX] = endx - _xorig[iX];
133  _xcen [iX] = _xorig[iX] + (0.5 * _xsize[iX]) - 0.5;
134  }
135 
136  for (int iY = 0; iY < nySample; ++iY) {
137  const int endy = std::min(((iY+1)*height + nySample/2)/nySample, height);
138  _yorig[iY] = (iY == 0) ? 0 : _yorig[iY-1] + _ysize[iY-1];
139  _ysize[iY] = endy - _yorig[iY];
140  _ycen [iY] = _yorig[iY] + (0.5 * _ysize[iY]) - 0.5;
141  }
142 }
std::vector< int > _xsize
x size of sub images
Definition: Background.h:339
std::vector< double > _xcen
x center pix coords of sub images
Definition: Background.h:335
std::vector< int > _yorig
y origin ...
Definition: Background.h:338
std::vector< double > _ycen
y center ...
Definition: Background.h:336
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
std::vector< int > _xorig
x origin pix coords of sub images
Definition: Background.h:337
std::vector< int > _ysize
y size ...
Definition: Background.h:340
boost::shared_ptr< math::Approximate<InternalPixelT> > lsst::afw::math::Background::getApproximate ( ApproximateControl const &  actrl,
UndersampleStyle const  undersampleStyle = THROW_EXCEPTION 
) const
inline

Method to return an approximation to the background.

Parameters
actrlApproximation style
undersampleStyleBehaviour if there are too few points

Definition at line 314 of file Background.h.

317  {
318  InternalPixelT disambiguate = 0;
319  return _getApproximate(actrl, undersampleStyle, disambiguate);
320  }
float InternalPixelT
type used for any internal images, and returned by getApproximate
Definition: Background.h:240
Interpolate::Style lsst::afw::math::Background::getAsUsedInterpStyle ( ) const
inline

Return the Interpolate::Style that we actually used in the last call to getImage()

N.b. Interpolate can fallback to a lower order if there aren't enough samples

Definition at line 302 of file Background.h.

302  {
303  return _asUsedInterpStyle;
304  }
Interpolate::Style _asUsedInterpStyle
the style we actually used
Definition: Background.h:332
UndersampleStyle lsst::afw::math::Background::getAsUsedUndersampleStyle ( ) const
inline

Return the UndersampleStyle that we actually used in the last call to getImage()

Definition at line 308 of file Background.h.

308  {
310  }
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
Definition: Background.h:333
boost::shared_ptr< BackgroundControl > lsst::afw::math::Background::getBackgroundControl ( )
inline

Definition at line 326 of file Background.h.

326 { return _bctrl; }
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
boost::shared_ptr< BackgroundControl const> lsst::afw::math::Background::getBackgroundControl ( ) const
inline

Definition at line 327 of file Background.h.

327 { return _bctrl; }
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
template<typename PixelT >
boost::shared_ptr< lsst::afw::image::Image<PixelT> > lsst::afw::math::Background::getImage ( Interpolate::Style const  interpStyle,
UndersampleStyle const  undersampleStyle = THROW_EXCEPTION 
) const
inline

Method to interpolate and return the background for entire image.

Returns
A boost shared-pointer to an image containing the estimated background
Parameters
interpStyleStyle of the interpolation
undersampleStyleBehaviour if there are too few points

Definition at line 252 of file Background.h.

255  {
256  return getImage<PixelT>(_imgBBox, interpStyle, undersampleStyle);
257  }
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:330
template<typename PixelT >
boost::shared_ptr< lsst::afw::image::Image<PixelT> > lsst::afw::math::Background::getImage ( std::string const &  interpStyle,
std::string const &  undersampleStyle = "THROW_EXCEPTION" 
) const
inline

Method to interpolate and return the background for entire image.

Returns
A boost shared-pointer to an image containing the estimated background
Parameters
interpStyleStyle of the interpolation
undersampleStyleBehaviour if there are too few points

Definition at line 264 of file Background.h.

267  {
268  return getImage<PixelT>(math::stringToInterpStyle(interpStyle),
269  stringToUndersampleStyle(undersampleStyle));
270  }
UndersampleStyle stringToUndersampleStyle(std::string const &style)
Conversion function to switch a string to an UndersampleStyle.
Definition: Background.cc:148
Interpolate::Style stringToInterpStyle(std::string const &style)
Conversion function to switch a string to an Interpolate::Style.
Definition: Interpolate.cc:262
template<typename PixelT >
boost::shared_ptr< lsst::afw::image::Image<PixelT> > lsst::afw::math::Background::getImage ( lsst::afw::geom::Box2I const &  bbox,
Interpolate::Style const  interpStyle,
UndersampleStyle const  undersampleStyle = THROW_EXCEPTION 
) const
inline
Parameters
bboxBounding box for sub-image
interpStyleStyle of the interpolation
undersampleStyleBehaviour if there are too few points

Definition at line 272 of file Background.h.

276  {
277  return _getImage(bbox, interpStyle, undersampleStyle, static_cast<PixelT>(0));
278  }
template<typename PixelT >
boost::shared_ptr< lsst::afw::image::Image<PixelT> > lsst::afw::math::Background::getImage ( lsst::afw::geom::Box2I const &  bbox,
std::string const &  interpStyle,
std::string const &  undersampleStyle = "THROW_EXCEPTION" 
) const
inline
Parameters
bboxBounding box for sub-image
interpStyleStyle of the interpolation
undersampleStyleBehaviour if there are too few points

Definition at line 280 of file Background.h.

284  {
285  return _getImage(bbox, math::stringToInterpStyle(interpStyle),
286  stringToUndersampleStyle(undersampleStyle), static_cast<PixelT>(0));
287  }
UndersampleStyle stringToUndersampleStyle(std::string const &style)
Conversion function to switch a string to an UndersampleStyle.
Definition: Background.cc:148
Interpolate::Style stringToInterpStyle(std::string const &style)
Conversion function to switch a string to an Interpolate::Style.
Definition: Interpolate.cc:262
template<typename PixelT >
boost::shared_ptr< lsst::afw::image::Image<PixelT> > lsst::afw::math::Background::getImage ( ) const
inline

Method to interpolate and return the background for entire image.

Deprecated:
New code should specify the interpolation style in getImage, not the ctor

Definition at line 294 of file Background.h.

294  {
295  return getImage<PixelT>(_bctrl->getInterpStyle(), _bctrl->getUndersampleStyle());
296  }
boost::shared_ptr< BackgroundControl > _bctrl
control info set by user.
Definition: Background.h:331
geom::Box2I lsst::afw::math::Background::getImageBBox ( ) const
inline

Return the input image's (PARENT) bounding box

Definition at line 324 of file Background.h.

324 { return _imgBBox; }
geom::Box2I _imgBBox
size and origin of input image
Definition: Background.h:330
virtual void lsst::afw::math::Background::operator+= ( float const  delta)
pure virtual

Add a constant level to a background.

Implemented in lsst::afw::math::BackgroundMI.

virtual void lsst::afw::math::Background::operator-= ( float const  delta)
pure virtual

Subtract a constant level from a background.

Implemented in lsst::afw::math::BackgroundMI.

Background& lsst::afw::math::Background::operator= ( Background const &  )
private

Member Data Documentation

Interpolate::Style lsst::afw::math::Background::_asUsedInterpStyle
mutableprotected

the style we actually used

Definition at line 332 of file Background.h.

UndersampleStyle lsst::afw::math::Background::_asUsedUndersampleStyle
mutableprotected

the undersampleStyle we actually used

Definition at line 333 of file Background.h.

boost::shared_ptr< BackgroundControl > lsst::afw::math::Background::_bctrl
protected

control info set by user.

Definition at line 331 of file Background.h.

geom::Box2I lsst::afw::math::Background::_imgBBox
protected

size and origin of input image

Definition at line 330 of file Background.h.

std::vector<double> lsst::afw::math::Background::_xcen
protected

x center pix coords of sub images

Definition at line 335 of file Background.h.

std::vector<int> lsst::afw::math::Background::_xorig
protected

x origin pix coords of sub images

Definition at line 337 of file Background.h.

std::vector<int> lsst::afw::math::Background::_xsize
protected

x size of sub images

Definition at line 339 of file Background.h.

std::vector<double> lsst::afw::math::Background::_ycen
protected

y center ...

Definition at line 336 of file Background.h.

std::vector<int> lsst::afw::math::Background::_yorig
protected

y origin ...

Definition at line 338 of file Background.h.

std::vector<int> lsst::afw::math::Background::_ysize
protected

y size ...

Definition at line 340 of file Background.h.


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