lsst.afw  14.0-69-ge506bfb5f
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/afw/geom.h"
41 #include "lsst/afw/math/Function.h"
43 #include "lsst/afw/math/Kernel.h"
44 
45 namespace lsst {
46 namespace afw {
47 namespace geom {
48 class SkyWcs;
49 }
50 namespace math {
51 
65 public:
66  explicit LanczosWarpingKernel(int order
67  )
68  : SeparableKernel(2 * order, 2 * order, LanczosFunction1<Kernel::Pixel>(order),
69  LanczosFunction1<Kernel::Pixel>(order)) {}
70 
73  LanczosWarpingKernel &operator=(const LanczosWarpingKernel &) = delete;
74  LanczosWarpingKernel &operator=(LanczosWarpingKernel &&) = delete;
75 
76  virtual ~LanczosWarpingKernel() = default;
77 
78  virtual std::shared_ptr<Kernel> clone() const;
79 
83  int getOrder() const;
84 
85 protected:
86  virtual void setKernelParameter(unsigned int ind, double value) const;
87 };
88 
99 public:
102 
105  BilinearWarpingKernel &operator=(const BilinearWarpingKernel &) = delete;
106  BilinearWarpingKernel &operator=(BilinearWarpingKernel &&) = delete;
107 
108  virtual ~BilinearWarpingKernel() = default;
109 
110  virtual std::shared_ptr<Kernel> clone() const;
111 
119  class BilinearFunction1 : public Function1<Kernel::Pixel> {
120  public:
122 
126  explicit BilinearFunction1(double fracPos)
127  : Function1<Kernel::Pixel>(1) {
128  this->_params[0] = fracPos;
129  }
130  virtual ~BilinearFunction1() {}
131 
132  virtual Function1Ptr clone() const { return Function1Ptr(new BilinearFunction1(this->_params[0])); }
133 
141  virtual Kernel::Pixel operator()(double x) const;
142 
146  virtual std::string toString(std::string const & = "") const;
147  };
148 
149 protected:
150  virtual void setKernelParameter(unsigned int ind, double value) const;
151 };
152 
163 public:
165 
166  NearestWarpingKernel(const NearestWarpingKernel &) = delete;
168  NearestWarpingKernel &operator=(const NearestWarpingKernel &) = delete;
169  NearestWarpingKernel &operator=(NearestWarpingKernel &&) = delete;
170 
171  virtual ~NearestWarpingKernel() = default;
172 
173  virtual std::shared_ptr<Kernel> clone() const;
174 
182  class NearestFunction1 : public Function1<Kernel::Pixel> {
183  public:
185 
189  explicit NearestFunction1(double fracPos)
190  : Function1<Kernel::Pixel>(1) {
191  this->_params[0] = fracPos;
192  }
193  virtual ~NearestFunction1() {}
194 
195  virtual Function1Ptr clone() const { return Function1Ptr(new NearestFunction1(this->_params[0])); }
196 
204  virtual Kernel::Pixel operator()(double x) const;
205 
209  virtual std::string toString(std::string const & = "") const;
210  };
211 
212 protected:
213  virtual void setKernelParameter(unsigned int ind, double value) const;
214 };
215 
241 
250 public:
257  explicit WarpingControl(
258  std::string const &warpingKernelName,
259  std::string const &maskWarpingKernelName = "",
261  int cacheSize = 0,
266  int interpLength = 0,
268  lsst::afw::image::MaskPixel growFullMask = 0
270  )
271  : _warpingKernelPtr(makeWarpingKernel(warpingKernelName)),
272  _maskWarpingKernelPtr(),
273  _cacheSize(cacheSize),
274  _interpLength(interpLength),
275  _growFullMask(growFullMask) {
276  setMaskWarpingKernelName(maskWarpingKernelName);
277  }
278 
279  virtual ~WarpingControl(){};
280 
284  int getCacheSize() const { return _cacheSize; };
285 
294  void setCacheSize(int cacheSize
295  ) {
296  _cacheSize = cacheSize;
297  };
298 
302  int getInterpLength() const { return _interpLength; };
303 
312  void setInterpLength(int interpLength
313  ) {
314  _interpLength = interpLength;
315  };
316 
320  std::shared_ptr<SeparableKernel> getWarpingKernel() const;
321 
325  void setWarpingKernelName(std::string const &warpingKernelName
326  );
327 
333  void setWarpingKernel(SeparableKernel const &warpingKernel
334  );
335 
339  std::shared_ptr<SeparableKernel> getMaskWarpingKernel() const;
340 
344  bool hasMaskWarpingKernel() const { return static_cast<bool>(_maskWarpingKernelPtr); }
345 
349  void setMaskWarpingKernelName(std::string const &maskWarpingKernelName
351  );
352 
358  void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel
359  );
360 
364  lsst::afw::image::MaskPixel getGrowFullMask() const { return _growFullMask; };
365 
370  ) {
372  _growFullMask = growFullMask;
373  }
374 
375 private:
382  void _testWarpingKernels(SeparableKernel const &warpingKernel,
383  SeparableKernel const &maskWarpingKernel
384  ) const;
385 
386  std::shared_ptr<SeparableKernel> _warpingKernelPtr;
387  std::shared_ptr<SeparableKernel> _maskWarpingKernelPtr;
388  int _cacheSize;
389  int _interpLength;
390  lsst::afw::image::MaskPixel _growFullMask;
391 };
392 
398 template <typename DestExposureT, typename SrcExposureT>
399 int warpExposure(
400  DestExposureT &destExposure,
401  SrcExposureT const &srcExposure,
404  WarpingControl const &control,
405  typename DestExposureT::MaskedImageT::SinglePixel padValue =
406  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
408  typename DestExposureT::MaskedImageT>::image_category())
410 );
411 
452 template <typename DestImageT, typename SrcImageT>
453 int warpImage(DestImageT &destImage,
454  geom::SkyWcs const &destWcs,
455  SrcImageT const &srcImage,
456  geom::SkyWcs const &srcWcs,
457  WarpingControl const &control,
458  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
461 );
462 
477 template <typename DestImageT, typename SrcImageT>
478 int warpImage(DestImageT &destImage,
479  SrcImageT const &srcImage,
480  geom::TransformPoint2ToPoint2 const & srcToDest,
481  WarpingControl const &control,
482  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
484 
490 template <typename DestImageT, typename SrcImageT>
492  DestImageT &destImage,
493  SrcImageT const &srcImage,
495  lsst::afw::geom::Point2D const &centerPosition,
496  WarpingControl const &control,
497  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
500 );
501 
502 namespace details {
503 template <typename A, typename B>
504 bool isSameObject(A const &, B const &) {
505  return false;
506 }
507 
508 template <typename A>
509 bool isSameObject(A const &a, A const &b) {
510  return &a == &b;
511 }
512 } // namespace details
513 } // namespace math
514 } // namespace afw
515 } // namespace lsst
516 
517 #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:364
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:113
1-dimensional Lanczos function
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...
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:950
Parameters to control convolution.
Definition: warpExposure.h:249
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:294
int warpCenteredImage(DestImageT &destImage, SrcImageT const &srcImage, lsst::afw::geom::LinearTransform const &linearTransform, lsst::afw::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.
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:184
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:132
STL class.
A 2D linear coordinate transformation.
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
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.
bool isSameObject(A const &a, A const &b)
Definition: warpExposure.h:509
A base class for image defects.
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:302
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:312
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:369
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:119
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:284
A Function taking one argument.
Definition: Function.h:213
traits class for image categories
Definition: ImageBase.h:70
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:98
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:121
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:195
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:162
NearestFunction1(double fracPos)
Construct a Nearest interpolation function.
Definition: warpExposure.h:189
BilinearFunction1(double fracPos)
Construct a Bilinear interpolation function.
Definition: warpExposure.h:126
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:64
ImageT::image_category image_category
Definition: ImageBase.h:71
bool hasMaskWarpingKernel() const
return true if there is a mask kernel
Definition: warpExposure.h:344
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:182
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:257
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:123
Transform LSST spatial data, such as Point2D and SpherePoint, using an AST mapping.
Definition: Transform.h:67