38 namespace afwGeom = lsst::afw::geom;
54 template<
typename ImageT>
58 std::string
const& algorithmName,
67 typename ImageT::Ptr buffImage;
71 typename ImageT::Ptr buffered(
new ImageT(dims.getX() + 2 * buffer, dims.getY() + 2 * buffer));
74 typename ImageT::Ptr buffSmall(
new ImageT(*buffImage, box,
afwImage::LOCAL,
false));
75 *buffSmall <<= inImage;
77 buffImage = boost::make_shared<ImageT>(inImage);
80 if (offsetKernel->getWidth() > buffImage->getWidth() ||
81 offsetKernel->getHeight() > buffImage->getHeight()) {
83 (
boost::format(
"Image of size %dx%d is too small to offset using a %s kernel"
85 buffImage->getWidth() % buffImage->getHeight() % algorithmName %
86 offsetKernel->getWidth() % offsetKernel->getHeight()).str());
90 typename ImageT::Ptr convImage(
new ImageT(buffImage->getDimensions()));
95 if (dx > -1 && dx < 1 && dy > -1 && dy < 1) {
101 dOrigX =
static_cast<int>(
std::floor(dx + 0.5));
102 dOrigY =
static_cast<int>(
std::floor(dy + 0.5));
108 double dKerX = -fracX;
109 double dKerY = -fracY;
117 offsetKernel->setCtrX(offsetKernel->getCtrX() + 1);
120 offsetKernel->setCtrY(offsetKernel->getCtrY() + 1);
123 offsetKernel->setKernelParameters(std::make_pair(dKerX, dKerY));
125 convolve(*convImage, *buffImage, *offsetKernel,
true,
true);
127 typename ImageT::Ptr outImage;
130 typename ImageT::Ptr out(
new ImageT(*convImage, box,
afwImage::LOCAL,
true));
133 outImage = convImage;
137 outImage->setXY0(
geom::Point2I(inImage.getX0() + dOrigX, inImage.getY0() + dOrigY));
147 #define INSTANTIATE(TYPE) \
148 template afwImage::Image<TYPE>::Ptr offsetImage(afwImage::Image<TYPE> const&, float, float, \
149 std::string const&, unsigned int); \
150 template afwImage::MaskedImage<TYPE>::Ptr offsetImage(afwImage::MaskedImage<TYPE> const&, float, float, \
151 std::string const&, unsigned int);
boost::shared_ptr< SeparableKernel > Ptr
boost::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
#define INSTANTIATE(MATCH)
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
ImageT::Ptr 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.
#define LSST_EXCEPT(type,...)
Extent< int, N > floor(Extent< double, N > const &input)
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...
Support for warping an image to a new WCS.
A coordinate class intended to represent offsets and dimensions.