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));
52 PTR(afw::detection::Psf::Image) subimage = boost::make_shared<afw::detection::Psf::Image>(
69 PTR(afw::detection::Psf::Image) warpAffine(
70 afw::detection::Psf::Image const &im, afw::geom::AffineTransform const &t,
71 afw::math::WarpingControl const &wc
73 static const int dst_padding = 0;
75 afw::math::SeparableKernel
const& kernel = *wc.getWarpingKernel();
77 int const xPad = std::max(center.getX(), kernel.getWidth() - center.getX());
78 int const yPad = std::min(center.getY(), kernel.getHeight() - center.getY());
84 static const double maxTransformCoeff = 200.0;
86 if (t.getLinear().getMatrix().lpNorm<Eigen::Infinity>() > maxTransformCoeff) {
88 pex::exceptions::RangeError,
89 "Unexpectedly large transform passed to WarpedPsf"
94 int in_xlo = im.getX0();
95 int in_xhi = im.getX0() + im.getWidth() - 1;
96 int in_ylo = im.getY0();
97 int in_yhi = im.getY0() + im.getHeight() - 1;
108 int out_xlo =
floor(min4(c00.getX(),c01.getX(),c10.getX(),c11.getX())) - dst_padding;
109 int out_ylo =
floor(min4(c00.getY(),c01.getY(),c10.getY(),c11.getY())) - dst_padding;
110 int out_xhi =
ceil(max4(c00.getX(),c01.getX(),c10.getX(),c11.getX())) + dst_padding;
111 int out_yhi =
ceil(max4(c00.getY(),c01.getY(),c10.getY(),c11.getY())) + dst_padding;
115 = boost::make_shared<afw::detection::Psf::Image>(out_xhi-out_xlo+1, out_yhi-out_ylo+1);
116 ret->setXY0(afw::geom::
Point2I(out_xlo,out_ylo));
119 PTR(afw::detection::Psf::Image) im_padded = zeroPadImage(im, xPad, yPad);
122 afw::math::
warpImage(*ret, *im_padded, t, wc, 0.0);
129 PTR(afw::detection::Psf const) undistortedPsf,
130 PTR(afw::geom::XYTransform const) distortion,
131 CONST_PTR(afw::math::WarpingControl) control
134 _undistortedPsf(undistortedPsf),
135 _distortion(distortion),
136 _warpingControl(control)
144 std::string
const& kernelName,
148 _undistortedPsf(undistortedPsf),
149 _distortion(distortion),
150 _warpingControl(new afw::math::WarpingControl(kernelName,
"", cache))
159 pex::exceptions::LogicError,
160 "Undistorted Psf passed to WarpedPsf must not be None/NULL"
165 pex::exceptions::LogicError,
166 "XYTransform passed to WarpedPsf must not be None/NULL"
171 pex::exceptions::LogicError,
172 "WarpingControl passed to WarpedPsf must not be None/NULL"
182 return boost::make_shared<WarpedPsf>(_undistortedPsf->clone(), _distortion->clone(), _warpingControl);
186 afw::geom::
Point2D const & position, afw::
image::Color const & color
191 PTR(
Image) im = _undistortedPsf->computeKernelImage(tp, color);
194 PTR(afw::detection::Psf::Psf::Image) ret
197 double normFactor = 1.0;
203 for (
int y = 0;
y != ret->getHeight(); ++
y) {
206 normFactor += *imPtr;
209 if (normFactor == 0.0) {
210 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.
Include files required for standard LSST Exception handling.
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.
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