Class BackgroundMI

Inheritance Relationships

Base Type

Class Documentation

class BackgroundMI : public lsst::afw::math::Background

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);

// get the background at a pixel at i_x,i_y
double someValue = backobj.getPixel(math::Interpolate::LINEAR, i_x, i_y);

Public Functions

template<typename ImageT>
BackgroundMI(ImageT const &img, BackgroundControl const &bgCtrl)

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

There is a ticket (#2825) to allow getImage to specify a default value to use when interpolation fails

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)

Parameters
  • img: ImageT (or MaskedImage) whose properties we want

  • bgCtrl: Control how the BackgroundMI is estimated

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

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

Parameters
  • imageDimensions: unbinned Image’s BBox

  • statsImage: Internal stats image

BackgroundMI(BackgroundMI const&)
BackgroundMI(BackgroundMI&&)
BackgroundMI &operator=(BackgroundMI const&)
BackgroundMI &operator=(BackgroundMI&&)
~BackgroundMI()
BackgroundMI &operator+=(float const delta)

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

Parameters
  • delta: Value to add

BackgroundMI &operator-=(float const delta)

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

Parameters
  • delta: Value to subtract

double getPixel(Interpolate::Style const style, int const x, int const y) const

Method to retrieve the background level at a pixel coord.

Return

an estimated background at x,y (double)

Parameters
  • style: How to interpolate

  • x: x-pixel coordinate (column)

  • y: y-pixel coordinate (row)

double getPixel(int const x, int const y) const

Return the background value at a point

Warning

This is very inefficient only use it for debugging, if then.

lsst::afw::image::MaskedImage<InternalPixelT> getStatsImage() const

Return the image of statistical quantities extracted from the image