LSSTApplications  20.0.0
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 
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(
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 
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 
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::math::WarpingControl::setWarpingKernelName
void setWarpingKernelName(std::string const &warpingKernelName)
set the warping kernel by name
Definition: warpExposure.cc:186
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1::operator()
Kernel::Pixel operator()(double x) const override
Solve bilinear equation.
Definition: warpExposure.cc:112
lsst::afw::math::WarpingControl
Parameters to control convolution.
Definition: warpExposure.h:250
lsst::afw::math::NearestWarpingKernel::NearestWarpingKernel
NearestWarpingKernel(const NearestWarpingKernel &)=delete
lsst::afw::math::LanczosWarpingKernel::getOrder
int getOrder() const
get the order of the kernel
Definition: warpExposure.cc:101
lsst::afw::math::NearestWarpingKernel::NearestWarpingKernel
NearestWarpingKernel(NearestWarpingKernel &&)=delete
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1::BilinearFunction1
BilinearFunction1(double fracPos)
Construct a Bilinear interpolation function.
Definition: warpExposure.h:127
lsst::afw::math::LanczosWarpingKernel::~LanczosWarpingKernel
~LanczosWarpingKernel() override=default
std::string
STL class.
std::shared_ptr< Kernel >
lsst::afw::math::NearestWarpingKernel::setKernelParameter
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
Definition: warpExposure.cc:149
lsst::afw::math::LanczosWarpingKernel::LanczosWarpingKernel
LanczosWarpingKernel(LanczosWarpingKernel &&)=delete
lsst::afw::math::LanczosWarpingKernel::LanczosWarpingKernel
LanczosWarpingKernel(const LanczosWarpingKernel &)=delete
lsst::afw::math::WarpingControl::~WarpingControl
virtual ~WarpingControl()
Definition: warpExposure.h:280
lsst::afw::math::BilinearWarpingKernel::clone
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: warpExposure.cc:108
cacheSize
afw::table::Key< int > cacheSize
Definition: CoaddPsf.cc:339
lsst::afw::math::BilinearWarpingKernel::BilinearWarpingKernel
BilinearWarpingKernel(const BilinearWarpingKernel &)=delete
lsst::geom::LinearTransform
A 2D linear coordinate transformation.
Definition: LinearTransform.h:69
lsst::afw::math::NearestWarpingKernel
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:163
lsst::afw::math::NearestWarpingKernel::~NearestWarpingKernel
~NearestWarpingKernel() override=default
FunctionLibrary.h
lsst::afw::math::makeWarpingKernel
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
Definition: warpExposure.cc:161
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::math::NearestWarpingKernel::NearestFunction1::clone
Function1Ptr clone() const override
Definition: warpExposure.h:196
lsst::afw::math::LanczosWarpingKernel::operator=
LanczosWarpingKernel & operator=(LanczosWarpingKernel &&)=delete
lsst::afw::math::WarpingControl::getMaskWarpingKernel
std::shared_ptr< SeparableKernel > getMaskWarpingKernel() const
get the mask warping kernel
Definition: warpExposure.cc:200
lsst::afw::math::NearestWarpingKernel::NearestWarpingKernel
NearestWarpingKernel()
Definition: warpExposure.h:165
geom.h
lsst::afw::math::LanczosWarpingKernel::setKernelParameter
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
Definition: warpExposure.cc:103
geom.h
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::image::detail::image_traits::image_category
ImageT::image_category image_category
Definition: ImageBase.h:67
warpingKernelName
afw::table::Key< std::string > warpingKernelName
Definition: CoaddPsf.cc:341
lsst::afw::math::WarpingControl::getGrowFullMask
lsst::afw::image::MaskPixel getGrowFullMask() const
get mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:365
lsst::afw::math::NearestWarpingKernel::operator=
NearestWarpingKernel & operator=(const NearestWarpingKernel &)=delete
lsst::afw::math::NearestWarpingKernel::NearestFunction1
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:183
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1::Function1Ptr
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:122
lsst::afw::math::WarpingControl::hasMaskWarpingKernel
bool hasMaskWarpingKernel() const
return true if there is a mask kernel
Definition: warpExposure.h:345
lsst::afw::math::BilinearWarpingKernel::setKernelParameter
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
Definition: warpExposure.cc:128
lsst::afw::math::BilinearWarpingKernel::BilinearWarpingKernel
BilinearWarpingKernel(BilinearWarpingKernel &&)=delete
lsst::afw::math::LanczosFunction1
1-dimensional Lanczos function
Definition: FunctionLibrary.h:927
lsst::afw::math::NearestWarpingKernel::NearestFunction1::toString
std::string toString(std::string const &="") const override
Return string representation.
Definition: warpExposure.cc:154
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst::afw::geom::TransformPoint2ToPoint2
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
lsst::afw::math::warpExposure
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.
Definition: warpExposure.cc:238
lsst::afw::math::NearestWarpingKernel::NearestFunction1::operator()
Kernel::Pixel operator()(double x) const override
Solve nearest neighbor equation.
Definition: warpExposure.cc:144
std::int32_t
lsst::afw::math::BilinearWarpingKernel
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:99
lsst::afw::math::LanczosWarpingKernel
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:65
base.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::math::BilinearWarpingKernel::operator=
BilinearWarpingKernel & operator=(const BilinearWarpingKernel &)=delete
lsst::afw::math::warpImage
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.
Definition: warpExposure.cc:283
lsst::afw::math::WarpingControl::setGrowFullMask
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:370
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1::toString
std::string toString(std::string const &="") const override
Return string representation.
Definition: warpExposure.cc:133
lsst::afw::math::Function< Kernel::Pixel >::_params
std::vector< double > _params
Definition: Function.h:185
lsst::geom
Definition: geomOperators.dox:4
LsstImageTypes.h
lsst::afw::math::WarpingControl::WarpingControl
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
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1::~BilinearFunction1
~BilinearFunction1() override
Definition: warpExposure.h:131
lsst::afw::math::WarpingControl::setInterpLength
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:313
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:120
lsst::afw::math::BilinearWarpingKernel::BilinearFunction1::clone
Function1Ptr clone() const override
Definition: warpExposure.h:133
lsst::afw::math::WarpingControl::setMaskWarpingKernelName
void setMaskWarpingKernelName(std::string const &maskWarpingKernelName)
set or clear the mask warping kernel by name
Definition: warpExposure.cc:209
lsst::afw::math::WarpingControl::getWarpingKernel
std::shared_ptr< SeparableKernel > getWarpingKernel() const
get the warping kernel
Definition: warpExposure.cc:179
lsst::afw::math::NearestWarpingKernel::NearestFunction1::~NearestFunction1
~NearestFunction1() override
Definition: warpExposure.h:194
Kernel.h
lsst::geom::Point< double, 2 >
lsst::afw::math::LanczosWarpingKernel::LanczosWarpingKernel
LanczosWarpingKernel(int order)
Definition: warpExposure.h:67
lsst::afw::math::NearestWarpingKernel::NearestFunction1::Function1Ptr
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:185
lsst::afw::math::WarpingControl::getCacheSize
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:285
lsst::afw::math::WarpingControl::setMaskWarpingKernel
void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel)
set the mask warping kernel
Definition: warpExposure.cc:218
lsst::afw::math::BilinearWarpingKernel::BilinearWarpingKernel
BilinearWarpingKernel()
Definition: warpExposure.h:101
lsst::afw::math::WarpingControl::setCacheSize
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:295
lsst::afw::math::Kernel
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:111
lsst::afw::math::NearestWarpingKernel::operator=
NearestWarpingKernel & operator=(NearestWarpingKernel &&)=delete
lsst::afw::math::BilinearWarpingKernel::~BilinearWarpingKernel
~BilinearWarpingKernel() override=default
lsst::afw::math::LanczosWarpingKernel::operator=
LanczosWarpingKernel & operator=(const LanczosWarpingKernel &)=delete
lsst::afw::math::LanczosWarpingKernel::clone
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: warpExposure.cc:97
lsst::afw::image::detail::image_traits
traits class for image categories
Definition: ImageBase.h:66
lsst::afw::math::BilinearWarpingKernel::operator=
BilinearWarpingKernel & operator=(BilinearWarpingKernel &&)=delete
lsst::afw::math::Function1
A Function taking one argument.
Definition: Function.h:202
Function.h
Exposure.h
ConvolveImage.h
lsst::afw::math::WarpingControl::getInterpLength
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:303
lsst::afw::math::WarpingControl::setWarpingKernel
void setWarpingKernel(SeparableKernel const &warpingKernel)
set the warping kernel
Definition: warpExposure.cc:191
lsst::afw::math::SeparableKernel
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:907
lsst::afw::math::NearestWarpingKernel::NearestFunction1::NearestFunction1
NearestFunction1(double fracPos)
Construct a Nearest interpolation function.
Definition: warpExposure.h:190
exceptions.h
lsst::afw::math::NearestWarpingKernel::clone
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: warpExposure.cc:140
lsst::afw::math::Kernel::Pixel
double Pixel
Definition: Kernel.h:113
lsst::afw::math::warpCenteredImage
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.
Definition: warpExposure.cc:510