LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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
afw::table::Key< int > cacheSize
Definition: CoaddPsf.cc:339
1-dimensional Lanczos function
afw::table::Key< std::string > warpingKernelName
Definition: CoaddPsf.cc:341
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:895
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.
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
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:202
traits class for image categories
Definition: ImageBase.h:66
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
Basic LSST definitions.
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:67
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:111
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.