lsst.afw  14.0-52-g19103d347
warpExposure.cc
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  * Support for warping an %image to a new Wcs.
26  */
27 
28 #include <cassert>
29 #include <cmath>
30 #include <cstdint>
31 #include <limits>
32 #include <memory>
33 #include <sstream>
34 #include <string>
35 #include <vector>
36 #include <utility>
37 #include <ctime>
38 
39 #include <memory>
40 #include "boost/pointer_cast.hpp"
41 #include "boost/regex.hpp"
42 #include "astshim.h"
43 
44 #include "lsst/log/Log.h"
45 #include "lsst/pex/exceptions.h"
47 #include "lsst/afw/geom.h"
48 #include "lsst/afw/math/Kernel.h"
49 #include "lsst/afw/coord/Coord.h"
50 #include "lsst/afw/image/Calib.h"
52 
54 
55 using std::swap;
56 
57 namespace lsst {
58 namespace afw {
59 namespace math {
60 
61 //
62 // A helper function for the warping kernels which provides error-checking:
63 // the warping kernels are designed to work in two cases
64 // 0 < x < 1 and ctrX=(size-1)/2
65 // -1 < x < 0 and ctrX=(size+1)/2
66 // (and analogously for y). Note that to get the second case, Kernel::setCtrX(1) must be
67 // called before calling Kernel::setKernelParameter(). [see afw::math::offsetImage() for
68 // an example]
69 //
70 // FIXME eventually the 3 warping kernels will inherit from a common base class WarpingKernel
71 // and this routine can be eliminated by putting the code in WarpingKernel::setKernelParameter()
72 //
73 static inline void checkWarpingKernelParameter(const SeparableKernel *p, unsigned int ind, double value) {
74  if (ind > 1) {
76  "bad ind argument in WarpingKernel::setKernelParameter()");
77  }
78  int ctr = p->getCtr()[ind];
79  int size = p->getDimensions()[ind];
80 
81  if (ctr == (size - 1) / 2) {
82  if (value < -1e-6 || value > 1 + 1e-6) {
84  "bad coordinate in WarpingKernel::setKernelParameter()");
85  }
86  } else if (ctr == (size + 1) / 2) {
87  if (value < -1 - 1e-6 || value > 1e-6) {
89  "bad coordinate in WarpingKernel::setKernelParameter()");
90  }
91  } else {
93  "bad ctr value in WarpingKernel::setKernelParameter()");
94  }
95 }
96 
99 }
100 
101 int LanczosWarpingKernel::getOrder() const { return this->getWidth() / 2; }
102 
103 void LanczosWarpingKernel::setKernelParameter(unsigned int ind, double value) const {
104  checkWarpingKernelParameter(this, ind, value);
106 }
107 
110 }
111 
113  //
114  // this->_params[0] = value of x where we want to interpolate the function
115  // x = integer value of x where we evaluate the function in the interpolation
116  //
117  // The following weird-looking expression has no if/else statements, is roundoff-tolerant,
118  // and works in the following two cases:
119  // 0 < this->_params[0] < 1, x \in {0,1}
120  // -1 < this->_params[0] < 0, x \in {-1,0}
121  //
122  // The checks in BilinearWarpingKernel::setKernelParameter() ensure that one of these
123  // conditions is satisfied
124  //
125  return 0.5 + (1.0 - (2.0 * fabs(this->_params[0]))) * (0.5 - fabs(x));
126 }
127 
128 void BilinearWarpingKernel::setKernelParameter(unsigned int ind, double value) const {
129  checkWarpingKernelParameter(this, ind, value);
131 }
132 
135  os << "_BilinearFunction1: ";
136  os << Function1<Kernel::Pixel>::toString(prefix);
137  return os.str();
138 }
139 
141  return std::make_shared<NearestWarpingKernel>();
142 }
143 
145  // this expression is faster than using conditionals, but offers no sanity checking
146  return static_cast<double>((fabs(this->_params[0]) < 0.5) == (fabs(x) < 0.5));
147 }
148 
149 void NearestWarpingKernel::setKernelParameter(unsigned int ind, double value) const {
150  checkWarpingKernelParameter(this, ind, value);
152 }
153 
156  os << "_NearestFunction1: ";
157  os << Function1<Kernel::Pixel>::toString(prefix);
158  return os.str();
159 }
160 
162  typedef std::shared_ptr<SeparableKernel> KernelPtr;
163  boost::cmatch matches;
164  static const boost::regex LanczosRE("lanczos(\\d+)");
165  if (name == "bilinear") {
166  return KernelPtr(new BilinearWarpingKernel());
167  } else if (boost::regex_match(name.c_str(), matches, LanczosRE)) {
168  std::string orderStr(matches[1].first, matches[1].second);
169  int order;
170  std::istringstream(orderStr) >> order;
171  return KernelPtr(new LanczosWarpingKernel(order));
172  } else if (name == "nearest") {
173  return KernelPtr(new NearestWarpingKernel());
174  } else {
175  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "unknown warping kernel name: \"" + name + "\"");
176  }
177 }
178 
180  if (_warpingKernelPtr->getCacheSize() != _cacheSize) {
181  _warpingKernelPtr->computeCache(_cacheSize);
182  }
183  return _warpingKernelPtr;
184 };
185 
186 void WarpingControl::setWarpingKernelName(std::string const &warpingKernelName) {
187  std::shared_ptr<SeparableKernel> warpingKernelPtr(makeWarpingKernel(warpingKernelName));
188  setWarpingKernel(*warpingKernelPtr);
189 }
190 
192  if (_maskWarpingKernelPtr) {
193  _testWarpingKernels(warpingKernel, *_maskWarpingKernelPtr);
194  }
195  std::shared_ptr<SeparableKernel> warpingKernelPtr(
196  std::static_pointer_cast<SeparableKernel>(warpingKernel.clone()));
197  _warpingKernelPtr = warpingKernelPtr;
198 }
199 
201  if (_maskWarpingKernelPtr) { // lazily update kernel cache
202  if (_maskWarpingKernelPtr->getCacheSize() != _cacheSize) {
203  _maskWarpingKernelPtr->computeCache(_cacheSize);
204  }
205  }
206  return _maskWarpingKernelPtr;
207 }
208 
209 void WarpingControl::setMaskWarpingKernelName(std::string const &maskWarpingKernelName) {
210  if (!maskWarpingKernelName.empty()) {
211  std::shared_ptr<SeparableKernel> maskWarpingKernelPtr(makeWarpingKernel(maskWarpingKernelName));
212  setMaskWarpingKernel(*maskWarpingKernelPtr);
213  } else {
214  _maskWarpingKernelPtr.reset();
215  }
216 }
217 
219  _testWarpingKernels(*_warpingKernelPtr, maskWarpingKernel);
220  _maskWarpingKernelPtr = std::static_pointer_cast<SeparableKernel>(maskWarpingKernel.clone());
221 }
222 
223 void WarpingControl::_testWarpingKernels(SeparableKernel const &warpingKernel,
224  SeparableKernel const &maskWarpingKernel) const {
225  geom::Box2I kernelBBox = geom::Box2I(geom::Point2I(0, 0) - geom::Extent2I(warpingKernel.getCtr()),
226  warpingKernel.getDimensions());
227  geom::Box2I maskKernelBBox = geom::Box2I(geom::Point2I(0, 0) - geom::Extent2I(maskWarpingKernel.getCtr()),
228  maskWarpingKernel.getDimensions());
229  if (!kernelBBox.contains(maskKernelBBox)) {
231  "warping kernel is smaller than mask warping kernel");
232  }
233 }
234 
235 template <typename DestExposureT, typename SrcExposureT>
236 int warpExposure(DestExposureT &destExposure, SrcExposureT const &srcExposure, WarpingControl const &control,
237  typename DestExposureT::MaskedImageT::SinglePixel padValue) {
238  if (!destExposure.hasWcs()) {
239  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "destExposure has no Wcs");
240  }
241  if (!srcExposure.hasWcs()) {
242  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "srcExposure has no Wcs");
243  }
244  typename DestExposureT::MaskedImageT mi = destExposure.getMaskedImage();
245  std::shared_ptr<image::Calib> calibCopy(new image::Calib(*srcExposure.getCalib()));
246  destExposure.setCalib(calibCopy);
247  destExposure.setFilter(srcExposure.getFilter());
248  destExposure.getInfo()->setVisitInfo(srcExposure.getInfo()->getVisitInfo());
249  return warpImage(mi, *destExposure.getWcs(), srcExposure.getMaskedImage(), *srcExposure.getWcs(), control,
250  padValue);
251 }
252 
253 namespace {
254 
255 inline geom::Point2D computeSrcPos(int destCol,
256  int destRow,
257  geom::Point2D const &destXY0,
258  geom::SkyWcs const &destWcs,
259  geom::SkyWcs const &srcWcs)
260 {
261  geom::Point2D const destPix(image::indexToPosition(destCol + destXY0[0]),
262  image::indexToPosition(destRow + destXY0[1]));
263  return srcWcs.skyToPixel(destWcs.pixelToSky(destPix));
264 }
265 
266 inline double computeRelativeArea(
267  geom::Point2D const &srcPos,
268  geom::Point2D const &leftSrcPos,
269  geom::Point2D const &upSrcPos)
270 {
271  geom::Extent2D dSrcA = srcPos - leftSrcPos;
272  geom::Extent2D dSrcB = srcPos - upSrcPos;
273 
274  return std::abs(dSrcA.getX() * dSrcB.getY() - dSrcA.getY() * dSrcB.getX());
275 }
276 
277 } // namespace
278 
279 template <typename DestImageT, typename SrcImageT>
280 int warpImage(DestImageT &destImage, geom::SkyWcs const &destWcs, SrcImageT const &srcImage,
281  geom::SkyWcs const &srcWcs, WarpingControl const &control,
282  typename DestImageT::SinglePixel padValue) {
283  auto srcToDest = geom::makeWcsPairTransform(srcWcs, destWcs);
284  return warpImage(destImage, srcImage, *srcToDest, control, padValue);
285 }
286 
287 template <typename DestImageT, typename SrcImageT>
288 int warpImage(DestImageT &destImage, SrcImageT const &srcImage,
289  geom::TransformPoint2ToPoint2 const &srcToDest, WarpingControl const &control,
290  typename DestImageT::SinglePixel padValue) {
291  if (details::isSameObject(destImage, srcImage)) {
292  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "destImage is srcImage; cannot warp in place");
293  }
294  if (destImage.getBBox(image::LOCAL).isEmpty()) {
295  return 0;
296  }
297  // if src image is too small then don't try to warp
298  std::shared_ptr<SeparableKernel> warpingKernelPtr = control.getWarpingKernel();
299  try {
300  warpingKernelPtr->shrinkBBox(srcImage.getBBox(image::LOCAL));
302  for (int y = 0, height = destImage.getHeight(); y < height; ++y) {
303  for (typename DestImageT::x_iterator destPtr = destImage.row_begin(y), end = destImage.row_end(y);
304  destPtr != end; ++destPtr) {
305  *destPtr = padValue;
306  }
307  }
308  return 0;
309  }
310  int interpLength = control.getInterpLength();
311 
312  std::shared_ptr<LanczosWarpingKernel const> const lanczosKernelPtr =
314 
315  int numGoodPixels = 0;
316 
317  // compute a transform from local destination pixels to parent source pixels
318  auto const parentDestToParentSrc = srcToDest.getInverse();
319  std::vector<double> const localDestToParentDestVec = {static_cast<double>(destImage.getX0()),
320  static_cast<double>(destImage.getY0())};
321  auto const localDestToParentDest = geom::TransformPoint2ToPoint2(ast::ShiftMap(localDestToParentDestVec));
322  auto const localDestToParentSrc = localDestToParentDest.then(*parentDestToParentSrc);
323 
324  // Get the source MaskedImage and a pixel accessor to it.
325  int const srcWidth = srcImage.getWidth();
326  int const srcHeight = srcImage.getHeight();
327  LOGL_DEBUG("TRACE2.afw.math.warp", "source image width=%d; height=%d", srcWidth, srcHeight);
328 
329  int const destWidth = destImage.getWidth();
330  int const destHeight = destImage.getHeight();
331  LOGL_DEBUG("TRACE2.afw.math.warp", "remap image width=%d; height=%d", destWidth, destHeight);
332 
333  // Set each pixel of destExposure's MaskedImage
334  LOGL_DEBUG("TRACE3.afw.math.warp", "Remapping masked image");
335 
336  int const maxCol = destWidth - 1;
337  int const maxRow = destHeight - 1;
338 
339  detail::WarpAtOnePoint<DestImageT, SrcImageT> warpAtOnePoint(srcImage, control, padValue);
340 
341  if (interpLength > 0) {
342  // Use interpolation. Note that 1 produces the same result as no interpolation
343  // but uses this code branch, thus providing an easy way to compare the two branches.
344 
345  // Estimate for number of horizontal interpolation band edges, to reserve memory in vectors
346  int const numColEdges = 2 + ((destWidth - 1) / interpLength);
347 
348  // A list of edge column indices for interpolation bands;
349  // starts at -1, increments by interpLen (except the final interval), and ends at destWidth-1
350  std::vector<int> edgeColList;
351  edgeColList.reserve(numColEdges);
352 
353  // A list of 1/column width for horizontal interpolation bands; the first value is garbage.
354  // The inverse is used for speed because the values are always multiplied.
355  std::vector<double> invWidthList;
356  invWidthList.reserve(numColEdges);
357 
358  // Compute edgeColList and invWidthList
359  edgeColList.push_back(-1);
360  invWidthList.push_back(0.0);
361  for (int prevEndCol = -1; prevEndCol < maxCol; prevEndCol += interpLength) {
362  int endCol = prevEndCol + interpLength;
363  if (endCol > maxCol) {
364  endCol = maxCol;
365  }
366  edgeColList.push_back(endCol);
367  assert(endCol - prevEndCol > 0);
368  invWidthList.push_back(1.0 / static_cast<double>(endCol - prevEndCol));
369  }
370  assert(edgeColList.back() == maxCol);
371 
372  // A list of delta source positions along the edge columns of the horizontal interpolation bands
373  std::vector<geom::Extent2D> yDeltaSrcPosList(edgeColList.size());
374 
375  // A cache of pixel positions on the source corresponding to the previous or current row
376  // of the destination image.
377  // The first value is for column -1 because the previous source position is used to compute relative
378  // area To simplify the indexing, use an iterator that starts at begin+1, thus: srcPosView =
379  // srcPosList.begin() + 1 srcPosView[col-1] and lower indices are for this row srcPosView[col] and
380  // higher indices are for the previous row
381  std::vector<geom::Point2D> srcPosList(1 + destWidth);
382  std::vector<geom::Point2D>::iterator const srcPosView = srcPosList.begin() + 1;
383 
384  std::vector<geom::Point2D> endColPosList;
385  endColPosList.reserve(numColEdges);
386 
387  // Initialize srcPosList for row -1
388  for (int colBand = 0, endBand = edgeColList.size(); colBand < endBand; ++colBand) {
389  int const endCol = edgeColList[colBand];
390  endColPosList.emplace_back(geom::Point2D(endCol, -1));
391  }
392  auto rightSrcPosList = localDestToParentSrc->applyForward(endColPosList);
393  srcPosView[-1] = rightSrcPosList[0];
394  for (int colBand = 1, endBand = edgeColList.size(); colBand < endBand; ++colBand) {
395  int const prevEndCol = edgeColList[colBand - 1];
396  int const endCol = edgeColList[colBand];
397  geom::Point2D leftSrcPos = srcPosView[prevEndCol];
398 
399  geom::Extent2D xDeltaSrcPos = (rightSrcPosList[colBand] - leftSrcPos) * invWidthList[colBand];
400 
401  for (int col = prevEndCol + 1; col <= endCol; ++col) {
402  srcPosView[col] = srcPosView[col - 1] + xDeltaSrcPos;
403  }
404  }
405 
406  int endRow = -1;
407  while (endRow < maxRow) {
408  // Next horizontal interpolation band
409 
410  int prevEndRow = endRow;
411  endRow = prevEndRow + interpLength;
412  if (endRow > maxRow) {
413  endRow = maxRow;
414  }
415  assert(endRow - prevEndRow > 0);
416  double interpInvHeight = 1.0 / static_cast<double>(endRow - prevEndRow);
417 
418  // Set yDeltaSrcPosList for this horizontal interpolation band
419  std::vector<geom::Point2D> destRowPosList;
420  destRowPosList.reserve(edgeColList.size());
421  for (int colBand = 0, endBand = edgeColList.size(); colBand < endBand; ++colBand) {
422  int endCol = edgeColList[colBand];
423  destRowPosList.emplace_back(geom::Point2D(endCol, endRow));
424  }
425  auto bottomSrcPosList = localDestToParentSrc->applyForward(destRowPosList);
426  for (int colBand = 0, endBand = edgeColList.size(); colBand < endBand; ++colBand) {
427  int endCol = edgeColList[colBand];
428  yDeltaSrcPosList[colBand] =
429  (bottomSrcPosList[colBand] - srcPosView[endCol]) * interpInvHeight;
430  }
431 
432  for (int row = prevEndRow + 1; row <= endRow; ++row) {
433  typename DestImageT::x_iterator destXIter = destImage.row_begin(row);
434  srcPosView[-1] += yDeltaSrcPosList[0];
435  for (int colBand = 1, endBand = edgeColList.size(); colBand < endBand; ++colBand) {
436  // Next vertical interpolation band
437 
438  int const prevEndCol = edgeColList[colBand - 1];
439  int const endCol = edgeColList[colBand];
440 
441  // Compute xDeltaSrcPos; remember that srcPosView contains
442  // positions for this row in prevEndCol and smaller indices,
443  // and positions for the previous row for larger indices (including endCol)
444  geom::Point2D leftSrcPos = srcPosView[prevEndCol];
445  geom::Point2D rightSrcPos = srcPosView[endCol] + yDeltaSrcPosList[colBand];
446  geom::Extent2D xDeltaSrcPos = (rightSrcPos - leftSrcPos) * invWidthList[colBand];
447 
448  for (int col = prevEndCol + 1; col <= endCol; ++col, ++destXIter) {
449  geom::Point2D leftSrcPos = srcPosView[col - 1];
450  geom::Point2D srcPos = leftSrcPos + xDeltaSrcPos;
451  double relativeArea = computeRelativeArea(srcPos, leftSrcPos, srcPosView[col]);
452 
453  srcPosView[col] = srcPos;
454 
455  if (warpAtOnePoint(
456  destXIter, srcPos, relativeArea,
458  ++numGoodPixels;
459  }
460  } // for col
461  } // for col band
462  } // for row
463  } // while next row band
464 
465  } else {
466  // No interpolation
467 
468  // prevSrcPosList = source positions from the previous row; these are used to compute pixel area;
469  // to begin, compute sources positions corresponding to destination row = -1
470  std::vector<geom::Point2D> destPosList;
471  destPosList.reserve(1 + destWidth);
472  for (int col = -1; col < destWidth; ++col) {
473  destPosList.emplace_back(geom::Point2D(col, -1));
474  }
475  auto prevSrcPosList = localDestToParentSrc->applyForward(destPosList);
476 
477  for (int row = 0; row < destHeight; ++row) {
478  destPosList.clear();
479  for (int col = -1; col < destWidth; ++col) {
480  destPosList.emplace_back(geom::Point2D(col, row));
481  }
482  auto srcPosList = localDestToParentSrc->applyForward(destPosList);
483 
484  typename DestImageT::x_iterator destXIter = destImage.row_begin(row);
485  for (int col = 0; col < destWidth; ++col, ++destXIter) {
486  // column index = column + 1 because the first entry in srcPosList is for column -1
487  auto srcPos = srcPosList[col + 1];
488  double relativeArea =
489  computeRelativeArea(srcPos, prevSrcPosList[col], prevSrcPosList[col + 1]);
490 
491  if (warpAtOnePoint(destXIter, srcPos, relativeArea,
493  ++numGoodPixels;
494  }
495  } // for col
496  // move points from srcPosList to prevSrcPosList (we don't care about what ends up in srcPosList
497  // because it will be reallocated anyway)
498  swap(srcPosList, prevSrcPosList);
499  } // for row
500  } // if interp
501 
502  return numGoodPixels;
503 }
504 
505 template <typename DestImageT, typename SrcImageT>
506 int warpCenteredImage(DestImageT &destImage, SrcImageT const &srcImage,
507  geom::LinearTransform const &linearTransform, geom::Point2D const &centerPosition,
508  WarpingControl const &control, typename DestImageT::SinglePixel padValue) {
509  // force src and dest to be the same size and xy0
510  if ((destImage.getWidth() != srcImage.getWidth()) || (destImage.getHeight() != srcImage.getHeight()) ||
511  (destImage.getXY0() != srcImage.getXY0())) {
512  std::ostringstream errStream;
513  errStream << "src and dest images must have same size and xy0.";
515  }
516 
517  // set the xy0 coords to 0,0 to make life easier
518  SrcImageT srcImageCopy(srcImage, true);
519  srcImageCopy.setXY0(0, 0);
520  destImage.setXY0(0, 0);
521  geom::Extent2D cLocal = geom::Extent2D(centerPosition) - geom::Extent2D(srcImage.getXY0());
522 
523  // for the affine transform, the centerPosition will not only get sheared, but also
524  // moved slightly. So we'll include a translation to move it back by an amount
525  // centerPosition - translatedCenterPosition
526  geom::AffineTransform affTran(linearTransform, cLocal - linearTransform(cLocal));
528 
529 // now warp
530 #if 0
531  static float t = 0.0;
532  float t_before = 1.0*clock()/CLOCKS_PER_SEC;
533  int n = warpImage(destImage, srcImageCopy, affTran, control, padValue);
534  float t_after = 1.0*clock()/CLOCKS_PER_SEC;
535  float dt = t_after - t_before;
536  t += dt;
537  std::cout <<srcImage.getWidth()<<"x"<<srcImage.getHeight()<<": "<< dt <<" "<< t <<std::endl;
538 #else
539  int n = warpImage(destImage, srcImageCopy, *affineTransform22, control, padValue);
540 #endif
541 
542  // fix the origin and we're done.
543  destImage.setXY0(srcImage.getXY0());
544 
545  return n;
546 }
547 
548 //
549 // Explicit instantiations
550 //
552 // may need to omit default params for EXPOSURE -- original code did that and it worked
553 #define EXPOSURE(PIXTYPE) image::Exposure<PIXTYPE, image::MaskPixel, image::VariancePixel>
554 #define MASKEDIMAGE(PIXTYPE) image::MaskedImage<PIXTYPE, image::MaskPixel, image::VariancePixel>
555 #define IMAGE(PIXTYPE) image::Image<PIXTYPE>
556 #define NL /* */
557 
558 #define INSTANTIATE(DESTIMAGEPIXELT, SRCIMAGEPIXELT) \
559  template int warpCenteredImage( \
560  IMAGE(DESTIMAGEPIXELT) & destImage, IMAGE(SRCIMAGEPIXELT) const &srcImage, \
561  geom::LinearTransform const &linearTransform, geom::Point2D const &centerPosition, \
562  WarpingControl const &control, IMAGE(DESTIMAGEPIXELT)::SinglePixel padValue); \
563  NL template int warpCenteredImage( \
564  MASKEDIMAGE(DESTIMAGEPIXELT) & destImage, MASKEDIMAGE(SRCIMAGEPIXELT) const &srcImage, \
565  geom::LinearTransform const &linearTransform, geom::Point2D const &centerPosition, \
566  WarpingControl const &control, MASKEDIMAGE(DESTIMAGEPIXELT)::SinglePixel padValue); \
567  NL template int warpImage(IMAGE(DESTIMAGEPIXELT) & destImage, IMAGE(SRCIMAGEPIXELT) const &srcImage, \
568  geom::TransformPoint2ToPoint2 const &srcToDest, WarpingControl const &control, \
569  IMAGE(DESTIMAGEPIXELT)::SinglePixel padValue); \
570  NL template int warpImage(MASKEDIMAGE(DESTIMAGEPIXELT) & destImage, \
571  MASKEDIMAGE(SRCIMAGEPIXELT) const &srcImage, \
572  geom::TransformPoint2ToPoint2 const &srcToDest, WarpingControl const &control, \
573  MASKEDIMAGE(DESTIMAGEPIXELT)::SinglePixel padValue); \
574  NL template int warpImage(IMAGE(DESTIMAGEPIXELT) & destImage, geom::SkyWcs const &destWcs, \
575  IMAGE(SRCIMAGEPIXELT) const &srcImage, geom::SkyWcs const &srcWcs, \
576  WarpingControl const &control, IMAGE(DESTIMAGEPIXELT)::SinglePixel padValue); \
577  NL template int warpImage(MASKEDIMAGE(DESTIMAGEPIXELT) & destImage, geom::SkyWcs const &destWcs, \
578  MASKEDIMAGE(SRCIMAGEPIXELT) const &srcImage, geom::SkyWcs const &srcWcs, \
579  WarpingControl const &control, \
580  MASKEDIMAGE(DESTIMAGEPIXELT)::SinglePixel padValue); \
581  NL template int warpExposure(EXPOSURE(DESTIMAGEPIXELT) & destExposure, \
582  EXPOSURE(SRCIMAGEPIXELT) const &srcExposure, WarpingControl const &control, \
583  EXPOSURE(DESTIMAGEPIXELT)::MaskedImageT::SinglePixel padValue);
584 
585 INSTANTIATE(double, double)
586 INSTANTIATE(double, float)
587 INSTANTIATE(double, int)
588 INSTANTIATE(double, std::uint16_t)
589 INSTANTIATE(float, float)
590 INSTANTIATE(float, int)
592 INSTANTIATE(int, int)
595 } // namespace math
596 } // namespace afw
597 } // namespace lsst
T empty(T... args)
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:114
virtual std::string toString(std::string const &="") const
Return string representation.
double indexToPosition(double ind)
Convert image index to image position.
Definition: ImageUtils.h:55
table::Key< std::string > name
Definition: ApCorrMap.cc:71
Extent< double, 2 > Extent2D
Definition: Extent.h:383
std::shared_ptr< Transform< ToEndpoint, FromEndpoint > > getInverse() const
The inverse of this Transform.
T swap(T... args)
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
T endl(T... args)
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:250
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:950
void setWarpingKernelName(std::string const &warpingKernelName)
set the warping kernel by name
A functor that computes one warped pixel.
Parameters to control convolution.
Definition: warpExposure.h:249
std::shared_ptr< SeparableKernel > getWarpingKernel() const
get the warping kernel
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.
#define LOGL_DEBUG(logger, message...)
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Describe an exposure&#39;s calibration.
Definition: Calib.h:96
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel)
set the mask warping kernel
An integer coordinate rectangle.
Definition: Box.h:55
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:311
STL class.
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Definition: warpExposure.cc:97
A 2D linear coordinate transformation.
T push_back(T... args)
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.
int getOrder() const
get the order of the kernel
A base class for image defects.
int end
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:302
An affine coordinate transformation consisting of a linear transformation and an offset.
void setMaskWarpingKernelName(std::string const &maskWarpingKernelName)
set or clear the mask warping kernel by name
bool isSameObject(A const &, B const &)
Definition: warpExposure.h:504
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:156
void setWarpingKernel(SeparableKernel const &warpingKernel)
set the warping kernel
T str(T... args)
virtual std::string toString(std::string const &="") const
Return string representation.
T static_pointer_cast(T... args)
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.
double x
coord::IcrsCoord pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:324
T clear(T... args)
Point2D skyToPixel(coord::IcrsCoord const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:335
bool contains(Point2I const &point) const
Return true if the box contains the point.
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(AffineTransform const &affine)
Wrap an AffineTransform as a Transform.
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:98
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
virtual Kernel::Pixel operator()(double x) const
Solve bilinear equation.
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:458
T size(T... args)
std::shared_ptr< SeparableKernel > getMaskWarpingKernel() const
get the mask warping kernel
#define LSST_EXCEPT(type,...)
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
T begin(T... args)
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
T c_str(T... args)
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:162
T back(T... args)
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:64
ImageT::image_category image_category
Definition: ImageBase.h:71
virtual Kernel::Pixel operator()(double x) const
Solve nearest neighbor equation.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:228
Transform LSST spatial data, such as Point2D and IcrsCoord, using an AST transform.
Definition: Transform.h:69
T reserve(T... args)
T emplace_back(T... args)