LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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 
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 
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 
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(
261  std::string const &maskWarpingKernelName = "",
266  int cacheSize = 0,
268  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 
322 
327  );
328 
334  void setWarpingKernel(SeparableKernel const &warpingKernel
335  );
336 
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 
372  ) {
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,
404  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)
table::Key< std::string > name
Definition: Amplifier.cc:116
double x
Basic LSST definitions.
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:120
std::string toString(std::string const &="") const override
Return string representation.
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:122
Function1Ptr clone() const override
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:133
BilinearFunction1(double fracPos)
Construct a Bilinear interpolation function.
Definition: warpExposure.h:127
Kernel::Pixel operator()(double x) const override
Solve bilinear equation.
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:99
BilinearWarpingKernel & operator=(BilinearWarpingKernel &&)=delete
BilinearWarpingKernel & operator=(const BilinearWarpingKernel &)=delete
BilinearWarpingKernel(BilinearWarpingKernel &&)=delete
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
BilinearWarpingKernel(const BilinearWarpingKernel &)=delete
A Function taking one argument.
Definition: Function.h:202
std::vector< double > _params
Definition: Function.h:185
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:111
1-dimensional Lanczos function
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:65
int getOrder() const
get the order of the kernel
LanczosWarpingKernel(const LanczosWarpingKernel &)=delete
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
~LanczosWarpingKernel() override=default
LanczosWarpingKernel & operator=(const LanczosWarpingKernel &)=delete
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: warpExposure.cc:97
LanczosWarpingKernel & operator=(LanczosWarpingKernel &&)=delete
LanczosWarpingKernel(LanczosWarpingKernel &&)=delete
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:183
NearestFunction1(double fracPos)
Construct a Nearest interpolation function.
Definition: warpExposure.h:190
Kernel::Pixel operator()(double x) const override
Solve nearest neighbor equation.
Function1Ptr clone() const override
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:196
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:185
std::string toString(std::string const &="") const override
Return string representation.
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:163
NearestWarpingKernel(NearestWarpingKernel &&)=delete
NearestWarpingKernel & operator=(NearestWarpingKernel &&)=delete
NearestWarpingKernel(const NearestWarpingKernel &)=delete
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
NearestWarpingKernel & operator=(const NearestWarpingKernel &)=delete
~NearestWarpingKernel() override=default
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:861
Parameters to control convolution.
Definition: warpExposure.h:250
bool hasMaskWarpingKernel() const
return true if there is a mask kernel
Definition: warpExposure.h:345
lsst::afw::image::MaskPixel getGrowFullMask() const
get mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:365
void setWarpingKernel(SeparableKernel const &warpingKernel)
set the warping kernel
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:303
void setWarpingKernelName(std::string const &warpingKernelName)
set the warping kernel by name
void setMaskWarpingKernelName(std::string const &maskWarpingKernelName)
set or clear the mask warping kernel by name
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:295
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:285
void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel)
set the mask warping kernel
std::shared_ptr< SeparableKernel > getWarpingKernel() const
get the warping kernel
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:370
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:313
std::shared_ptr< SeparableKernel > getMaskWarpingKernel() const
get the mask warping kernel
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
A 2D linear coordinate transformation.
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
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.
int warpImage(DestImageT &destImage, geom::SkyWcs const &destWcs, SrcImageT const &srcImage, geom::SkyWcs 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.
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.
afw::table::Key< int > cacheSize
Definition: CoaddPsf.cc:339
afw::table::Key< std::string > warpingKernelName
Definition: CoaddPsf.cc:341
traits class for image categories
Definition: ImageBase.h:66
ImageT::image_category image_category
Definition: ImageBase.h:67