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