LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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:115
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: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
Basic LSST definitions.