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));
68 PTR(afw::detection::Psf::Image) warpAffine(
69 afw::detection::Psf::Image const &im, afw::geom::AffineTransform const &t,
70 afw::math::WarpingControl const &wc
72 static const int dst_padding = 0;
74 afw::geom::AffineXYTransform xyTransform(t);
76 afw::math::SeparableKernel
const& kernel = *wc.getWarpingKernel();
78 int const xPad = std::max(center.getX(), kernel.getWidth() - center.getX());
79 int const yPad = std::min(center.getY(), kernel.getHeight() - center.getY());
85 static const double maxTransformCoeff = 200.0;
87 if (t.getLinear().getMatrix().lpNorm<Eigen::Infinity>() > maxTransformCoeff) {
89 pex::exceptions::RangeError,
90 "Unexpectedly large transform passed to WarpedPsf"
95 int in_xlo = im.getX0();
96 int in_xhi = im.getX0() + im.getWidth() - 1;
97 int in_ylo = im.getY0();
98 int in_yhi = im.getY0() + im.getHeight() - 1;
109 int out_xlo =
floor(min4(c00.getX(),c01.getX(),c10.getX(),c11.getX())) - dst_padding;
110 int out_ylo =
floor(min4(c00.getY(),c01.getY(),c10.getY(),c11.getY())) - dst_padding;
111 int out_xhi =
ceil(max4(c00.getX(),c01.getX(),c10.getX(),c11.getX())) + dst_padding;
112 int out_yhi =
ceil(max4(c00.getY(),c01.getY(),c10.getY(),c11.getY())) + dst_padding;
116 = std::make_shared<afw::detection::Psf::Image>(out_xhi-out_xlo+1, out_yhi-out_ylo+1);
117 ret->setXY0(afw::geom::
Point2I(out_xlo,out_ylo));
120 PTR(afw::detection::Psf::Image) im_padded = zeroPadImage(im, xPad, yPad);
123 afw::math::
warpImage(*ret, *im_padded, xyTransform, wc, 0.0);
130 PTR(afw::detection::Psf const) undistortedPsf,
131 PTR(afw::geom::XYTransform const) distortion,
132 CONST_PTR(afw::math::WarpingControl) control
135 _undistortedPsf(undistortedPsf),
136 _distortion(distortion),
137 _warpingControl(control)
145 std::string
const& kernelName,
149 _undistortedPsf(undistortedPsf),
150 _distortion(distortion),
151 _warpingControl(new afw::math::WarpingControl(kernelName,
"", cache))
160 pex::exceptions::LogicError,
161 "Undistorted Psf passed to WarpedPsf must not be None/NULL"
166 pex::exceptions::LogicError,
167 "XYTransform passed to WarpedPsf must not be None/NULL"
172 pex::exceptions::LogicError,
173 "WarpingControl passed to WarpedPsf must not be None/NULL"
183 return std::make_shared<WarpedPsf>(_undistortedPsf->clone(), _distortion->clone(), _warpingControl);
187 afw::geom::
Point2D const & position, afw::
image::Color const & color
192 PTR(
Image) im = _undistortedPsf->computeKernelImage(tp, color);
195 PTR(afw::detection::Psf::Psf::Image) ret
198 double normFactor = 1.0;
204 for (
int y = 0;
y != ret->getHeight(); ++
y) {
207 normFactor += *imPtr;
210 if (normFactor == 0.0) {
211 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
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Point< double, 2 > Point2D
Extent< int, 2 > Extent2I
Extent< int, N > ceil(Extent< double, N > const &input)
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. See also convenience function warpExposure() to warp an Ex...
table::Key< table::Array< Kernel::Pixel > > image
#define LSST_EXCEPT(type,...)
Extent< int, N > floor(Extent< double, N > const &input)
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.
afw::table::Key< double > b
An intermediate base class for Psfs that use an image representation.
Include files required for standard LSST Exception handling.
A polymorphic base class for representing an image's Point Spread Function.
boost::shared_ptr< afw::detection::Psf const > _undistortedPsf
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