LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
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"
35 #include "lsst/afw/image/Image.h"
37 #include "lsst/afw/math/Kernel.h"
39 
40 #define IS_INSTANCE(A, B) (dynamic_cast<B const*>(&(A)) != NULL)
41 
42 namespace lsst {
43 namespace afw {
44 namespace math {
45 
46 namespace detail {
67 template <typename OutImageT, typename InImageT>
68 void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage, lsst::afw::math::Kernel const& kernel,
69  lsst::afw::math::ConvolutionControl const& convolutionControl);
70 
79 template <typename OutImageT, typename InImageT>
80 void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
82  lsst::afw::math::ConvolutionControl const& convolutionControl);
83 
105 template <typename OutImageT, typename InImageT>
106 void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
108  lsst::afw::math::ConvolutionControl const& convolutionControl);
109 
118 template <typename OutImageT, typename InImageT>
119 void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
120  lsst::afw::math::SeparableKernel const& kernel,
121  lsst::afw::math::ConvolutionControl const& convolutionControl);
122 
146 template <typename OutImageT, typename InImageT>
147 void 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 
173 public:
178 
193 
205  KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::geom::Box2I const& bbox,
206  lsst::geom::Point2I const& xy0, bool doNormalize);
227  KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::geom::Box2I const& bbox,
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 
280 private:
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;
322  lsst::geom::Point2I _xy0;
323  bool _doNormalize;
324  mutable std::vector<ImagePtr> _imagePtrList;
325 
326  static int const _MinInterpolationSize;
327 };
328 
335 public:
337  typedef RegionList::iterator Iterator;
338  typedef RegionList::const_iterator ConstIterator;
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(); };
366  std::shared_ptr<KernelImagesForRegion> front() { return _regionList.front(); };
370  std::shared_ptr<KernelImagesForRegion> back() { return _regionList.back(); };
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 
384 private:
385  int _nx;
386  int _ny;
387  int _yInd;
388  RegionList _regionList;
389 };
390 
410 template <typename OutImageT, typename InImageT>
411 void convolveWithInterpolation(OutImageT& outImage, InImageT const& inImage,
412  lsst::afw::math::Kernel const& kernel,
413  ConvolutionControl const& convolutionControl);
414 
419 public:
422  : leftImage(dimensions),
423  rightImage(dimensions),
424  leftDeltaImage(dimensions),
425  rightDeltaImage(dimensions),
426  deltaImage(dimensions),
427  kernelImage(dimensions) {}
428  Image leftImage;
429  Image rightImage;
432  Image deltaImage;
433  Image kernelImage;
434 };
435 
448 template <typename OutImageT, typename InImageT>
449 void convolveRegionWithInterpolation(OutImageT& outImage, InImageT const& inImage,
452 
453 /*
454  * Define inline functions
455  */
456 
464 inline 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 
478 inline 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)
lsst::geom::Point2I getXY0() const
Get xy0 of the image.
Definition: Convolve.h:238
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
lsst::geom::Box2I getBBox() const
Get the bounding box for the region.
Definition: Convolve.h:234
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...
Parameters to control convolution.
Definition: ConvolveImage.h:50
ImagePtr getImage(Location location) const
Return the image and sum at the specified location.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:898
Location
locations of various points in the region
Definition: Convolve.h:192
RegionList::iterator begin()
Return the begin iterator for the list.
Definition: Convolve.h:358
std::shared_ptr< KernelImagesForRegion > front()
Return the first region in the list.
Definition: Convolve.h:366
T floor(T... args)
RegionList::iterator end()
Return the end iterator for the list.
Definition: Convolve.h:362
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...
bool getDoNormalize() const
Get the doNormalize parameter.
Definition: Convolve.h:242
static int getMinInterpolationSize()
Get the minInterpolationSize class constant.
Definition: Convolve.h:278
kernel images used by convolveRegionWithInterpolation
Definition: Convolve.h:418
A base class for image defects.
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image
Definition: Convolve.h:420
bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const
Compute next row of subregions.
std::shared_ptr< lsst::afw::math::Kernel const > KernelConstPtr
Definition: Convolve.h:174
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:741
T str(T... args)
A row of KernelImagesForRegion.
Definition: Convolve.h:334
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.
table::Box2IKey bbox
Definition: Detector.cc:166
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
STL class.
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...
RegionList::const_iterator end() const
Return the end iterator for the list.
Definition: Convolve.h:354
KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::geom::Box2I const &bbox, lsst::geom::Point2I const &xy0, bool doNormalize)
Construct a KernelImagesForRegion.
std::shared_ptr< Image const > ImageConstPtr
Definition: Convolve.h:177
RegionList::const_iterator begin() const
Return the begin iterator for the list.
Definition: Convolve.h:350
std::shared_ptr< KernelImagesForRegion > back()
Return the last region in the list.
Definition: Convolve.h:370
Reports invalid arguments.
Definition: Runtime.h:66
ConvolveWithInterpolationWorkingImages(lsst::geom::Extent2I const &dimensions)
Definition: Convolve.h:421
std::shared_ptr< KernelImagesForRegion const > getRegion(int ind) const
get the specified region (range-checked)
Definition: Convolve.h:379
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55
KernelConstPtr getKernel() const
Get the kernel (as a shared pointer to const)
Definition: Convolve.h:254
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:112
An integer coordinate rectangle.
Definition: Box.h:54
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.
A collection of Kernel images for special locations on a rectangular region of an image...
Definition: Convolve.h:172
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:681
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image
Definition: Convolve.h:175
std::ostream * os
Definition: Schema.cc:746
std::vector< std::shared_ptr< KernelImagesForRegion > > RegionList
Definition: Convolve.h:336