lsst.afw  13.0-109-g62eb66483
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 image {
48 class Wcs;
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 
71  virtual ~LanczosWarpingKernel() {}
72 
73  virtual std::shared_ptr<Kernel> clone() const;
74 
78  int getOrder() const;
79 
80 protected:
81  virtual void setKernelParameter(unsigned int ind, double value) const;
82 };
83 
94 public:
97 
99 
100  virtual std::shared_ptr<Kernel> clone() const;
101 
109  class BilinearFunction1 : public Function1<Kernel::Pixel> {
110  public:
111  typedef std::shared_ptr<Function1<Kernel::Pixel>> Function1Ptr;
112 
116  explicit BilinearFunction1(double fracPos)
117  : Function1<Kernel::Pixel>(1) {
118  this->_params[0] = fracPos;
119  }
120  virtual ~BilinearFunction1() {}
121 
122  virtual Function1Ptr clone() const { return Function1Ptr(new BilinearFunction1(this->_params[0])); }
123 
131  virtual Kernel::Pixel operator()(double x) const;
132 
136  virtual std::string toString(std::string const & = "") const;
137  };
138 
139 protected:
140  virtual void setKernelParameter(unsigned int ind, double value) const;
141 };
142 
153 public:
155 
157 
158  virtual std::shared_ptr<Kernel> clone() const;
159 
167  class NearestFunction1 : public Function1<Kernel::Pixel> {
168  public:
169  typedef std::shared_ptr<Function1<Kernel::Pixel>> Function1Ptr;
170 
174  explicit NearestFunction1(double fracPos)
175  : Function1<Kernel::Pixel>(1) {
176  this->_params[0] = fracPos;
177  }
178  virtual ~NearestFunction1() {}
179 
180  virtual Function1Ptr clone() const { return Function1Ptr(new NearestFunction1(this->_params[0])); }
181 
189  virtual Kernel::Pixel operator()(double x) const;
190 
194  virtual std::string toString(std::string const & = "") const;
195  };
196 
197 protected:
198  virtual void setKernelParameter(unsigned int ind, double value) const;
199 };
200 
225 std::shared_ptr<SeparableKernel> makeWarpingKernel(std::string name);
226 
235 public:
242  explicit WarpingControl(
243  std::string const &warpingKernelName,
244  std::string const &maskWarpingKernelName = "",
246  int cacheSize = 0,
251  int interpLength = 0,
253  lsst::afw::image::MaskPixel growFullMask = 0
255  )
256  : _warpingKernelPtr(makeWarpingKernel(warpingKernelName)),
257  _maskWarpingKernelPtr(),
258  _cacheSize(cacheSize),
259  _interpLength(interpLength),
260  _growFullMask(growFullMask) {
261  setMaskWarpingKernelName(maskWarpingKernelName);
262  }
263 
264  virtual ~WarpingControl(){};
265 
269  int getCacheSize() const { return _cacheSize; };
270 
279  void setCacheSize(int cacheSize
280  ) {
281  _cacheSize = cacheSize;
282  };
283 
287  int getInterpLength() const { return _interpLength; };
288 
297  void setInterpLength(int interpLength
298  ) {
299  _interpLength = interpLength;
300  };
301 
305  std::shared_ptr<SeparableKernel> getWarpingKernel() const;
306 
310  void setWarpingKernelName(std::string const &warpingKernelName
311  );
312 
318  void setWarpingKernel(SeparableKernel const &warpingKernel
319  );
320 
324  std::shared_ptr<SeparableKernel> getMaskWarpingKernel() const;
325 
329  bool hasMaskWarpingKernel() const { return static_cast<bool>(_maskWarpingKernelPtr); }
330 
334  void setMaskWarpingKernelName(std::string const &maskWarpingKernelName
336  );
337 
343  void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel
344  );
345 
349  lsst::afw::image::MaskPixel getGrowFullMask() const { return _growFullMask; };
350 
355  ) {
357  _growFullMask = growFullMask;
358  }
359 
360 private:
367  void _testWarpingKernels(SeparableKernel const &warpingKernel,
368  SeparableKernel const &maskWarpingKernel
369  ) const;
370 
371  std::shared_ptr<SeparableKernel> _warpingKernelPtr;
372  std::shared_ptr<SeparableKernel> _maskWarpingKernelPtr;
373  int _cacheSize;
374  int _interpLength;
375  lsst::afw::image::MaskPixel _growFullMask;
376 };
377 
383 template <typename DestExposureT, typename SrcExposureT>
384 int warpExposure(
385  DestExposureT &destExposure,
386  SrcExposureT const &srcExposure,
389  WarpingControl const &control,
390  typename DestExposureT::MaskedImageT::SinglePixel padValue =
391  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
393  typename DestExposureT::MaskedImageT>::image_category())
395  );
396 
437 template <typename DestImageT, typename SrcImageT>
438 int warpImage(DestImageT &destImage,
439  lsst::afw::image::Wcs const &destWcs,
440  SrcImageT const &srcImage,
441  lsst::afw::image::Wcs const &srcWcs,
442  WarpingControl const &control,
443  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
446  );
447 
452 template <typename DestImageT, typename SrcImageT>
453 int warpImage(DestImageT &destImage,
454  SrcImageT const &srcImage,
456  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,
481  WarpingControl const &control,
482  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
484  );
485 
486 
492 template <typename DestImageT, typename SrcImageT>
494  DestImageT &destImage,
495  SrcImageT const &srcImage,
497  lsst::afw::geom::Point2D const &centerPosition,
498  WarpingControl const &control,
499  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
502  );
503 
504 namespace details {
505 template <typename A, typename B>
506 bool isSameObject(A const &, B const &) {
507  return false;
508 }
509 
510 template <typename A>
511 bool isSameObject(A const &a, A const &b) {
512  return &a == &b;
513 }
514 }
515 }
516 }
517 } // lsst::afw::math
518 
519 #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:349
table::Key< std::string > name
Definition: ApCorrMap.cc:71
1-dimensional Lanczos function
int warpImage(DestImageT &destImage, SrcImageT const &srcImage, geom::Transform< geom::Point2Endpoint, geom::Point2Endpoint > const &destToSrc, 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 TransformPoint2ToPoint2 instead of a pair of WCS to describe the t...
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:927
Parameters to control convolution.
Definition: warpExposure.h:234
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:104
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:279
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:169
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:122
A 2D linear coordinate transformation.
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:511
A base class for image defects.
Definition: cameraGeom.dox:3
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:287
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:297
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:354
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:109
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:269
A Function taking one argument.
Definition: Function.h:207
traits class for image categories
Definition: ImageBase.h:70
double x
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:93
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:111
virtual Function1Ptr clone() const
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:180
Virtual base class for 2D transforms.
Definition: XYTransform.h:49
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:152
NearestFunction1(double fracPos)
Construct a Nearest interpolation function.
Definition: warpExposure.h:174
BilinearFunction1(double fracPos)
Construct a Bilinear interpolation function.
Definition: warpExposure.h:116
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:329
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:167
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:242
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:123
Transform LSST spatial data, such as Point2D and IcrsCoord, using an AST transform.
Definition: Transform.h:64