36 namespace afwGeom = lsst::afw::geom;
42 template <
typename ImageT>
43 std::shared_ptr<ImageT>
offsetImage(ImageT
const& inImage,
float dx,
float dy,
44 std::string
const& algorithmName,
unsigned int buffer
49 std::shared_ptr<ImageT> buffImage;
53 std::shared_ptr<ImageT> buffered(
new ImageT(dims.getX() + 2 * buffer, dims.getY() + 2 * buffer));
56 buffImage->assign(inImage, box);
58 buffImage = std::make_shared<ImageT>(inImage);
61 if (offsetKernel->getWidth() > buffImage->getWidth() ||
62 offsetKernel->getHeight() > buffImage->getHeight()) {
63 throw LSST_EXCEPT(pexExcept::LengthError,
64 (boost::format(
"Image of size %dx%d is too small to offset using a %s kernel"
66 buffImage->getWidth() % buffImage->getHeight() % algorithmName %
67 offsetKernel->getWidth() % offsetKernel->getHeight())
72 std::shared_ptr<ImageT> convImage(
new ImageT(buffImage->getDimensions()));
77 if (dx > -1 && dx < 1 && dy > -1 && dy < 1) {
83 dOrigX =
static_cast<int>(
std::floor(dx + 0.5));
84 dOrigY =
static_cast<int>(
std::floor(dy + 0.5));
90 double dKerX = -fracX;
91 double dKerY = -fracY;
99 offsetKernel->setCtrX(offsetKernel->getCtrX() + 1);
102 offsetKernel->setCtrY(offsetKernel->getCtrY() + 1);
105 offsetKernel->setKernelParameters(std::make_pair(dKerX, dKerY));
107 convolve(*convImage, *buffImage, *offsetKernel,
true,
true);
109 std::shared_ptr<ImageT> outImage;
112 std::shared_ptr<ImageT> out(
new ImageT(*convImage, box,
afwImage::LOCAL,
true));
115 outImage = convImage;
119 outImage->setXY0(
geom::Point2I(inImage.getX0() + dOrigX, inImage.getY0() + dOrigY));
128 #define INSTANTIATE(TYPE) \
129 template std::shared_ptr<afwImage::Image<TYPE>> offsetImage(afwImage::Image<TYPE> const&, float, float, \
130 std::string const&, unsigned int); \
131 template std::shared_ptr<afwImage::MaskedImage<TYPE>> offsetImage( \
132 afwImage::MaskedImage<TYPE> const&, float, float, std::string const&, unsigned int);
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
An integer coordinate rectangle.
Extent< int, N > floor(Extent< double, N > const &input)
Return the component-wise floor (round towards more negative).
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image...
std::shared_ptr< ImageT > offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Return an image offset by (dx, dy) using the specified algorithm.