LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
ConvolveImage.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_CONVOLVEIMAGE_H
26 #define LSST_AFW_MATH_CONVOLVEIMAGE_H
27 
39 #include <limits>
40 #include <sstream>
41 
42 #include "lsst/pex/exceptions.h"
43 #include "lsst/afw/geom.h"
44 #include "lsst/afw/image/Image.h"
46 #include "lsst/afw/math/Kernel.h"
47 
48 namespace lsst {
49 namespace afw {
50 namespace math {
51 
58  public:
60  bool doNormalize = true,
61  bool doCopyEdge = false,
62  int maxInterpolationDistance = 10
64  )
66  :
67  _doNormalize(doNormalize),
68  _doCopyEdge(doCopyEdge),
69  _maxInterpolationDistance(maxInterpolationDistance)
70  { }
71 
72  bool getDoNormalize() const { return _doNormalize; }
73  bool getDoCopyEdge() const { return _doCopyEdge; }
75 
76  void setDoNormalize(bool doNormalize) {_doNormalize = doNormalize; }
77  void setDoCopyEdge(bool doCopyEdge) { _doCopyEdge = doCopyEdge; }
78  void setMaxInterpolationDistance(int maxInterpolationDistance) {
79  _maxInterpolationDistance = maxInterpolationDistance; }
80 
81  private:
82  bool _doNormalize;
83  bool _doCopyEdge;
86  };
88 
89  template <typename OutImageT, typename InImageT>
90  void scaledPlus(
91  OutImageT &outImage,
92  double c1,
93  InImageT const &inImage1,
94  double c2,
95  InImageT const &inImage2);
96 
97  template <typename OutImageT, typename InImageT>
98  inline typename OutImageT::SinglePixel convolveAtAPoint(
99  typename InImageT::const_xy_locator inImageLocator,
101  int kWidth,
102  int kHeight);
103 
104  template <typename OutImageT, typename InImageT>
105  inline typename OutImageT::SinglePixel convolveAtAPoint(
106  typename InImageT::const_xy_locator inImageLocator,
107  std::vector<lsst::afw::math::Kernel::Pixel> const& kernelColList,
108  std::vector<lsst::afw::math::Kernel::Pixel> const& kernelRowList);
109 
110  template <typename OutImageT, typename InImageT, typename KernelT>
111  void convolve(
112  OutImageT& convolvedImage,
113  InImageT const& inImage,
114  KernelT const& kernel,
115  ConvolutionControl const& convolutionControl = ConvolutionControl());
116 
117  template <typename OutImageT, typename InImageT, typename KernelT>
118  void convolve(
119  OutImageT& convolvedImage,
120  InImageT const& inImage,
121  KernelT const& kernel,
122  bool doNormalize,
123  bool doCopyEdge = false);
124 
130  template <typename ImageT>
131  typename ImageT::SinglePixel edgePixel(
134  ) {
135  typedef typename ImageT::SinglePixel SinglePixelT;
136  return SinglePixelT(
137  std::numeric_limits<SinglePixelT>::has_quiet_NaN ?
138  std::numeric_limits<SinglePixelT>::quiet_NaN() : 0);
139  }
140 
149  template <typename MaskedImageT>
150  typename MaskedImageT::SinglePixel edgePixel(
153  ) {
154  typedef typename MaskedImageT::Image::Pixel ImagePixelT;
155  typedef typename MaskedImageT::Variance::Pixel VariancePixelT;
156 
157  return typename MaskedImageT::SinglePixel(
158  std::numeric_limits<ImagePixelT>::has_quiet_NaN ?
159  std::numeric_limits<ImagePixelT>::quiet_NaN() : 0,
160  MaskedImageT::Mask::getPlaneBitMask("NO_DATA"),
161  std::numeric_limits<VariancePixelT>::infinity());
162  }
163 }}} // lsst::afw::math
164 
165 /*
166  * Define inline functions
167  */
168 
178 template <typename OutImageT, typename InImageT>
179 inline typename OutImageT::SinglePixel lsst::afw::math::convolveAtAPoint(
180  typename InImageT::const_xy_locator inImageLocator,
184  int kWidth,
185  int kHeight)
186 {
187  typename OutImageT::SinglePixel outValue = 0;
188  for (int kRow = 0; kRow != kHeight; ++kRow) {
190  kernelLocator + lsst::afw::image::detail::difference_type(kWidth, 0);
191  kernelLocator != kEnd; ++inImageLocator.x(), ++kernelLocator.x()) {
192  typename lsst::afw::math::Kernel::Pixel const kVal = kernelLocator[0];
193  if (kVal != 0) {
194  outValue += *inImageLocator*kVal;
195  }
196  }
197 
198  inImageLocator += lsst::afw::image::detail::difference_type(-kWidth, 1);
199  kernelLocator += lsst::afw::image::detail::difference_type(-kWidth, 1);
200  }
201 
202  return outValue;
203 }
204 
214 template <typename OutImageT, typename InImageT>
215 inline typename OutImageT::SinglePixel lsst::afw::math::convolveAtAPoint(
216  typename InImageT::const_xy_locator inImageLocator,
217  std::vector<lsst::afw::math::Kernel::Pixel> const &kernelXList,
219  std::vector<lsst::afw::math::Kernel::Pixel> const &kernelYList)
220 {
221  typedef typename std::vector<lsst::afw::math::Kernel::Pixel>::const_iterator k_iter;
222 
223  typedef typename OutImageT::SinglePixel OutT;
224  OutT outValue = 0;
225  for (k_iter kernelYIter = kernelYList.begin(), yEnd = kernelYList.end();
226  kernelYIter != yEnd; ++kernelYIter) {
227 
228  OutT outValueY = 0;
229  for (k_iter kernelXIter = kernelXList.begin(), xEnd = kernelXList.end();
230  kernelXIter != xEnd; ++kernelXIter, ++inImageLocator.x()) {
231  typename lsst::afw::math::Kernel::Pixel const kValX = *kernelXIter;
232  if (kValX != 0) {
233  outValueY += *inImageLocator*kValX;
234  }
235  }
236 
237  double const kValY = *kernelYIter;
238  if (kValY != 0) {
239  outValue += outValueY*kValY;
240  }
241 
242  inImageLocator += lsst::afw::image::detail::difference_type(-kernelXList.size(), 1);
243  }
244 
245  return outValue;
246 }
247 
248 
249 #endif // !defined(LSST_AFW_MATH_CONVOLVEIMAGE_H)
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
Compute the scaled sum of two images.
An include file to include the header files for lsst::afw::geom.
Declare the Kernel class and subclasses.
OutImageT::SinglePixel convolveAtAPoint(typename InImageT::const_xy_locator inImageLocator, typename lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel >::const_xy_locator kernelLocator, int kWidth, int kHeight)
Apply convolution kernel to an image at one point.
Include files required for standard LSST Exception handling.
Parameters to control convolution.
Definition: ConvolveImage.h:57
bool _doNormalize
normalize the kernel to sum=1?
Definition: ConvolveImage.h:82
void setDoCopyEdge(bool doCopyEdge)
Definition: ConvolveImage.h:77
bool _doCopyEdge
copy edge pixels from source image
Definition: ConvolveImage.h:83
void setDoNormalize(bool doNormalize)
Definition: ConvolveImage.h:76
ConvolutionControl(bool doNormalize=true, bool doCopyEdge=false, int maxInterpolationDistance=10)
Definition: ConvolveImage.h:59
A traits class for MaskedImage.
Definition: MaskedImage.h:54
void setMaxInterpolationDistance(int maxInterpolationDistance)
Definition: ConvolveImage.h:78
Support for 2-D images.
ImageT::SinglePixel edgePixel(lsst::afw::image::detail::Image_tag)
Return an off-the-edge pixel appropriate for a given Image type.
_view_t::xy_locator::const_t const_xy_locator
A const_xy_locator.
Definition: Image.h:140
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...
Implementation of the Class MaskedImage.
int _maxInterpolationDistance
maximum width or height of a region
Definition: ConvolveImage.h:85