25 #if !defined(LSST_AFW_MATH_BACKGROUND_H)
26 #define LSST_AFW_MATH_BACKGROUND_H
30 #include <boost/preprocessor/seq.hpp>
32 #include "lsst/daf/base/Citizen.h"
33 #include "lsst/pex/exceptions.h"
76 if (nxSample <= 0 || nySample <= 0) {
77 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
78 str(boost::format(
"You must specify at least one point, not %dx%d") % nxSample %
93 std::string
const& prop,
102 if (nxSample <= 0 || nySample <= 0) {
103 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
104 str(boost::format(
"You must specify at least one point, not %dx%d") % nxSample %
129 _undersampleStyle(undersampleStyle),
133 if (nxSample <= 0 || nySample <= 0) {
134 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
135 str(boost::format(
"You must specify at least one point, not %dx%d") % nxSample %
154 std::string
const& undersampleStyle =
"THROW_EXCEPTION",
156 std::string
const& prop =
"MEANCLIP",
165 if (nxSample <= 0 || nySample <= 0) {
166 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
167 str(boost::format(
"You must specify at least one point, not %dx%d") % nxSample %
175 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
176 str(boost::format(
"nxSample must be position, not %d") % nxSample));
178 _nxSample = nxSample;
182 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
183 str(boost::format(
"nySample must be position, not %d") % nySample));
185 _nySample = nySample;
193 _undersampleStyle = undersampleStyle;
204 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
205 str(boost::format(
"Style %d is invalid") % _style));
226 std::shared_ptr<StatisticsControl> _sctrl;
228 std::shared_ptr<ApproximateControl> _actrl;
249 template <
typename ImageT>
280 template <
typename PixelT>
281 std::shared_ptr<lsst::afw::image::Image<PixelT>>
getImage(
284 return getImage<PixelT>(
_imgBBox, interpStyle, undersampleStyle);
293 template <
typename PixelT>
294 std::shared_ptr<lsst::afw::image::Image<PixelT>>
getImage(
295 std::string
const& interpStyle, std::string
const& undersampleStyle =
"THROW_EXCEPTION")
const {
304 template <
typename PixelT>
305 std::shared_ptr<lsst::afw::image::Image<PixelT>>
getImage(
308 return _getImage(bbox, interpStyle, undersampleStyle, static_cast<PixelT>(0));
315 template <
typename PixelT>
316 std::shared_ptr<lsst::afw::image::Image<PixelT>>
getImage(
318 std::string
const& undersampleStyle =
"THROW_EXCEPTION")
const {
327 template <
typename PixelT>
328 std::shared_ptr<lsst::afw::image::Image<PixelT>>
getImage()
const {
329 return getImage<PixelT>(
_bctrl->getInterpStyle(),
_bctrl->getUndersampleStyle());
351 return _getApproximate(actrl, undersampleStyle, disambiguate);
363 std::shared_ptr<BackgroundControl>
_bctrl;
383 #define LSST_makeBackground_getImage_types (Background::InternalPixelT)
384 #define LSST_makeBackground_getApproximate_types (Background::InternalPixelT)
385 #define LSST_makeBackground_getImage(m, v, T) \
386 virtual std::shared_ptr<lsst::afw::image::Image<T>> _getImage( \
387 lsst::afw::geom::Box2I const& bbox, \
388 Interpolate::Style const interpStyle, \
389 UndersampleStyle const undersampleStyle = \
394 #define LSST_makeBackground_getApproximate(m, v, T) \
395 virtual std::shared_ptr<Approximate<T>> _getApproximate( \
396 ApproximateControl const& actrl, \
397 UndersampleStyle const undersampleStyle = \
411 void _setCenOrigSize(
int const width,
int const height,
int const nxSample,
int const nySample);
438 template <
typename ImageT>
517 mutable std::vector<std::vector<double>> _gridColumns;
520 int const iX, std::vector<int>
const& ypix)
const;
522 #if defined(LSST_makeBackground_getImage)
525 #if 0 // keep for use in Background instantiations
526 #undef LSST_makeBackground_getImage_types
527 #undef LSST_makeBackground_getApproximate_types
529 #undef LSST_makeBackground_getImage
530 #undef LSST_makeBackground_getApproximate
536 template <
typename PixelT>
537 std::shared_ptr<image::Image<PixelT>> doGetImage(
geom::Box2I const& bbox,
541 template <
typename PixelT>
542 std::shared_ptr<Approximate<PixelT>> doGetApproximate(
ApproximateControl const& actrl,
550 template <
typename ImageT>
552 return std::shared_ptr<Background>(
new BackgroundMI(img, bgCtrl));
558 #endif // LSST_AFW_MATH_BACKGROUND_H
float InternalPixelT
type used for any internal images, and returned by getApproximate
std::vector< int > _xsize
x size of sub images
UndersampleStyle stringToUndersampleStyle(std::string const &style)
Conversion function to switch a string to an UndersampleStyle.
std::vector< double > _xcen
x center pix coords of sub images
Interpolate::Style stringToInterpStyle(std::string const &style)
Conversion function to switch a string to an Interpolate::Style.
std::vector< int > _yorig
y origin ...
void setNySample(int nySample)
geom::Box2I getImageBBox() const
Return the input image's (PARENT) bounding box.
Background(ImageT const &img, BackgroundControl const &bgCtrl)
Constructor for Background.
geom::Box2I _imgBBox
size and origin of input image
BackgroundControl(Interpolate::Style const style, int const nxSample=10, int const nySample=10, UndersampleStyle const undersampleStyle=THROW_EXCEPTION, StatisticsControl const sctrl=StatisticsControl(), Property const prop=MEANCLIP, ApproximateControl const actrl=ApproximateControl(ApproximateControl::UNKNOWN, 1))
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.
std::shared_ptr< Background > makeBackground(ImageT const &img, BackgroundControl const &bgCtrl)
A convenience function that uses function overloading to make the correct type of Background...
std::shared_ptr< ApproximateControl > getApproximateControl()
void setInterpStyle(Interpolate::Style const style)
#define LSST_makeBackground_getApproximate_types
std::vector< double > _ycen
y center ...
BackgroundControl(int const nxSample, int const nySample, StatisticsControl const &sctrl, std::string const &prop, ApproximateControl const actrl=ApproximateControl(ApproximateControl::UNKNOWN, 1))
Overload constructor to handle string for statistical operator.
void setStatisticsProperty(std::string prop)
Pass parameters to a Background object.
Interpolate::Style getAsUsedInterpStyle() const
Return the Interpolate::Style that we actually used in the last call to getImage() ...
std::shared_ptr< math::Approximate< InternalPixelT > > getApproximate(ApproximateControl const &actrl, UndersampleStyle const undersampleStyle=THROW_EXCEPTION) const
Method to return an approximation to the background.
A virtual base class to evaluate image background levels.
An integer coordinate rectangle.
Property getStatisticsProperty() const
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
Control how to make an approximation.
void setUndersampleStyle(std::string const &undersampleStyle)
Pass parameters to a Statistics object.
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Interpolate::Style _asUsedInterpStyle
the style we actually used
virtual ~BackgroundControl()
std::shared_ptr< BackgroundControl > getBackgroundControl()
virtual ~Background()
dtor
Interpolate::Style getInterpStyle() const
std::shared_ptr< StatisticsControl > getStatisticsControl()
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
UndersampleStyle getUndersampleStyle() const
void setUndersampleStyle(UndersampleStyle const undersampleStyle)
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
std::shared_ptr< ApproximateControl const > getApproximateControl() const
virtual Background & operator+=(float const delta)=0
Add a constant level to a background.
lsst::afw::image::MaskedImage< InternalPixelT > getStatsImage() const
Return the image of statistical quantities extracted from the image.
BackgroundControl(std::string const &style, int const nxSample=10, int const nySample=10, std::string const &undersampleStyle="THROW_EXCEPTION", StatisticsControl const sctrl=StatisticsControl(), std::string const &prop="MEANCLIP", ApproximateControl const actrl=ApproximateControl(ApproximateControl::UNKNOWN, 1))
Overload constructor to handle strings for both interp and undersample styles.
#define LSST_makeBackground_getImage_types
#define LSST_makeBackground_getImage(m, v, T)
std::shared_ptr< BackgroundControl const > getBackgroundControl() const
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.
BackgroundControl(int const nxSample, int const nySample, StatisticsControl const sctrl=StatisticsControl(), Property const prop=MEANCLIP, ApproximateControl const actrl=ApproximateControl(ApproximateControl::UNKNOWN, 1))
std::vector< int > _xorig
x origin pix coords of sub images
std::shared_ptr< StatisticsControl const > getStatisticsControl() const
virtual Background & operator-=(float const delta)=0
Subtract a constant level from a background.
std::shared_ptr< BackgroundControl > _bctrl
control info set by user.
std::vector< int > _ysize
y size ...
UndersampleStyle _asUsedUndersampleStyle
the undersampleStyle we actually used
void setInterpStyle(std::string const &style)
double getPixel(int const x, int const y) const
Return the background value at a point.
#define LSST_makeBackground_getApproximate(m, v, T)
A class to evaluate image background levels.
std::shared_ptr< lsst::afw::image::Image< PixelT > > getImage() const
Method to interpolate and return the background for entire image.
Property
control what is calculated
void setStatisticsProperty(Property prop)
UndersampleStyle getAsUsedUndersampleStyle() const
Return the UndersampleStyle that we actually used in the last call to getImage()
void setNxSample(int nxSample)
void setApproximateControl(std::shared_ptr< ApproximateControl > actrl)