30 namespace lsst {
namespace meas {
namespace algorithms {
34 inline double min4(
double a,
double b,
double c,
double d) {
38 inline double max4(
double a,
double b,
double c,
double d) {
45 int nx = im.getWidth();
46 int ny = im.getHeight();
49 out->setXY0(im.getX0()-xPad, im.getY0()-yPad);
57 afw::geom::Box2I computeBBoxFromTransform
58 (afw::geom::Box2I
const bbox,
59 afw::geom::AffineTransform
const &t
61 static const int dst_padding = 0;
67 static const double maxTransformCoeff = 200.0;
69 if (t.getLinear().getMatrix().lpNorm<Eigen::Infinity>() > maxTransformCoeff) {
71 pex::exceptions::RangeError,
72 "Unexpectedly large transform passed to WarpedPsf");
76 int in_xlo = bbox.getMinX();
77 int in_xhi = bbox.getMinX() + bbox.getWidth() - 1;
78 int in_ylo = bbox.getMinY();
79 int in_yhi = bbox.getMinY() + bbox.getHeight() - 1;
90 int out_xlo =
floor(min4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) - dst_padding;
91 int out_ylo =
floor(min4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) - dst_padding;
92 int out_xhi =
ceil(max4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) + dst_padding;
93 int out_yhi =
ceil(max4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) + dst_padding;
115 afw::math::WarpingControl
const &wc
120 afw::math::SeparableKernel
const& kernel = *wc.getWarpingKernel();
122 int const xPad =
std::max(center.getX(), kernel.getWidth() - center.getX());
123 int const yPad =
std::max(center.getY(), kernel.getHeight() - center.getY());
126 afw::geom::Box2I bbox = computeBBoxFromTransform(im.getBBox(), srcToDest);
145 _undistortedPsf(undistortedPsf),
146 _distortion(distortion),
147 _warpingControl(control)
161 _warpingControl(new afw::
math::WarpingControl(kernelName,
"", cache))
166 void WarpedPsf::_init()
171 "Undistorted Psf passed to WarpedPsf must not be None/NULL" 177 "Transform passed to WarpedPsf must not be None/NULL" 180 if (!_warpingControl) {
183 "WarpingControl passed to WarpedPsf must not be None/NULL" 213 PTR(afw::detection::Psf::Psf::Image) ret = warpAffine(*im, srcToDest, *_warpingControl);
215 double normFactor = 1.0;
221 for (
int y = 0;
y != ret->getHeight(); ++
y) {
224 normFactor += *imPtr;
227 if (normFactor == 0.0) {
WarpedPsf(boost::shared_ptr< afw::detection::Psf const > undistortedPsf, boost::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > distortion, boost::shared_ptr< afw::math::WarpingControl const > control)
Construct WarpedPsf from unwarped psf and distortion.
virtual afw::geom::Point2D getAveragePosition() const
Return the average of the positions of the stars that went into this Psf.
_view_t::x_iterator x_iterator
Extent< int, 2 > Extent2I
AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, Point2D const &inPoint)
Point< double, 2 > Point2D
virtual boost::shared_ptr< afw::detection::Psf::Image > doComputeKernelImage(afw::geom::Point2D const &position, afw::image::Color const &color) const
int warpImage(DestImageT &destImage, geom::SkyWcs const &destWcs, SrcImageT const &srcImage, geom::SkyWcs const &srcWcs, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
virtual boost::shared_ptr< afw::detection::Psf > resized(int width, int height) const
Return a clone with specified kernel dimensions.
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(AffineTransform const &affine)
virtual boost::shared_ptr< afw::detection::Psf > clone() const
Polymorphic deep copy. Usually unnecessary, as Psfs are immutable.
#define LSST_EXCEPT(type,...)
afw::table::Key< double > b
An intermediate base class for Psfs that use an image representation.
boost::shared_ptr< afw::detection::Psf const > _undistortedPsf
boost::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > _distortion
image::Image< Pixel > Image