34 namespace algorithms {
38 inline double min4(
double a,
double b,
double c,
double d) {
42 inline double max4(
double a,
double b,
double c,
double d) {
49 int nx = im.getWidth();
50 int ny = im.getHeight();
53 out = std::make_shared<afw::detection::Psf::Image>(nx + 2 * xPad, ny + 2 * yPad);
54 out->setXY0(im.getX0() - xPad, im.getY0() - yPad);
62 geom::Box2I computeBBoxFromTransform(geom::Box2I
const bbox, geom::AffineTransform
const &t) {
63 static const int dst_padding = 0;
69 static const double maxTransformCoeff = 200.0;
71 if (t.getLinear().getMatrix().lpNorm<Eigen::Infinity>() > maxTransformCoeff) {
72 throw LSST_EXCEPT(pex::exceptions::RangeError,
"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;
95 geom::Box2I ret = geom::Box2I(
geom::Point2I(out_xlo, out_ylo),
115 afw::math::WarpingControl
const &wc) {
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 geom::Box2I bbox = computeBBoxFromTransform(im.getBBox(), srcToDest);
142 _undistortedPsf(undistortedPsf),
143 _distortion(distortion),
144 _warpingControl(control) {
154 _warpingControl(new
afw::math::WarpingControl(kernelName,
"", cache)) {
158 void WarpedPsf::_init() {
161 "Undistorted Psf passed to WarpedPsf must not be None/NULL");
166 if (!_warpingControl) {
168 "WarpingControl passed to WarpedPsf must not be None/NULL");
196 PTR(afw::detection::Psf::Psf::Image) ret = warpAffine(*im, srcToDest, *_warpingControl);
198 double normFactor = 1.0;
204 for (
int y = 0;
y != ret->getHeight(); ++
y) {
207 normFactor += *imPtr;
210 if (normFactor == 0.0) {
Extent< int, N > ceil(Extent< double, N > const &input) noexcept
Return the component-wise ceil (round towards more positive).
lsst::geom::AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, lsst::geom::Point2D const &inPoint)
Approximate a Transform by its local linearization.
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.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Parameters to control convolution.
Point< double, 2 > Point2D
A base class for image defects.
#define CONST_PTR(...)
A shared pointer to a const object.
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()))
Warp an Image or MaskedImage to a new Wcs.
virtual boost::shared_ptr< afw::detection::Psf > resized(int width, int height) const
Return a clone with specified kernel dimensions.
Reports errors in the logical structure of the program.
virtual geom::Point2D getAveragePosition() const
Return the average of the positions of the stars that went into this Psf.
virtual boost::shared_ptr< afw::detection::Psf > clone() const
Polymorphic deep copy. Usually unnecessary, as Psfs are immutable.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Extent< int, 2 > Extent2I
Reports invalid arguments.
An intermediate base class for Psfs that use an image representation.
Extent< int, N > floor(Extent< double, N > const &input) noexcept
Return the component-wise floor (round towards more negative).
Describe the colour of a source.
A polymorphic base class for representing an image's Point Spread Function.
boost::shared_ptr< afw::detection::Psf const > _undistortedPsf
An integer coordinate rectangle.
boost::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > _distortion
virtual boost::shared_ptr< afw::detection::Psf::Image > doComputeKernelImage(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...
image::Image< Pixel > Image
Image type returned by computeImage.
A Psf class that maps an arbitrary Psf through a coordinate transformation.
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.