LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Convolve.h
Go to the documentation of this file.
1// -*- LSST-C++ -*-
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#ifndef LSST_AFW_MATH_DETAIL_CONVOLVE_H
26#define LSST_AFW_MATH_DETAIL_CONVOLVE_H
27/*
28 * Convolution support
29 */
30#include <memory>
31#include <sstream>
32
33#include "lsst/pex/exceptions.h"
34#include "lsst/afw/geom.h"
39
40#define IS_INSTANCE(A, B) (dynamic_cast<B const*>(&(A)) != NULL)
41
42namespace lsst {
43namespace afw {
44namespace math {
45
46namespace detail {
67template <typename OutImageT, typename InImageT>
68void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage, lsst::afw::math::Kernel const& kernel,
69 lsst::afw::math::ConvolutionControl const& convolutionControl);
70
79template <typename OutImageT, typename InImageT>
80void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
82 lsst::afw::math::ConvolutionControl const& convolutionControl);
83
105template <typename OutImageT, typename InImageT>
106void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
108 lsst::afw::math::ConvolutionControl const& convolutionControl);
109
118template <typename OutImageT, typename InImageT>
119void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
121 lsst::afw::math::ConvolutionControl const& convolutionControl);
122
146template <typename OutImageT, typename InImageT>
147void convolveWithBruteForce(OutImageT& convolvedImage, InImageT const& inImage,
148 lsst::afw::math::Kernel const& kernel,
149 lsst::afw::math::ConvolutionControl const& convolutionControl);
150
151// I would prefer this to be nested in KernelImagesForRegion but SWIG doesn't support that
153
173public:
178
193
206 lsst::geom::Point2I const& xy0, bool doNormalize);
228 lsst::geom::Point2I const& xy0, bool doNormalize, ImagePtr bottomLeftImagePtr,
229 ImagePtr bottomRightImagePtr, ImagePtr topLeftImagePtr, ImagePtr topRightImagePtr);
230
234 lsst::geom::Box2I getBBox() const { return _bbox; };
238 lsst::geom::Point2I getXY0() const { return _xy0; };
242 bool getDoNormalize() const { return _doNormalize; };
250 ImagePtr getImage(Location location) const;
254 KernelConstPtr getKernel() const { return _kernelPtr; };
273 bool computeNextRow(RowOfKernelImagesForRegion& regionRow) const;
274
278 static int getMinInterpolationSize() { return _MinInterpolationSize; };
279
280private:
281 using LocationList = std::vector<Location>;
282
288 void _computeImage(Location location) const;
289 inline void _insertImage(Location location, ImagePtr imagePtr) const;
303 void _moveUp(bool isFirst, int newHeight);
304
305 // static helper functions
306 static inline int _computeNextSubregionLength(int length, int nDivisions);
317 static std::vector<int> _computeSubregionLengths(int length, int nDivisions);
318
319 // member variables
320 KernelConstPtr _kernelPtr;
321 lsst::geom::Box2I _bbox;
323 bool _doNormalize;
324 mutable std::vector<ImagePtr> _imagePtrList;
325
326 static int const _MinInterpolationSize;
327};
328
335public:
337 using Iterator = RegionList::iterator;
338 using ConstIterator = RegionList::const_iterator;
339
346 RowOfKernelImagesForRegion(int nx, int ny);
350 RegionList::const_iterator begin() const { return _regionList.begin(); };
354 RegionList::const_iterator end() const { return _regionList.end(); };
358 RegionList::iterator begin() { return _regionList.begin(); };
362 RegionList::iterator end() { return _regionList.end(); };
371 int getNX() const { return _nx; };
372 int getNY() const { return _ny; };
373 int getYInd() const { return _yInd; };
379 std::shared_ptr<KernelImagesForRegion const> getRegion(int ind) const { return _regionList.at(ind); };
380 bool hasData() const { return static_cast<bool>(_regionList[0]); };
381 bool isLastRow() const { return _yInd + 1 >= _ny; };
382 int incrYInd() { return ++_yInd; };
383
384private:
385 int _nx;
386 int _ny;
387 int _yInd;
388 RegionList _regionList;
389};
390
410template <typename OutImageT, typename InImageT>
411void convolveWithInterpolation(OutImageT& outImage, InImageT const& inImage,
412 lsst::afw::math::Kernel const& kernel,
413 ConvolutionControl const& convolutionControl);
414
435
448template <typename OutImageT, typename InImageT>
449void convolveRegionWithInterpolation(OutImageT& outImage, InImageT const& inImage,
450 KernelImagesForRegion const& region,
452
453/*
454 * Define inline functions
455 */
456
464inline int KernelImagesForRegion::_computeNextSubregionLength(
465 int length,
466 int nDivisions)
467{
468 return static_cast<int>(
469 std::floor(0.5 + (static_cast<double>(length) / static_cast<double>(nDivisions))));
470}
471
478inline void KernelImagesForRegion::_insertImage(Location location,
479 ImagePtr imagePtr)
480 const {
481 if (imagePtr) {
482 if (_kernelPtr->getDimensions() != imagePtr->getDimensions()) {
484 os << "image dimensions = ( " << imagePtr->getWidth() << ", " << imagePtr->getHeight() << ") != ("
485 << _kernelPtr->getWidth() << ", " << _kernelPtr->getHeight() << ") = kernel dimensions";
487 }
488 _imagePtrList[location] = imagePtr;
489 }
490}
491} // namespace detail
492} // namespace math
493} // namespace afw
494} // namespace lsst
495
496#endif // !defined(LSST_AFW_MATH_DETAIL_CONVOLVE_H)
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
std::ostream * os
Definition Schema.cc:557
T at(T... args)
T back(T... args)
T begin(T... args)
Parameters to control convolution.
A kernel that has only one non-zero pixel (of value 1)
Definition Kernel.h:643
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition Kernel.h:110
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition Kernel.h:212
int getHeight() const
Return the Kernel's height.
Definition Kernel.h:229
int getWidth() const
Return the Kernel's width.
Definition Kernel.h:224
A kernel that is a linear combination of fixed basis kernels.
Definition Kernel.h:704
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition Kernel.h:860
A collection of Kernel images for special locations on a rectangular region of an image.
Definition Convolve.h:172
KernelConstPtr getKernel() const
Get the kernel (as a shared pointer to const)
Definition Convolve.h:254
Location
locations of various points in the region
Definition Convolve.h:192
KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::geom::Box2I const &bbox, lsst::geom::Point2I const &xy0, bool doNormalize)
Construct a KernelImagesForRegion.
bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const
Compute next row of subregions.
lsst::geom::Point2I getPixelIndex(Location location) const
Compute pixel index of a given location, relative to the parent image (thus offset by bottom left cor...
ImagePtr getImage(Location location) const
Return the image and sum at the specified location.
bool getDoNormalize() const
Get the doNormalize parameter.
Definition Convolve.h:242
lsst::geom::Box2I getBBox() const
Get the bounding box for the region.
Definition Convolve.h:234
lsst::geom::Point2I getXY0() const
Get xy0 of the image.
Definition Convolve.h:238
std::shared_ptr< const lsst::afw::math::Kernel > KernelConstPtr
Definition Convolve.h:174
static int getMinInterpolationSize()
Get the minInterpolationSize class constant.
Definition Convolve.h:278
std::vector< std::shared_ptr< KernelImagesForRegion > > RegionList
Definition Convolve.h:336
RegionList::iterator end()
Return the end iterator for the list.
Definition Convolve.h:362
RowOfKernelImagesForRegion(int nx, int ny)
Construct a RowOfKernelImagesForRegion.
std::shared_ptr< KernelImagesForRegion > back()
Return the last region in the list.
Definition Convolve.h:370
RegionList::const_iterator begin() const
Return the begin iterator for the list.
Definition Convolve.h:350
std::shared_ptr< KernelImagesForRegion > front()
Return the first region in the list.
Definition Convolve.h:366
RegionList::iterator begin()
Return the begin iterator for the list.
Definition Convolve.h:358
RegionList::const_iterator end() const
Return the end iterator for the list.
Definition Convolve.h:354
std::shared_ptr< KernelImagesForRegion const > getRegion(int ind) const
get the specified region (range-checked)
Definition Convolve.h:379
An integer coordinate rectangle.
Definition Box.h:55
Reports invalid arguments.
Definition Runtime.h:66
T end(T... args)
T floor(T... args)
T front(T... args)
void convolveRegionWithInterpolation(OutImageT &outImage, InImageT const &inImage, KernelImagesForRegion const &region, ConvolveWithInterpolationWorkingImages &workingImages)
Convolve a region of an Image or MaskedImage with a spatially varying Kernel using interpolation.
void convolveWithInterpolation(OutImageT &outImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, ConvolutionControl const &convolutionControl)
Convolve an Image or MaskedImage with a spatially varying Kernel using linear interpolation.
void basicConvolve(OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
Low-level convolution function that does not set edge pixels.
void convolveWithBruteForce(OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
Convolve an Image or MaskedImage with a Kernel by computing the kernel image at every point.
kernel images used by convolveRegionWithInterpolation
Definition Convolve.h:418
ConvolveWithInterpolationWorkingImages(lsst::geom::Extent2I const &dimensions)
Definition Convolve.h:421