LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
warpExposure.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 /*
26  * Support for warping an image to a new WCS.
27  */
28 
29 #ifndef LSST_AFW_MATH_WARPEXPOSURE_H
30 #define LSST_AFW_MATH_WARPEXPOSURE_H
31 
32 #include <memory>
33 #include <string>
34 
35 #include "lsst/base.h"
36 #include "lsst/pex/exceptions.h"
37 #include "lsst/geom.h"
38 #include "lsst/afw/geom.h"
42 #include "lsst/afw/math/Function.h"
44 #include "lsst/afw/math/Kernel.h"
45 
46 namespace lsst {
47 namespace afw {
48 namespace geom {
49 class SkyWcs;
50 }
51 namespace math {
52 
66 public:
67  explicit LanczosWarpingKernel(int order
68  )
69  : SeparableKernel(2 * order, 2 * order, LanczosFunction1<Kernel::Pixel>(order),
70  LanczosFunction1<Kernel::Pixel>(order)) {}
71 
74  LanczosWarpingKernel &operator=(const LanczosWarpingKernel &) = delete;
75  LanczosWarpingKernel &operator=(LanczosWarpingKernel &&) = delete;
76 
77  ~LanczosWarpingKernel() override = default;
78 
79  std::shared_ptr<Kernel> clone() const override;
80 
84  int getOrder() const;
85 
86 protected:
87  void setKernelParameter(unsigned int ind, double value) const override;
88 };
89 
100 public:
103 
106  BilinearWarpingKernel &operator=(const BilinearWarpingKernel &) = delete;
107  BilinearWarpingKernel &operator=(BilinearWarpingKernel &&) = delete;
108 
109  ~BilinearWarpingKernel() override = default;
110 
111  std::shared_ptr<Kernel> clone() const override;
112 
120  class BilinearFunction1 : public Function1<Kernel::Pixel> {
121  public:
123 
127  explicit BilinearFunction1(double fracPos)
128  : Function1<Kernel::Pixel>(1) {
129  this->_params[0] = fracPos;
130  }
131  ~BilinearFunction1() override {}
132 
133  Function1Ptr clone() const override { return Function1Ptr(new BilinearFunction1(this->_params[0])); }
134 
142  Kernel::Pixel operator()(double x) const override;
143 
147  std::string toString(std::string const & = "") const override;
148  };
149 
150 protected:
151  void setKernelParameter(unsigned int ind, double value) const override;
152 };
153 
164 public:
166 
167  NearestWarpingKernel(const NearestWarpingKernel &) = delete;
169  NearestWarpingKernel &operator=(const NearestWarpingKernel &) = delete;
170  NearestWarpingKernel &operator=(NearestWarpingKernel &&) = delete;
171 
172  ~NearestWarpingKernel() override = default;
173 
174  std::shared_ptr<Kernel> clone() const override;
175 
183  class NearestFunction1 : public Function1<Kernel::Pixel> {
184  public:
186 
190  explicit NearestFunction1(double fracPos)
191  : Function1<Kernel::Pixel>(1) {
192  this->_params[0] = fracPos;
193  }
194  ~NearestFunction1() override {}
195 
196  Function1Ptr clone() const override { return Function1Ptr(new NearestFunction1(this->_params[0])); }
197 
205  Kernel::Pixel operator()(double x) const override;
206 
210  std::string toString(std::string const & = "") const override;
211  };
212 
213 protected:
214  void setKernelParameter(unsigned int ind, double value) const override;
215 };
216 
242 
251 public:
258  explicit WarpingControl(
260  std::string const &maskWarpingKernelName = "",
262  int cacheSize = 0,
267  int interpLength = 0,
269  lsst::afw::image::MaskPixel growFullMask = 0
271  )
272  : _warpingKernelPtr(makeWarpingKernel(warpingKernelName)),
273  _maskWarpingKernelPtr(),
274  _cacheSize(cacheSize),
275  _interpLength(interpLength),
276  _growFullMask(growFullMask) {
277  setMaskWarpingKernelName(maskWarpingKernelName);
278  }
279 
280  virtual ~WarpingControl(){};
281 
285  int getCacheSize() const { return _cacheSize; };
286 
296  ) {
297  _cacheSize = cacheSize;
298  };
299 
303  int getInterpLength() const { return _interpLength; };
304 
313  void setInterpLength(int interpLength
314  ) {
315  _interpLength = interpLength;
316  };
317 
321  std::shared_ptr<SeparableKernel> getWarpingKernel() const;
322 
326  void setWarpingKernelName(std::string const &warpingKernelName
327  );
328 
334  void setWarpingKernel(SeparableKernel const &warpingKernel
335  );
336 
340  std::shared_ptr<SeparableKernel> getMaskWarpingKernel() const;
341 
345  bool hasMaskWarpingKernel() const { return static_cast<bool>(_maskWarpingKernelPtr); }
346 
350  void setMaskWarpingKernelName(std::string const &maskWarpingKernelName
352  );
353 
359  void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel
360  );
361 
365  lsst::afw::image::MaskPixel getGrowFullMask() const { return _growFullMask; };
366 
371  ) {
373  _growFullMask = growFullMask;
374  }
375 
376 private:
383  void _testWarpingKernels(SeparableKernel const &warpingKernel,
384  SeparableKernel const &maskWarpingKernel
385  ) const;
386 
387  std::shared_ptr<SeparableKernel> _warpingKernelPtr;
388  std::shared_ptr<SeparableKernel> _maskWarpingKernelPtr;
389  int _cacheSize;
390  int _interpLength;
391  lsst::afw::image::MaskPixel _growFullMask;
392 };
393 
399 template <typename DestExposureT, typename SrcExposureT>
400 int warpExposure(
401  DestExposureT &destExposure,
402  SrcExposureT const &srcExposure,
405  WarpingControl const &control,
406  typename DestExposureT::MaskedImageT::SinglePixel padValue =
407  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
409  typename DestExposureT::MaskedImageT>::image_category())
411 );
412 
459 template <typename DestImageT, typename SrcImageT>
460 int warpImage(DestImageT &destImage,
461  geom::SkyWcs const &destWcs,
462  SrcImageT const &srcImage,
463  geom::SkyWcs const &srcWcs,
464  WarpingControl const &control,
465  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
468 );
469 
484 template <typename DestImageT, typename SrcImageT>
485 int warpImage(DestImageT &destImage, SrcImageT const &srcImage,
486  geom::TransformPoint2ToPoint2 const &srcToDest, WarpingControl const &control,
487  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
489 
495 template <typename DestImageT, typename SrcImageT>
497  DestImageT &destImage,
498  SrcImageT const &srcImage,
499  lsst::geom::LinearTransform const &linearTransform,
500  lsst::geom::Point2D const &centerPosition,
501  WarpingControl const &control,
502  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
505 );
506 
507 } // namespace math
508 } // namespace afw
509 } // namespace lsst
510 
511 #endif // !defined(LSST_AFW_MATH_WARPEXPOSURE_H)
lsst::afw::image::MaskPixel getGrowFullMask() const
get mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:365
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
afw::table::Key< int > cacheSize
Definition: CoaddPsf.cc:339
1-dimensional Lanczos function
afw::table::Key< std::string > warpingKernelName
Definition: CoaddPsf.cc:341
Basic LSST definitions.
int warpImage(DestImageT &destImage, SrcImageT const &srcImage, geom::TransformPoint2ToPoint2 const &srcToDest, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
A variant of warpImage that uses a Transform<Point2Endpoint, Point2Endpoint> instead of a pair of WCS...
Function1Ptr clone() const override
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:196
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:898
Parameters to control convolution.
Definition: warpExposure.h:250
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:295
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:185
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
STL class.
int warpExposure(DestExposureT &destExposure, SrcExposureT const &srcExposure, WarpingControl const &control, typename DestExposureT::MaskedImageT::SinglePixel padValue=lsst::afw::math::edgePixel< typename DestExposureT::MaskedImageT >(typename lsst::afw::image::detail::image_traits< typename DestExposureT::MaskedImageT >::image_category()))
Warp (remap) one exposure to another.
A base class for image defects.
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:303
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:313
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:370
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:120
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:285
A Function taking one argument.
Definition: Function.h:204
traits class for image categories
Definition: ImageBase.h:67
double x
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:99
Function1Ptr clone() const override
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:133
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:122
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:163
NearestFunction1(double fracPos)
Construct a Nearest interpolation function.
Definition: warpExposure.h:190
BilinearFunction1(double fracPos)
Construct a Bilinear interpolation function.
Definition: warpExposure.h:127
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:65
ImageT::image_category image_category
Definition: ImageBase.h:68
bool hasMaskWarpingKernel() const
return true if there is a mask kernel
Definition: warpExposure.h:345
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:183
WarpingControl(std::string const &warpingKernelName, std::string const &maskWarpingKernelName="", int cacheSize=0, int interpLength=0, lsst::afw::image::MaskPixel growFullMask=0)
Construct a WarpingControl object.
Definition: warpExposure.h:258
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:112
int warpCenteredImage(DestImageT &destImage, SrcImageT const &srcImage, lsst::geom::LinearTransform const &linearTransform, lsst::geom::Point2D const &centerPosition, 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 with a LinearTranform about a specified point.
A 2D linear coordinate transformation.
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67