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
Files | Namespaces | Classes | Functions
LSST framework

Files

file  Coord.cc
 Provide functions to handle coordinates.
 
file  PsfFormatter.cc
 Implementation of PsfFormatter class.
 
file  DecoratedImageFormatter.cc
 Implementation of DecoratedImageFormatter class.
 
file  ExposureFormatter.cc
 Implementation of ExposureFormatter class.
 
file  ImageFormatter.cc
 Implementation of ImageFormatter class.
 
file  MaskedImageFormatter.cc
 Implementation of MaskedImageFormatter class.
 
file  MaskFormatter.cc
 Implementation of MaskFormatter class.
 
file  TanWcsFormatter.cc
 Implementation of TanWcsFormatter class.
 
file  WcsFormatter.cc
 Implementation of WcsFormatter class.
 
file  Background.cc
 Background estimation class code.
 
file  Background.cc
 Background estimation class code.
 
file  ConvolveImage.cc
 Definition of functions declared in ConvolveImage.h.
 
file  BasicConvolve.cc
 Definition of basicConvolve and convolveWithBruteForce functions declared in detail/ConvolveImage.h.
 
file  ConvolveWithInterpolation.cc
 Definition of convolveWithInterpolation and helper functions declared in detail/ConvolveImage.h.
 
file  KernelImagesForRegion.cc
 Definition of KernelImagesForRegion class declared in detail/ConvolveImage.h.
 
file  KernelFunctions.cc
 Definitions of members of lsst::afw::math.
 
file  minimize.cc
 Definition of member functions for minuit adaptors.
 
file  Random.cc
 Random number generator implementaion.
 
file  RandomImage.cc
 Fill Images with Random numbers.
 
file  SpatialCell.cc
 Implementation of SpatialCell class.
 
file  Statistics.cc
 Support statistical operations on images.
 
file  warpExposure.cc
 Support for warping an image to a new Wcs.
 
file  Coord.h
 Functions to handle coordinates.
 
file  Observatory.h
 Class to hold observatory/telescope location.
 
file  PsfFormatter.h
 Interface for PsfFormatter class.
 
file  DecoratedImageFormatter.h
 Interface for DecoratedImageFormatter class.
 
file  ExposureFormatter.h
 Interface for ExposureFormatter class.
 
file  ImageFormatter.h
 Interface for ImageFormatter class.
 
file  MaskedImageFormatter.h
 Interface for MaskedImageFormatter class.
 
file  MaskFormatter.h
 Interface for MaskFormatter class.
 
file  TanWcsFormatter.h
 Interface for TanWcsFormatter class.
 
file  WcsFormatter.h
 Interface for WcsFormatter class.
 
file  ImageSlice.h
 Define a single column or row of an Image.
 
file  ConvolveImage.h
 Convolve and convolveAtAPoint functions for Image and Kernel.
 
file  Convolve.h
 Convolution support.
 
file  PositionFunctor.h
 image warping
 
file  detail.h
 An include file to include the header files for lsst::afw::math::detail.
 
file  Function.h
 Define the basic Function classes.
 
file  FunctionLibrary.h
 Define a collection of useful Functions.
 
file  Integrate.h
 Compute 1d and 2d integral.
 
file  Kernel.h
 Declare the Kernel class and subclasses.
 
file  KernelFunctions.h
 Utility functions for kernels.
 
file  minimize.h
 Adaptor for minuit.
 
file  Random.h
 Random number generator class.
 
file  SpatialCell.h
 Class to ensure constraints for spatial modeling.
 
file  Statistics.h
 Compute Image Statistics.
 
file  warpExposure.h
 Support for warping an image to a new WCS.
 

Namespaces

 lsst
 Remove all non-astronomical counts from the Chunk Exposure's pixels.
 

Classes

class  lsst::afw::math::ApproximateControl
 Control how to make an approximation. More...
 
class  lsst::afw::math::Approximate< T >
 Approximate values for a MaskedImage. More...
 
class  lsst::afw::math::ConvolutionControl
 Parameters to control convolution. More...
 
class  lsst::afw::math::Function< ReturnT >
 Basic Function class. More...
 
class  lsst::afw::math::Function1< ReturnT >
 A Function taking one argument. More...
 
class  lsst::afw::math::Function2< ReturnT >
 A Function taking two arguments. More...
 
class  lsst::afw::math::BasePolynomialFunction2< ReturnT >
 Base class for 2-dimensional polynomials of the form: More...
 
class  lsst::afw::math::IntegerDeltaFunction1< ReturnT >
 1-dimensional integer delta function. More...
 
class  lsst::afw::math::IntegerDeltaFunction2< ReturnT >
 2-dimensional integer delta function. More...
 
class  lsst::afw::math::GaussianFunction1< ReturnT >
 1-dimensional Gaussian More...
 
class  lsst::afw::math::GaussianFunction2< ReturnT >
 2-dimensional Gaussian More...
 
class  lsst::afw::math::DoubleGaussianFunction2< ReturnT >
 double Guassian (sum of two Gaussians) More...
 
class  lsst::afw::math::PolynomialFunction1< ReturnT >
 1-dimensional polynomial function. More...
 
class  lsst::afw::math::PolynomialFunction2< ReturnT >
 2-dimensional polynomial function with cross terms More...
 
class  lsst::afw::math::Chebyshev1Function1< ReturnT >
 1-dimensional weighted sum of Chebyshev polynomials of the first kind. More...
 
class  lsst::afw::math::Chebyshev1Function2< ReturnT >
 2-dimensional weighted sum of Chebyshev polynomials of the first kind. More...
 
class  lsst::afw::math::LanczosFunction1< ReturnT >
 1-dimensional Lanczos function More...
 
class  lsst::afw::math::LanczosFunction2< ReturnT >
 2-dimensional separable Lanczos function More...
 
class  lsst::afw::math::Interpolate
 Interpolate values for a set of x,y vector<>s. More...
 
class  lsst::afw::math::Kernel
 Kernels are used for convolution with MaskedImages and (eventually) Images. More...
 
class  lsst::afw::math::FixedKernel
 A kernel created from an Image. More...
 
class  lsst::afw::math::AnalyticKernel
 A kernel described by a function. More...
 
class  lsst::afw::math::DeltaFunctionKernel
 A kernel that has only one non-zero pixel (of value 1) More...
 
class  lsst::afw::math::LinearCombinationKernel
 A kernel that is a linear combination of fixed basis kernels. More...
 
class  lsst::afw::math::SeparableKernel
 A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y) More...
 
class  lsst::afw::math::StatisticsControl
 Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calculated. More...
 
class  lsst::afw::math::Statistics
 A class to evaluate image statistics. More...
 
class  lsst::afw::math::WarpingControl
 Parameters to control convolution. More...
 
class  lsst::afw::detection::PsfFormatter
 Formatter for persistence of Psf instances. More...
 
class  lsst::afw::formatters::DecoratedImageFormatter< ImagePixelT >
 Class implementing persistence and retrieval for DecoratedImages. More...
 
class  lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >
 Class implementing persistence and retrieval for Exposures. More...
 
class  lsst::afw::formatters::ImageFormatter< ImagePixelT >
 Class implementing persistence and retrieval for Images. More...
 
class  lsst::afw::formatters::MaskedImageFormatter< ImagePixelT, MaskPixelT, VariancePixelT >
 Class implementing persistence and retrieval for MaskedImages. More...
 
class  lsst::afw::formatters::MaskFormatter< MaskPixelT >
 Class implementing persistence and retrieval for Masks. More...
 
class  lsst::afw::formatters::TanWcsFormatter
 Class implementing persistence and retrieval for TanWcs objects. More...
 
class  lsst::afw::formatters::WcsFormatter
 Class implementing persistence and retrieval for Wcs objects. More...
 
class  lsst::afw::image::ImageSlice< PixelT >
 A class to specify a slice of an image. More...
 

Functions

template<typename OutImageT , typename InImageT , typename KernelT >
void lsst::afw::math::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. More...
 
template<typename OutImageT , typename InImageT >
void lsst.afw.math.detail::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. More...
 
template<typename OutImageT , typename InImageT >
void lsst.afw.math.detail::basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::DeltaFunctionKernel const &kernel, lsst::afw::math::ConvolutionControl const &)
 A version of basicConvolve that should be used when convolving delta function kernels. More...
 
template<typename OutImageT , typename InImageT >
void lsst.afw.math.detail::basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::LinearCombinationKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 A version of basicConvolve that should be used when convolving a LinearCombinationKernel. More...
 
template<typename OutImageT , typename InImageT >
void lsst.afw.math.detail::basicConvolve (OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::SeparableKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
 A version of basicConvolve that should be used when convolving separable kernels. More...
 
template<typename OutImageT , typename InImageT >
void lsst.afw.math.detail::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. More...
 
void lsst::afw::math::printKernel (lsst::afw::math::Kernel const &kernel, bool doNormalize, double x=0, double y=0, std::string pixelFmt="%7.3f")
 Print the pixel values of a Kernel to std::cout. More...
 
template<typename OutImageT , typename InImageT >
OutImageT::SinglePixel lsst::afw::math::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. More...
 
template<typename OutImageT , typename InImageT >
OutImageT::SinglePixel lsst::afw::math::convolveAtAPoint (typename InImageT::const_xy_locator inImageLocator, std::vector< lsst::afw::math::Kernel::Pixel > const &kernelColList, std::vector< lsst::afw::math::Kernel::Pixel > const &kernelRowList)
 Apply separable convolution kernel to an image at one point. More...
 

Detailed Description

Function Documentation

template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::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.

convolvedImage must be the same size as inImage. convolvedImage has a border in which the output pixels are not set. This border has size:

  • kernel.getCtrX() along the left edge
  • kernel.getCtrY() along the bottom edge
  • kernel.getWidth() - 1 - kernel.getCtrX() along the right edge
  • kernel.getHeight() - 1 - kernel.getCtrY() along the top edge
Exceptions
lsst::pex::exceptions::InvalidParameterErrorif convolvedImage dimensions != inImage dimensions
lsst::pex::exceptions::InvalidParameterErrorif inImage smaller than kernel in width or height
lsst::pex::exceptions::InvalidParameterErrorif kernel width or height < 1
lsst::pex::exceptions::MemoryErrorwhen allocation of CPU memory fails
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 151 of file BasicConvolve.cc.

156 {
157  // Because convolve isn't a method of Kernel we can't always use Kernel's vtbl to dynamically
158  // dispatch the correct version of basicConvolve. The case that fails is convolving with a kernel
159  // obtained from a pointer or reference to a Kernel (base class), e.g. as used in LinearCombinationKernel.
161  LOGL_DEBUG("TRACE3.afw.math.convolve.basicConvolve",
162  "generic basicConvolve: dispatch to DeltaFunctionKernel basicConvolve");
163  mathDetail::basicConvolve(convolvedImage, inImage,
164  *dynamic_cast<afwMath::DeltaFunctionKernel const*>(&kernel),
165  convolutionControl);
166  return;
167  } else if (IS_INSTANCE(kernel, afwMath::SeparableKernel)) {
168  LOGL_DEBUG("TRACE3.afw.math.convolve.basicConvolve",
169  "generic basicConvolve: dispatch to SeparableKernel basicConvolve");
170  mathDetail::basicConvolve(convolvedImage, inImage,
171  *dynamic_cast<afwMath::SeparableKernel const*>(&kernel),
172  convolutionControl);
173  return;
174  } else if (IS_INSTANCE(kernel, afwMath::LinearCombinationKernel) && kernel.isSpatiallyVarying()) {
175  LOGL_DEBUG("TRACE3.afw.math.convolve.basicConvolve",
176  "generic basicConvolve: dispatch to spatially varying LinearCombinationKernel basicConvolve");
177  mathDetail::basicConvolve(convolvedImage, inImage,
178  *dynamic_cast<afwMath::LinearCombinationKernel const*>(&kernel),
179  convolutionControl);
180  return;
181  }
182  // OK, use general (and slower) form
183  if (kernel.isSpatiallyVarying() && (convolutionControl.getMaxInterpolationDistance() > 1)) {
184  // use linear interpolation
185  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
186  "generic basicConvolve: using linear interpolation");
187  mathDetail::convolveWithInterpolation(convolvedImage, inImage, kernel, convolutionControl);
188 
189  } else {
190  // use brute force
191  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
192  "generic basicConvolve: using brute force");
193  mathDetail::convolveWithBruteForce(convolvedImage, inImage, kernel,convolutionControl);
194  }
195 }
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:983
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...
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
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 kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:811
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.
#define IS_INSTANCE(A, B)
Definition: Convolve.h:46
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:741
template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::basicConvolve ( OutImageT &  convolvedImage,
InImageT const &  inImage,
lsst::afw::math::DeltaFunctionKernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)

A version of basicConvolve that should be used when convolving delta function kernels.

Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 203 of file BasicConvolve.cc.

208 {
209  assert (!kernel.isSpatiallyVarying());
210  assertDimensionsOK(convolvedImage, inImage, kernel);
211 
212  int const mImageWidth = inImage.getWidth(); // size of input region
213  int const mImageHeight = inImage.getHeight();
214  int const cnvWidth = mImageWidth + 1 - kernel.getWidth();
215  int const cnvHeight = mImageHeight + 1 - kernel.getHeight();
216  int const cnvStartX = kernel.getCtrX();
217  int const cnvStartY = kernel.getCtrY();
218  int const inStartX = kernel.getPixel().getX();
219  int const inStartY = kernel.getPixel().getY();
220 
221  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve", "DeltaFunctionKernel basicConvolve");
222 
223  for (int i = 0; i < cnvHeight; ++i) {
224  typename InImageT::x_iterator inPtr = inImage.x_at(inStartX, i + inStartY);
225  for (typename OutImageT::x_iterator cnvPtr = convolvedImage.x_at(cnvStartX, i + cnvStartY),
226  cnvEnd = cnvPtr + cnvWidth; cnvPtr != cnvEnd; ++cnvPtr, ++inPtr){
227  *cnvPtr = *inPtr;
228  }
229  }
230 }
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::basicConvolve ( OutImageT &  convolvedImage,
InImageT const &  inImage,
lsst::afw::math::LinearCombinationKernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)

A version of basicConvolve that should be used when convolving a LinearCombinationKernel.

The Algorithm:

  • If the kernel is spatially varying and contains only DeltaFunctionKernels then convolves the input Image by each basis kernel in turn, solves the spatial model for that component and adds in the appropriate amount of the convolved image.
  • In all other cases uses normal convolution
Exceptions
lsst::pex::exceptions::InvalidParameterErrorif convolvedImage dimensions != inImage dimensions
lsst::pex::exceptions::InvalidParameterErrorif inImage smaller than kernel in width or height
lsst::pex::exceptions::InvalidParameterErrorif kernel width or height < 1
lsst::pex::exceptions::MemoryErrorwhen allocation of CPU memory fails
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 249 of file BasicConvolve.cc.

254 {
255  if (!kernel.isSpatiallyVarying()) {
256  // use the standard algorithm for the spatially invariant case
257  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
258  "basicConvolve for LinearCombinationKernel: spatially invariant; using brute force");
259  return mathDetail::convolveWithBruteForce(convolvedImage, inImage, kernel,
260  convolutionControl.getDoNormalize());
261  } else {
262  // refactor the kernel if this is reasonable and possible;
263  // then use the standard algorithm for the spatially varying case
264  PTR(afwMath::Kernel) refKernelPtr; // possibly refactored version of kernel
265  if (static_cast<int>(kernel.getNKernelParameters()) > kernel.getNSpatialParameters()) {
266  // refactoring will speed convolution, so try it
267  refKernelPtr = kernel.refactor();
268  if (!refKernelPtr) {
269  refKernelPtr = kernel.clone();
270  }
271  } else {
272  // too few basis kernels for refactoring to be worthwhile
273  refKernelPtr = kernel.clone();
274  }
275  if (convolutionControl.getMaxInterpolationDistance() > 1) {
276  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
277  "basicConvolve for LinearCombinationKernel: using interpolation");
278  return mathDetail::convolveWithInterpolation(convolvedImage, inImage, *refKernelPtr, convolutionControl);
279  } else {
280  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
281  "basicConvolve for LinearCombinationKernel: maxInterpolationError < 0; using brute force");
282  return mathDetail::convolveWithBruteForce(convolvedImage, inImage, *refKernelPtr,
283  convolutionControl.getDoNormalize());
284  }
285  }
286 }
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...
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
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.
virtual boost::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
#define PTR(...)
Definition: base.h:41
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:131
template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::basicConvolve ( OutImageT &  convolvedImage,
InImageT const &  inImage,
lsst::afw::math::SeparableKernel const &  kernel,
lsst::afw::math::ConvolutionControl const &  convolutionControl 
)

A version of basicConvolve that should be used when convolving separable kernels.

Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 294 of file BasicConvolve.cc.

299 {
300  typedef typename afwMath::Kernel::Pixel KernelPixel;
301  typedef typename std::vector<KernelPixel> KernelVector;
302  typedef KernelVector::const_iterator KernelIterator;
303  typedef typename InImageT::const_x_iterator InXIterator;
304  typedef typename InImageT::const_xy_locator InXYLocator;
305  typedef typename OutImageT::x_iterator OutXIterator;
306  typedef typename OutImageT::y_iterator OutYIterator;
307  typedef typename OutImageT::SinglePixel OutPixel;
308 
309  assertDimensionsOK(convolvedImage, inImage, kernel);
310 
311  afwGeom::Box2I const fullBBox = inImage.getBBox(image::LOCAL);
312  afwGeom::Box2I const goodBBox = kernel.shrinkBBox(fullBBox);
313 
314  KernelVector kernelXVec(kernel.getWidth());
315  KernelVector kernelYVec(kernel.getHeight());
316 
317  if (kernel.isSpatiallyVarying()) {
318  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
319  "SeparableKernel basicConvolve: kernel is spatially varying");
320 
321  for (int cnvY = goodBBox.getMinY(); cnvY <= goodBBox.getMaxY(); ++cnvY) {
322  double const rowPos = inImage.indexToPosition(cnvY, afwImage::Y);
323 
324  InXYLocator inImLoc = inImage.xy_at(0, cnvY - goodBBox.getMinY());
325  OutXIterator cnvXIter = convolvedImage.row_begin(cnvY) + goodBBox.getMinX();
326  for (int cnvX = goodBBox.getMinX(); cnvX <= goodBBox.getMaxX();
327  ++cnvX, ++inImLoc.x(), ++cnvXIter) {
328  double const colPos = inImage.indexToPosition(cnvX, afwImage::X);
329 
330  KernelPixel kSum = kernel.computeVectors(kernelXVec, kernelYVec,
331  convolutionControl.getDoNormalize(), colPos, rowPos);
332 
333  // why does this trigger warnings? It did not in the past.
334  *cnvXIter = afwMath::convolveAtAPoint<OutImageT, InImageT>(inImLoc, kernelXVec, kernelYVec);
335  if (convolutionControl.getDoNormalize()) {
336  *cnvXIter = *cnvXIter/kSum;
337  }
338  }
339  }
340  } else {
341  // kernel is spatially invariant
342  // The basic sequence:
343  // - For each output row:
344  // - Compute x-convolved data: a kernel height's strip of input image convolved with kernel x vector
345  // - Compute one row of output by dotting each column of x-convolved data with the kernel y vector
346  // The x-convolved data is stored in a kernel-height by good-width buffer.
347  // This is circular buffer along y (to avoid shifting pixels before setting each new row);
348  // so for each new row the kernel y vector is rotated to match the order of the x-convolved data.
349 
350  LOGL_DEBUG("TRACE2.afw.math.convolve.basicConvolve",
351  "SeparableKernel basicConvolve: kernel is spatially invariant");
352 
353  kernel.computeVectors(kernelXVec, kernelYVec, convolutionControl.getDoNormalize());
354  KernelIterator const kernelXVecBegin = kernelXVec.begin();
355  KernelIterator const kernelYVecBegin = kernelYVec.begin();
356 
357  // buffer for x-convolved data
358  OutImageT buffer(afwGeom::Extent2I(goodBBox.getWidth(), kernel.getHeight()));
359 
360  // pre-fill x-convolved data buffer with all but one row of data
361  int yInd = 0; // during initial fill bufY = inImageY
362  int const yPrefillEnd = buffer.getHeight() - 1;
363  for (; yInd < yPrefillEnd; ++yInd) {
364  OutXIterator bufXIter = buffer.x_at(0, yInd);
365  OutXIterator const bufXEnd = buffer.x_at(goodBBox.getWidth(), yInd);
366  InXIterator inXIter = inImage.x_at(0, yInd);
367  for ( ; bufXIter != bufXEnd; ++bufXIter, ++inXIter) {
368  *bufXIter = kernelDotProduct<OutPixel, InXIterator, KernelIterator, KernelPixel>(
369  inXIter, kernelXVecBegin, kernel.getWidth());
370  }
371  }
372 
373  // compute output pixels using the sequence described above
374  int inY = yPrefillEnd;
375  int bufY = yPrefillEnd;
376  int cnvY = goodBBox.getMinY();
377  while (true) {
378  // fill next buffer row and compute output row
379  InXIterator inXIter = inImage.x_at(0, inY);
380  OutXIterator bufXIter = buffer.x_at(0, bufY);
381  OutXIterator cnvXIter = convolvedImage.x_at(goodBBox.getMinX(), cnvY);
382  for (int bufX = 0; bufX < goodBBox.getWidth(); ++bufX, ++cnvXIter, ++bufXIter, ++inXIter) {
383  // note: bufXIter points to the row of the buffer that is being updated,
384  // whereas bufYIter points to row 0 of the buffer
385  *bufXIter = kernelDotProduct<OutPixel, InXIterator, KernelIterator, KernelPixel>(
386  inXIter, kernelXVecBegin, kernel.getWidth());
387 
388  OutYIterator bufYIter = buffer.y_at(bufX, 0);
389  *cnvXIter = kernelDotProduct<OutPixel, OutYIterator, KernelIterator, KernelPixel>(
390  bufYIter, kernelYVecBegin, kernel.getHeight());
391  }
392 
393  // test for done now, instead of the start of the loop,
394  // to avoid an unnecessary extra rotation of the kernel Y vector
395  if (cnvY >= goodBBox.getMaxY()) break;
396 
397  // update y indices, including bufY, and rotate the kernel y vector to match
398  ++inY;
399  bufY = (bufY + 1) % kernel.getHeight();
400  ++cnvY;
401  std::rotate(kernelYVec.begin(), kernelYVec.end()-1, kernelYVec.end());
402  }
403  }
404 }
int getMinY() const
Definition: Box.h:125
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
An integer coordinate rectangle.
Definition: Box.h:53
int getMinX() const
Definition: Box.h:124
int getMaxX() const
Definition: Box.h:128
int getWidth() const
Definition: Box.h:154
int getMaxY() const
Definition: Box.h:129
template<typename OutImageT , typename InImageT , typename KernelT >
void lsst::afw::math::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.

Various convolution kernels are available, including:

  • FixedKernel: a kernel based on an image
  • AnalyticKernel: a kernel based on a Function
  • SeparableKernel: a kernel described by the product of two one-dimensional Functions: f0(x) * f1(y)
  • LinearCombinationKernel: a linear combination of a set of spatially invariant basis kernels.
  • DeltaFunctionKernel: a kernel that is all zeros except one pixel whose value is 1. Typically used as a basis kernel for LinearCombinationKernel.

If a kernel is spatially varying, its spatial model is computed at each pixel position on the image (pixel position, not pixel index). At present (2009-09-24) this position is computed relative to the lower left corner of the sub-image, but it will almost certainly change to be the lower left corner of the parent image.

All convolution is performed in real space. This allows convolution to handle masked pixels and spatially varying kernels. Although convolution of an Image with a spatially invariant kernel could, in fact, be performed in Fourier space, the code does not do this.

Note that mask bits are smeared by convolution; all nonzero pixels in the kernel smear the mask, even pixels that have very small values. Larger kernels smear the mask more and are also slower to convolve. Use the smallest kernel that will do the job.

convolvedImage has a border of edge pixels which cannot be computed normally. Normally these pixels are set to the standard edge pixel, as returned by edgePixel(). However, if your code cannot handle nans in the image or infs in the variance, you may set doCopyEdge true, in which case the edge pixels are set to the corresponding pixels of the input image and (if there is a mask) the mask EDGE bit is set.

The border of edge pixels has size:

  • kernel.getCtrX() along the left edge
  • kernel.getCtrY() along the bottom edge
  • kernel.getWidth() - 1 - kernel.getCtrX() along the right edge
  • kernel.getHeight() - 1 - kernel.getCtrY() along the top edge You can obtain a bounding box for the good pixels in the convolved image from a bounding box for the entire image using the Kernel method shrinkBBox.

Convolution has been optimized for the various kinds of kernels, as follows (listed approximately in order of decreasing speed):

  • DeltaFunctionKernel convolution is a simple image shift.
  • SeparableKernel convolution is performed by convolving the input by one of the two functions, then the result by the other function. Thus convolution with a kernel of size nCols x nRows becomes convolution with a kernel of size nCols x 1, followed by convolution with a kernel of size 1 x nRows.
  • Convolution with spatially invariant versions of the other kernels is performed by computing the kernel image once and convolving with that. The code has been optimized for cache performance and so should be fairly efficient.
  • Convolution with a spatially varying LinearCombinationKernel is performed by convolving the image by each basis kernel and combining the result by solving the spatial model. This will be efficient provided the kernel does not contain too many or very large basis kernels.
  • Convolution with spatially varying AnalyticKernel is likely to be slow. The code simply computes the output one pixel at a time by computing the AnalyticKernel at that point and applying it to the input image. This is not favorable for cache performance (especially for large kernels) but avoids recomputing the AnalyticKernel. It is probably possible to do better.

Additional convolution functions include:

  • convolveAtAPoint(): convolve a Kernel to an Image or MaskedImage at a point.
  • basicConvolve(): convolve a Kernel with an Image or MaskedImage, but do not set the edge pixels of the output. Optimization of convolution for different types of Kernel are handled by different specializations of basicConvolve().

afw/examples offers programs that time convolution including timeConvolve and timeSpatiallyVaryingConvolve.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif convolvedImage is not the same size as inImage
lsst::pex::exceptions::InvalidParameterErrorif inImage is smaller than kernel in columns and/or rows.
lsst::pex::exceptions::MemoryErrorwhen allocation of CPU memory fails
Parameters
convolvedImageconvolved image; must be the same size as inImage
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 319 of file ConvolveImage.cc.

324 {
325  mathDetail::basicConvolve(convolvedImage, inImage, kernel, convolutionControl);
326  setEdgePixels(convolvedImage, kernel, inImage, convolutionControl.getDoCopyEdge(),
328  );
329  convolvedImage.setXY0(inImage.getXY0());
330 }
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.
ImageT::image_category image_category
Definition: Image.h:78
template<typename OutImageT , typename InImageT >
OutImageT::SinglePixel lsst::afw::math::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 
)
inline

Apply convolution kernel to an image at one point.

Note
This subroutine sacrifices convenience for performance. The user is expected to figure out the kernel center and adjust the supplied pixel accessors accordingly. For an example of how to do this see convolve().
Parameters
inImageLocatorlocator for image pixel that overlaps pixel (0,0) of kernel (the origin of the kernel, not its center)
kernelLocatorlocator for (0,0) pixel of kernel (the origin of the kernel, not its center)
kWidthnumber of columns in kernel
kHeightnumber of rows in kernel

Definition at line 179 of file ConvolveImage.h.

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 }
_view_t::xy_locator::const_t const_xy_locator
A const_xy_locator.
Definition: Image.h:140
template<typename OutImageT , typename InImageT >
OutImageT::SinglePixel lsst::afw::math::convolveAtAPoint ( typename InImageT::const_xy_locator  inImageLocator,
std::vector< lsst::afw::math::Kernel::Pixel > const &  kernelXList,
std::vector< lsst::afw::math::Kernel::Pixel > const &  kernelYList 
)
inline

Apply separable convolution kernel to an image at one point.

Note
This subroutine sacrifices convenience for performance. The user is expected to figure out the kernel center and adjust the supplied pixel accessors accordingly. For an example of how to do this see convolve().
Parameters
inImageLocatorlocator for image pixel that overlaps pixel (0,0) of kernel (the origin of the kernel, not its center)
kernelXListkernel column vector
kernelYListkernel row vector

Definition at line 215 of file ConvolveImage.h.

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 }
template<typename OutImageT , typename InImageT >
void lsst::afw::math::detail::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.

(If the kernel is not spatially varying then only compute it once).

Warning
Low-level convolution function that does not set edge pixels.

convolvedImage must be the same size as inImage. convolvedImage has a border in which the output pixels are not set. This border has size:

  • kernel.getCtrX() along the left edge
  • kernel.getCtrY() along the bottom edge
  • kernel.getWidth() - 1 - kernel.getCtrX() along the right edge
  • kernel.getHeight() - 1 - kernel.getCtrY() along the top edge
Exceptions
lsst::pex::exceptions::InvalidParameterErrorif convolvedImage dimensions != inImage dimensions
lsst::pex::exceptions::InvalidParameterErrorif inImage smaller than kernel in width or height
lsst::pex::exceptions::InvalidParameterErrorif kernel width or height < 1
lsst::pex::exceptions::MemoryErrorwhen allocation of CPU memory fails
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 427 of file BasicConvolve.cc.

432 {
433  bool doNormalize=convolutionControl.getDoNormalize();
434 
435  typedef typename afwMath::Kernel::Pixel KernelPixel;
436  typedef afwImage::Image<KernelPixel> KernelImage;
437 
438  typedef typename KernelImage::const_x_iterator KernelXIterator;
439  typedef typename KernelImage::const_xy_locator KernelXYLocator;
440  typedef typename InImageT::const_x_iterator InXIterator;
441  typedef typename InImageT::const_xy_locator InXYLocator;
442  typedef typename OutImageT::x_iterator OutXIterator;
443  typedef typename OutImageT::SinglePixel OutPixel;
444 
445  assertDimensionsOK(convolvedImage, inImage, kernel);
446 
447  int const inImageWidth = inImage.getWidth();
448  int const inImageHeight = inImage.getHeight();
449  int const kWidth = kernel.getWidth();
450  int const kHeight = kernel.getHeight();
451  int const cnvWidth = inImageWidth + 1 - kernel.getWidth();
452  int const cnvHeight = inImageHeight + 1 - kernel.getHeight();
453  int const cnvStartX = kernel.getCtrX();
454  int const cnvStartY = kernel.getCtrY();
455  int const cnvEndX = cnvStartX + cnvWidth; // end index + 1
456  int const cnvEndY = cnvStartY + cnvHeight; // end index + 1
457 
458  KernelImage kernelImage(kernel.getDimensions());
459  KernelXYLocator const kernelLoc = kernelImage.xy_at(0,0);
460 
461  if (kernel.isSpatiallyVarying()) {
462  LOGL_DEBUG("TRACE4.afw.math.convolve.convolveWithBruteForce",
463  "convolveWithBruteForce: kernel is spatially varying");
464 
465  for (int cnvY = cnvStartY; cnvY != cnvEndY; ++cnvY) {
466  double const rowPos = inImage.indexToPosition(cnvY, afwImage::Y);
467 
468  InXYLocator inImLoc = inImage.xy_at(0, cnvY - cnvStartY);
469  OutXIterator cnvXIter = convolvedImage.x_at(cnvStartX, cnvY);
470  for (int cnvX = cnvStartX; cnvX != cnvEndX; ++cnvX, ++inImLoc.x(), ++cnvXIter) {
471  double const colPos = inImage.indexToPosition(cnvX, afwImage::X);
472 
473  KernelPixel kSum = kernel.computeImage(kernelImage, false, colPos, rowPos);
474  *cnvXIter = afwMath::convolveAtAPoint<OutImageT, InImageT>(
475  inImLoc, kernelLoc, kWidth, kHeight);
476  if (doNormalize) {
477  *cnvXIter = *cnvXIter/kSum;
478  }
479  }
480  }
481  } else {
482  LOGL_DEBUG("TRACE4.afw.math.convolve.convolveWithBruteForce",
483  "convolveWithBruteForce: kernel is spatially invariant");
484 
485  (void)kernel.computeImage(kernelImage, doNormalize);
486 
487  for (int inStartY = 0, cnvY = cnvStartY; inStartY < cnvHeight; ++inStartY, ++cnvY) {
488  KernelXIterator kernelXIter = kernelImage.x_at(0, 0);
489  InXIterator inXIter = inImage.x_at(0, inStartY);
490  OutXIterator cnvXIter = convolvedImage.x_at(cnvStartX, cnvY);
491  for (int x = 0; x < cnvWidth; ++x, ++cnvXIter, ++inXIter) {
492  *cnvXIter = kernelDotProduct<OutPixel, InXIterator, KernelXIterator, KernelPixel>(
493  inXIter, kernelXIter, kWidth);
494  }
495  for (int kernelY = 1, inY = inStartY + 1; kernelY < kHeight; ++inY, ++kernelY) {
496  KernelXIterator kernelXIter = kernelImage.x_at(0, kernelY);
497  InXIterator inXIter = inImage.x_at(0, inY);
498  OutXIterator cnvXIter = convolvedImage.x_at(cnvStartX, cnvY);
499  for (int x = 0; x < cnvWidth; ++x, ++cnvXIter, ++inXIter) {
500  *cnvXIter += kernelDotProduct<OutPixel, InXIterator, KernelXIterator, KernelPixel>(
501  inXIter, kernelXIter, kWidth);
502  }
503  }
504  }
505  }
506 }
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
double x
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:416
void lsst::afw::math::printKernel ( lsst::afw::math::Kernel const &  kernel,
bool  doNormalize,
double  xPos = 0,
double  yPos = 0,
std::string  pixelFmt = "%7.3f" 
)

Print the pixel values of a Kernel to std::cout.

Rows increase upward and columns to the right; thus the lower left pixel is (0,0).

Parameters
kernelthe kernel
doNormalizeif true, normalize kernel
xPosx at which to evaluate kernel
yPosy at which to evaluate kernel
pixelFmtformat for pixel values

Definition at line 46 of file KernelFunctions.cc.

52  {
53  typedef lsst::afw::math::Kernel::Pixel Pixel;
54 
55  lsst::afw::image::Image<Pixel> kImage(kernel.getDimensions());
56  double kSum = kernel.computeImage(kImage, doNormalize, xPos, yPos);
57 
58  for (int y = kImage.getHeight() - 1; y >= 0; --y) {
59  for (lsst::afw::image::Image<Pixel>::const_x_iterator ptr = kImage.row_begin(y);
60  ptr != kImage.row_end(y); ++ptr) {
61  std::cout << boost::format(pixelFmt) % *ptr << " ";
62  }
63  std::cout << std::endl;
64  }
65 
66  if (doNormalize && std::abs(static_cast<double>(kSum) - 1.0) > 1.0e-5) {
67  std::cout << boost::format("Warning! Sum of all pixels = %9.5f != 1.0\n") % kSum;
68  }
69  std::cout << std::endl;
70 }
int y
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
Definition: Image.h:157