30 namespace lsst {
namespace meas {
namespace algorithms {
34 inline double min4(
double a,
double b,
double c,
double d) {
35 return std::min(std::min(a,b), std::min(c,d));
38 inline double max4(
double a,
double b,
double c,
double d) {
39 return std::max(std::max(a,b), std::max(c,d));
45 int nx = im.getWidth();
46 int ny = im.getHeight();
49 out->setXY0(im.getX0()-xPad, im.getY0()-yPad);
51 afw::geom::Box2I box(afw::geom::
Point2I(xPad,yPad), afw::geom::
Extent2I(nx,ny));
57 afw::geom::Box2I computeBBoxFromTransform
58 (afw::geom::Box2I const bbox,
59 afw::geom::AffineTransform const &t
61 static const int dst_padding = 0;
63 afw::geom::AffineXYTransform xyTransform(t);
69 static const double maxTransformCoeff = 200.0;
71 if (t.getLinear().getMatrix().lpNorm<Eigen::Infinity>() > maxTransformCoeff) {
73 pex::exceptions::RangeError,
74 "Unexpectedly large transform passed to WarpedPsf");
78 int in_xlo = bbox.getMinX();
79 int in_xhi = bbox.getMinX() + bbox.getWidth() - 1;
80 int in_ylo = bbox.getMinY();
81 int in_yhi = bbox.getMinY() + bbox.getHeight() - 1;
92 int out_xlo =
floor(min4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) - dst_padding;
93 int out_ylo =
floor(min4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) - dst_padding;
94 int out_xhi =
ceil(max4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) + dst_padding;
95 int out_yhi =
ceil(max4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) + dst_padding;
114 afw::detection::Psf::Image const &im, afw::geom::AffineTransform const &t,
115 afw::math::WarpingControl const &wc
117 afw::geom::AffineXYTransform xyTransform(t);
119 afw::math::SeparableKernel
const& kernel = *wc.getWarpingKernel();
121 int const xPad = std::max(center.getX(), kernel.getWidth() - center.getX());
122 int const yPad = std::max(center.getY(), kernel.getHeight() - center.getY());
125 afw::geom::Box2I bbox = computeBBoxFromTransform(im.getBBox(), t);
129 PTR(afw::detection::Psf::Image) im_padded = zeroPadImage(im, xPad, yPad);
132 afw::math::
warpImage(*ret, *im_padded, xyTransform, wc, 0.0);
139 PTR(afw::detection::Psf const) undistortedPsf,
140 PTR(afw::geom::XYTransform const) distortion,
141 CONST_PTR(afw::math::WarpingControl) control
144 _undistortedPsf(undistortedPsf),
145 _distortion(distortion),
146 _warpingControl(control)
154 std::string
const& kernelName,
158 _undistortedPsf(undistortedPsf),
159 _distortion(distortion),
160 _warpingControl(new afw::math::WarpingControl(kernelName,
"", cache))
169 pex::exceptions::LogicError,
170 "Undistorted Psf passed to WarpedPsf must not be None/NULL"
175 pex::exceptions::LogicError,
176 "XYTransform passed to WarpedPsf must not be None/NULL"
181 pex::exceptions::LogicError,
182 "WarpingControl passed to WarpedPsf must not be None/NULL"
192 return std::make_shared<WarpedPsf>(_undistortedPsf->clone(), _distortion->clone(), _warpingControl);
196 afw::geom::
Point2D const & position, afw::
image::Color const & color
201 PTR(
Image) im = _undistortedPsf->computeKernelImage(tp, color);
204 PTR(afw::detection::Psf::Psf::Image) ret
207 double normFactor = 1.0;
213 for (
int y = 0;
y != ret->getHeight(); ++
y) {
216 normFactor += *imPtr;
219 if (normFactor == 0.0) {
220 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"psf image has sum 0");
virtual afw::geom::Point2D getAveragePosition() const
Return the average of the positions of the stars that went into this Psf.
boost::shared_ptr< afw::math::WarpingControl const > _warpingControl
Include files required for standard LSST Exception handling.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Extent< int, N > ceil(Extent< double, N > const &input)
Return the component-wise ceil (round towards more positive).
An integer coordinate rectangle.
int warpImage(DestImageT &destImage, lsst::afw::image::Wcs const &destWcs, SrcImageT const &srcImage, lsst::afw::image::Wcs const &srcWcs, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
Warp an Image or MaskedImage to a new Wcs.
table::Key< table::Array< Kernel::Pixel > > image
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Extent< int, N > floor(Extent< double, N > const &input)
Return the component-wise floor (round towards more negative).
Support for warping an image to a new WCS.
WarpedPsf(boost::shared_ptr< afw::detection::Psf const > undistortedPsf, boost::shared_ptr< afw::geom::XYTransform const > distortion, boost::shared_ptr< afw::math::WarpingControl const > control)
Construct WarpedPsf from unwarped psf and distortion.
virtual afw::geom::Box2I doComputeBBox(afw::geom::Point2D const &position, afw::image::Color const &color) const
These virtual member functions are private, not protected, because we only want derived classes to im...
afw::table::Key< double > b
Point< double, 2 > Point2D
An intermediate base class for Psfs that use an image representation.
Describe the colour of a source.
#define CONST_PTR(...)
A shared pointer to a const object.
A polymorphic base class for representing an image's Point Spread Function.
boost::shared_ptr< afw::detection::Psf const > _undistortedPsf
Extent< int, 2 > Extent2I
image::Image< Pixel > Image
Image type returned by computeImage.
A Psf class that maps an arbitrary Psf through a coordinate transformation.
boost::shared_ptr< afw::geom::XYTransform const > _distortion