LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Files | Namespaces | Classes | Functions
LSST framework

Files

file  Coord.h
 Functions to handle coordinates.
 
file  Observatory.h
 Class to hold observatory information.
 
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  CudaMemory.h
 Functions and a class to help allocating GPU global memory and transferring data to and from a GPU.
 
file  CudaQueryDevice.h
 Functions to query the properties of currently selected GPU device.
 
file  CudaSelectGpu.h
 Functions to help managing setup for GPU kernels.
 
file  GpuBuffer2D.h
 contains GpuBuffer2D class (for simple handling of images or 2D arrays)
 
file  DevicePreference.h
 Interface for CPU/GPU device selection.
 
file  GpuExceptions.h
 additional GPU exceptions
 
file  IsGpuBuild.h
 A function to determine whether compiling for GPU is enabled.
 
file  ImageSlice.h
 Define a single column or row of an Image.
 
file  ConvolveImage.h
 Convolve and convolveAtAPoint functions for Image and Kernel.
 
file  ConvCpuGpuShared.h
 CPU and GPU convolution shared code.
 
file  convCUDA.h
 GPU convolution code.
 
file  Convolve.h
 Convolution support.
 
file  ConvolveGPU.h
 Convolution support.
 
file  cudaConvWrapper.h
 Set up for convolution, calls GPU convolution kernels.
 
file  CudaLanczos.h
 Declaration of a GPU kernel for image warping and declarations of requred datatypes.
 
file  CudaLanczosWrapper.h
 GPU accelerared image warping.
 
file  PositionFunctor.h
 GPU accelerared 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.
 
file  Coord.cc
 Provide functions to handle coordinates.
 
file  Observatory.cc
 Provide functions to handle dates.
 
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  CudaMemory.cc
 Functions to help managing setup for GPU kernels.
 
file  CudaQueryDevice.cc
 Functions to query the properties of currently selected GPU device.
 
file  CudartClose.cc
 Calls cudaThreadExit from a destructor of a global object.
 
file  CudaSelectGpu.cc
 Functions for simplifying selecting GPU device, implementation file.
 
file  DevicePreference.cc
 Implementation file for CPU/GPU device selection.
 
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  BasicConvolveGPU.cc
 Definition of basicConvolveGPU, convolveLinearCombinationGPU and convolveSpatiallyInvariantGPU functions declared in ConvolveGPU.h.
 
file  convCpuGpuShared.cc
 Contains AssertDimensionsOK function.
 
file  ConvolveWithInterpolation.cc
 Definition of convolveWithInterpolation and helper functions declared in detail/ConvolveImage.h.
 
file  cudaConvWrapper.cc
 Set up for convolution, calls GPU convolution kernels.
 
file  cudaLanczosWrapper.cc
 GPU image warping implementation.
 
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.
 

Namespaces

 lsst
 < multiple inclusion guard macro
 

Classes

class  lsst.afw.gpu::detail::GpuBuffer2D< PixelT >
 Class for representing an image or 2D array in general) More...
 
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
 
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 >
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...
 
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. (If the kernel is not spatially varying then only compute it once). 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...
 

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
lsst::afw::gpu::GpuMemoryErrorwhen allocation or transfer to/from GPU memory fails
lsst::afw::gpu::GpuRuntimeErrorwhen GPU code run fails
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 159 of file BasicConvolve.cc.

164 {
165  // Because convolve isn't a method of Kernel we can't always use Kernel's vtbl to dynamically
166  // dispatch the correct version of basicConvolve. The case that fails is convolving with a kernel
167  // obtained from a pointer or reference to a Kernel (base class), e.g. as used in LinearCombinationKernel.
169  pexLog::TTrace<4>("lsst.afw.math.convolve",
170  "generic basicConvolve: dispatch to DeltaFunctionKernel basicConvolve");
171  mathDetail::basicConvolve(convolvedImage, inImage,
172  *dynamic_cast<afwMath::DeltaFunctionKernel const*>(&kernel),
173  convolutionControl);
174  return;
175  } else if (IS_INSTANCE(kernel, afwMath::SeparableKernel)) {
176  pexLog::TTrace<4>("lsst.afw.math.convolve",
177  "generic basicConvolve: dispatch to SeparableKernel basicConvolve");
178  mathDetail::basicConvolve(convolvedImage, inImage,
179  *dynamic_cast<afwMath::SeparableKernel const*>(&kernel),
180  convolutionControl);
181  return;
182  } else if (IS_INSTANCE(kernel, afwMath::LinearCombinationKernel) && kernel.isSpatiallyVarying()) {
183  pexLog::TTrace<4>("lsst.afw.math.convolve",
184  "generic basicConvolve: dispatch to spatially varying LinearCombinationKernel basicConvolve");
185  mathDetail::basicConvolve(convolvedImage, inImage,
186  *dynamic_cast<afwMath::LinearCombinationKernel const*>(&kernel),
187  convolutionControl);
188  return;
189  }
190  // OK, use general (and slower) form
191  if (kernel.isSpatiallyVarying() && (convolutionControl.getMaxInterpolationDistance() > 1)) {
192  // use linear interpolation
193  pexLog::TTrace<3>("lsst.afw.math.convolve", "generic basicConvolve: using linear interpolation");
194  mathDetail::convolveWithInterpolation(convolvedImage, inImage, kernel, convolutionControl);
195 
196  } else {
197  // use brute force
198  pexLog::TTrace<3>("lsst.afw.math.convolve", "generic basicConvolve: using brute force");
199  mathDetail::convolveWithBruteForce(convolvedImage, inImage, kernel,convolutionControl);
200  }
201 }
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:986
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...
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:814
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:48
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:744
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.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorwhen GPU acceleration forced
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 211 of file BasicConvolve.cc.

216 {
217  assert (!kernel.isSpatiallyVarying());
218  assertDimensionsOK(convolvedImage, inImage, kernel);
219 
220  CheckForceGpuOnUnsupportedKernel(convolutionControl);
221 
222  int const mImageWidth = inImage.getWidth(); // size of input region
223  int const mImageHeight = inImage.getHeight();
224  int const cnvWidth = mImageWidth + 1 - kernel.getWidth();
225  int const cnvHeight = mImageHeight + 1 - kernel.getHeight();
226  int const cnvStartX = kernel.getCtrX();
227  int const cnvStartY = kernel.getCtrY();
228  int const inStartX = kernel.getPixel().getX();
229  int const inStartY = kernel.getPixel().getY();
230 
231  pexLog::TTrace<3>("lsst.afw.math.convolve", "DeltaFunctionKernel basicConvolve");
232 
233  for (int i = 0; i < cnvHeight; ++i) {
234  typename InImageT::x_iterator inPtr = inImage.x_at(inStartX, i + inStartY);
235  for (typename OutImageT::x_iterator cnvPtr = convolvedImage.x_at(cnvStartX, i + cnvStartY),
236  cnvEnd = cnvPtr + cnvWidth; cnvPtr != cnvEnd; ++cnvPtr, ++inPtr){
237  *cnvPtr = *inPtr;
238  }
239  }
240 }
void assertDimensionsOK(OutImageT const &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel)
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
lsst::afw::gpu::GpuMemoryErrorwhen allocation or transfer to/from GPU memory fails
lsst::afw::gpu::GpuRuntimeErrorwhen GPU code run fails
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 261 of file BasicConvolve.cc.

266 {
267  if (!kernel.isSpatiallyVarying()) {
268  // use the standard algorithm for the spatially invariant case
269  pexLog::TTrace<3>("lsst.afw.math.convolve",
270  "basicConvolve for LinearCombinationKernel: spatially invariant; using brute force");
271  return mathDetail::convolveWithBruteForce(convolvedImage, inImage, kernel,
272  convolutionControl.getDoNormalize());
273  } else {
274  CheckForceGpuOnNoGpu(convolutionControl);
276  if (convolutionControl.getDevicePreference() == lsst::afw::gpu::AUTO_WITH_CPU_FALLBACK) {
277  try {
279  mathDetail::convolveLinearCombinationGPU(convolvedImage,inImage,kernel,
280  convolutionControl);
281  if (rc == mathDetail::ConvolveGpuStatus::OK) return;
282  } catch(lsst::afw::gpu::GpuMemoryError) { }
283  catch(pexExcept::MemoryError) { }
284  catch(lsst::afw::gpu::GpuRuntimeError) { }
285  } else if (convolutionControl.getDevicePreference() != lsst::afw::gpu::USE_CPU) {
287  mathDetail::convolveLinearCombinationGPU(convolvedImage,inImage,kernel,
288  convolutionControl);
289  if (rc == mathDetail::ConvolveGpuStatus::OK) return;
290  if (convolutionControl.getDevicePreference() == lsst::afw::gpu::USE_GPU) {
291  throw LSST_EXCEPT(pexExcept::RuntimeError, "Gpu will not process this kernel");
292  }
293  }
294  }
295 
296  // refactor the kernel if this is reasonable and possible;
297  // then use the standard algorithm for the spatially varying case
298  PTR(afwMath::Kernel) refKernelPtr; // possibly refactored version of kernel
299  if (static_cast<int>(kernel.getNKernelParameters()) > kernel.getNSpatialParameters()) {
300  // refactoring will speed convolution, so try it
301  refKernelPtr = kernel.refactor();
302  if (!refKernelPtr) {
303  refKernelPtr = kernel.clone();
304  }
305  } else {
306  // too few basis kernels for refactoring to be worthwhile
307  refKernelPtr = kernel.clone();
308  }
309  if (convolutionControl.getMaxInterpolationDistance() > 1) {
310  pexLog::TTrace<3>("lsst.afw.math.convolve",
311  "basicConvolve for LinearCombinationKernel: using interpolation");
312  return mathDetail::convolveWithInterpolation(convolvedImage, inImage, *refKernelPtr, convolutionControl);
313  } else {
314  pexLog::TTrace<3>("lsst.afw.math.convolve",
315  "basicConvolve for LinearCombinationKernel: maxInterpolationError < 0; using brute force");
316  return mathDetail::convolveWithBruteForce(convolvedImage, inImage, *refKernelPtr,
317  convolutionControl.getDoNormalize());
318  }
319  }
320 }
bool isGpuEnabled()
returns true if GPU acceleration is enabled
ConvolveGpuStatus::ReturnCode convolveLinearCombinationGPU(lsst::afw::image::MaskedImage< OutPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > &convolvedImage, lsst::afw::image::MaskedImage< InPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > const &inImage, lsst::afw::math::LinearCombinationKernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
#define PTR(...)
Definition: base.h:41
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...
virtual boost::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
bool isGpuBuild()
Inline function which returns true only when GPU_BUILD macro is defined.
Definition: IsGpuBuild.h:45
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.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
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.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorwhen GPU acceleration forced
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 330 of file BasicConvolve.cc.

335 {
336  typedef typename afwMath::Kernel::Pixel KernelPixel;
337  typedef typename std::vector<KernelPixel> KernelVector;
338  typedef KernelVector::const_iterator KernelIterator;
339  typedef typename InImageT::const_x_iterator InXIterator;
340  typedef typename InImageT::const_xy_locator InXYLocator;
341  typedef typename OutImageT::x_iterator OutXIterator;
342  typedef typename OutImageT::y_iterator OutYIterator;
343  typedef typename OutImageT::SinglePixel OutPixel;
344 
345  assertDimensionsOK(convolvedImage, inImage, kernel);
346 
347  CheckForceGpuOnUnsupportedKernel(convolutionControl);
348 
349  afwGeom::Box2I const fullBBox = inImage.getBBox(image::LOCAL);
350  afwGeom::Box2I const goodBBox = kernel.shrinkBBox(fullBBox);
351 
352  KernelVector kernelXVec(kernel.getWidth());
353  KernelVector kernelYVec(kernel.getHeight());
354 
355  if (kernel.isSpatiallyVarying()) {
356  pexLog::TTrace<3>("lsst.afw.math.convolve",
357  "SeparableKernel basicConvolve: kernel is spatially varying");
358 
359  for (int cnvY = goodBBox.getMinY(); cnvY <= goodBBox.getMaxY(); ++cnvY) {
360  double const rowPos = inImage.indexToPosition(cnvY, afwImage::Y);
361 
362  InXYLocator inImLoc = inImage.xy_at(0, cnvY - goodBBox.getMinY());
363  OutXIterator cnvXIter = convolvedImage.row_begin(cnvY) + goodBBox.getMinX();
364  for (int cnvX = goodBBox.getMinX(); cnvX <= goodBBox.getMaxX();
365  ++cnvX, ++inImLoc.x(), ++cnvXIter) {
366  double const colPos = inImage.indexToPosition(cnvX, afwImage::X);
367 
368  KernelPixel kSum = kernel.computeVectors(kernelXVec, kernelYVec,
369  convolutionControl.getDoNormalize(), colPos, rowPos);
370 
371  // why does this trigger warnings? It did not in the past.
372  *cnvXIter = afwMath::convolveAtAPoint<OutImageT, InImageT>(inImLoc, kernelXVec, kernelYVec);
373  if (convolutionControl.getDoNormalize()) {
374  *cnvXIter = *cnvXIter/kSum;
375  }
376  }
377  }
378  } else {
379  // kernel is spatially invariant
380  // The basic sequence:
381  // - For each output row:
382  // - Compute x-convolved data: a kernel height's strip of input image convolved with kernel x vector
383  // - Compute one row of output by dotting each column of x-convolved data with the kernel y vector
384  // The x-convolved data is stored in a kernel-height by good-width buffer.
385  // This is circular buffer along y (to avoid shifting pixels before setting each new row);
386  // so for each new row the kernel y vector is rotated to match the order of the x-convolved data.
387 
388  pexLog::TTrace<3>("lsst.afw.math.convolve",
389  "SeparableKernel basicConvolve: kernel is spatially invariant");
390 
391  kernel.computeVectors(kernelXVec, kernelYVec, convolutionControl.getDoNormalize());
392  KernelIterator const kernelXVecBegin = kernelXVec.begin();
393  KernelIterator const kernelYVecBegin = kernelYVec.begin();
394 
395  // buffer for x-convolved data
396  OutImageT buffer(afwGeom::Extent2I(goodBBox.getWidth(), kernel.getHeight()));
397 
398  // pre-fill x-convolved data buffer with all but one row of data
399  int yInd = 0; // during initial fill bufY = inImageY
400  int const yPrefillEnd = buffer.getHeight() - 1;
401  for (; yInd < yPrefillEnd; ++yInd) {
402  OutXIterator bufXIter = buffer.x_at(0, yInd);
403  OutXIterator const bufXEnd = buffer.x_at(goodBBox.getWidth(), yInd);
404  InXIterator inXIter = inImage.x_at(0, yInd);
405  for ( ; bufXIter != bufXEnd; ++bufXIter, ++inXIter) {
406  *bufXIter = kernelDotProduct<OutPixel, InXIterator, KernelIterator, KernelPixel>(
407  inXIter, kernelXVecBegin, kernel.getWidth());
408  }
409  }
410 
411  // compute output pixels using the sequence described above
412  int inY = yPrefillEnd;
413  int bufY = yPrefillEnd;
414  int cnvY = goodBBox.getMinY();
415  while (true) {
416  // fill next buffer row and compute output row
417  InXIterator inXIter = inImage.x_at(0, inY);
418  OutXIterator bufXIter = buffer.x_at(0, bufY);
419  OutXIterator cnvXIter = convolvedImage.x_at(goodBBox.getMinX(), cnvY);
420  for (int bufX = 0; bufX < goodBBox.getWidth(); ++bufX, ++cnvXIter, ++bufXIter, ++inXIter) {
421  // note: bufXIter points to the row of the buffer that is being updated,
422  // whereas bufYIter points to row 0 of the buffer
423  *bufXIter = kernelDotProduct<OutPixel, InXIterator, KernelIterator, KernelPixel>(
424  inXIter, kernelXVecBegin, kernel.getWidth());
425 
426  OutYIterator bufYIter = buffer.y_at(bufX, 0);
427  *cnvXIter = kernelDotProduct<OutPixel, OutYIterator, KernelIterator, KernelPixel>(
428  bufYIter, kernelYVecBegin, kernel.getHeight());
429  }
430 
431  // test for done now, instead of the start of the loop,
432  // to avoid an unnecessary extra rotation of the kernel Y vector
433  if (cnvY >= goodBBox.getMaxY()) break;
434 
435  // update y indices, including bufY, and rotate the kernel y vector to match
436  ++inY;
437  bufY = (bufY + 1) % kernel.getHeight();
438  ++cnvY;
439  std::rotate(kernelYVec.begin(), kernelYVec.end()-1, kernelYVec.end());
440  }
441  }
442 }
int getMinY() const
Definition: Box.h:125
int getMaxX() const
Definition: Box.h:128
An integer coordinate rectangle.
Definition: Box.h:53
int getMaxY() const
Definition: Box.h:129
int getMinX() const
Definition: Box.h:124
void assertDimensionsOK(OutImageT const &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel)
int getWidth() const
Definition: Box.h:154
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.

Note
This function is able to use GPU acceleration (for spatially invariant kernels and for LinearCombinationKernel). There is a limit on maximum kernel size, but kernels sized at most 17x17 should be accelerated on all supported GPU hardware (SM 1.3 and better). SM 2.x can accelerate kernels sized up to 22x22.
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
lsst::afw::gpu::GpuMemoryErrorwhen allocation or transfer to/from GPU memory fails
lsst::afw::gpu::GpuRuntimeErrorwhen GPU code run fails
Parameters
convolvedImageconvolved image; must be the same size as inImage
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 328 of file ConvolveImage.cc.

333 {
334  mathDetail::basicConvolve(convolvedImage, inImage, kernel, convolutionControl);
335  setEdgePixels(convolvedImage, kernel, inImage, convolutionControl.getDoCopyEdge(),
337  );
338  convolvedImage.setXY0(inImage.getXY0());
339 }
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:79
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 186 of file ConvolveImage.h.

193 {
194  typename OutImageT::SinglePixel outValue = 0;
195  for (int kRow = 0; kRow != kHeight; ++kRow) {
197  kernelLocator + lsst::afw::image::detail::difference_type(kWidth, 0);
198  kernelLocator != kEnd; ++inImageLocator.x(), ++kernelLocator.x()) {
199  typename lsst::afw::math::Kernel::Pixel const kVal = kernelLocator[0];
200  if (kVal != 0) {
201  outValue += *inImageLocator*kVal;
202  }
203  }
204 
205  inImageLocator += lsst::afw::image::detail::difference_type(-kWidth, 1);
206  kernelLocator += lsst::afw::image::detail::difference_type(-kWidth, 1);
207  }
208 
209  return outValue;
210 }
_view_t::xy_locator::const_t const_xy_locator
A const_xy_locator.
Definition: Image.h:141
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 222 of file ConvolveImage.h.

227 {
228  typedef typename std::vector<lsst::afw::math::Kernel::Pixel>::const_iterator k_iter;
229 
230  typedef typename OutImageT::SinglePixel OutT;
231  OutT outValue = 0;
232  for (k_iter kernelYIter = kernelYList.begin(), yEnd = kernelYList.end();
233  kernelYIter != yEnd; ++kernelYIter) {
234 
235  OutT outValueY = 0;
236  for (k_iter kernelXIter = kernelXList.begin(), xEnd = kernelXList.end();
237  kernelXIter != xEnd; ++kernelXIter, ++inImageLocator.x()) {
238  typename lsst::afw::math::Kernel::Pixel const kValX = *kernelXIter;
239  if (kValX != 0) {
240  outValueY += *inImageLocator*kValX;
241  }
242  }
243 
244  double const kValY = *kernelYIter;
245  if (kValY != 0) {
246  outValue += outValueY*kValY;
247  }
248 
249  inImageLocator += lsst::afw::image::detail::difference_type(-kernelXList.size(), 1);
250  }
251 
252  return outValue;
253 }
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::InvalidParameterErrorwhen GPU acceleration forced on spatially varying kernel
lsst::pex::exceptions::MemoryErrorwhen allocation of CPU memory fails
lsst::afw::gpu::GpuMemoryErrorwhen allocation or transfer to/from GPU memory fails
lsst::afw::gpu::GpuRuntimeErrorwhen GPU code run fails
Parameters
convolvedImageconvolved image
inImageimage to convolve
kernelconvolution kernel
convolutionControlconvolution control parameters

Definition at line 468 of file BasicConvolve.cc.

473 {
474  bool doNormalize=convolutionControl.getDoNormalize();
475 
476  typedef typename afwMath::Kernel::Pixel KernelPixel;
477  typedef afwImage::Image<KernelPixel> KernelImage;
478 
479  typedef typename KernelImage::const_x_iterator KernelXIterator;
480  typedef typename KernelImage::const_xy_locator KernelXYLocator;
481  typedef typename InImageT::const_x_iterator InXIterator;
482  typedef typename InImageT::const_xy_locator InXYLocator;
483  typedef typename OutImageT::x_iterator OutXIterator;
484  typedef typename OutImageT::SinglePixel OutPixel;
485 
486  assertDimensionsOK(convolvedImage, inImage, kernel);
487 
488  int const inImageWidth = inImage.getWidth();
489  int const inImageHeight = inImage.getHeight();
490  int const kWidth = kernel.getWidth();
491  int const kHeight = kernel.getHeight();
492  int const cnvWidth = inImageWidth + 1 - kernel.getWidth();
493  int const cnvHeight = inImageHeight + 1 - kernel.getHeight();
494  int const cnvStartX = kernel.getCtrX();
495  int const cnvStartY = kernel.getCtrY();
496  int const cnvEndX = cnvStartX + cnvWidth; // end index + 1
497  int const cnvEndY = cnvStartY + cnvHeight; // end index + 1
498 
499  KernelImage kernelImage(kernel.getDimensions());
500  KernelXYLocator const kernelLoc = kernelImage.xy_at(0,0);
501 
502  if (kernel.isSpatiallyVarying()) {
503  pexLog::TTrace<5>("lsst.afw.math.convolve",
504  "convolveWithBruteForce: kernel is spatially varying");
505 
506  CheckForceGpuOnUnsupportedKernel(convolutionControl);
507 
508  for (int cnvY = cnvStartY; cnvY != cnvEndY; ++cnvY) {
509  double const rowPos = inImage.indexToPosition(cnvY, afwImage::Y);
510 
511  InXYLocator inImLoc = inImage.xy_at(0, cnvY - cnvStartY);
512  OutXIterator cnvXIter = convolvedImage.x_at(cnvStartX, cnvY);
513  for (int cnvX = cnvStartX; cnvX != cnvEndX; ++cnvX, ++inImLoc.x(), ++cnvXIter) {
514  double const colPos = inImage.indexToPosition(cnvX, afwImage::X);
515 
516  KernelPixel kSum = kernel.computeImage(kernelImage, false, colPos, rowPos);
517  *cnvXIter = afwMath::convolveAtAPoint<OutImageT, InImageT>(
518  inImLoc, kernelLoc, kWidth, kHeight);
519  if (doNormalize) {
520  *cnvXIter = *cnvXIter/kSum;
521  }
522  }
523  }
524  } else {
525  pexLog::TTrace<5>("lsst.afw.math.convolve",
526  "convolveWithBruteForce: kernel is spatially invariant");
527 
528  CheckForceGpuOnNoGpu(convolutionControl);
530  if (convolutionControl.getDevicePreference() == lsst::afw::gpu::AUTO_WITH_CPU_FALLBACK) {
531  try {
533  mathDetail::convolveSpatiallyInvariantGPU(convolvedImage,inImage,kernel,
534  convolutionControl);
535  if (rc == mathDetail::ConvolveGpuStatus::OK) return;
536  } catch(lsst::afw::gpu::GpuMemoryError) { }
537  catch(pexExcept::MemoryError) { }
538  catch(lsst::afw::gpu::GpuRuntimeError) { }
539  } else if (convolutionControl.getDevicePreference() != lsst::afw::gpu::USE_CPU) {
541  mathDetail::convolveSpatiallyInvariantGPU(convolvedImage,inImage,kernel,
542  convolutionControl);
543  if (rc == mathDetail::ConvolveGpuStatus::OK) return;
544  if (convolutionControl.getDevicePreference() == lsst::afw::gpu::USE_GPU) {
545  throw LSST_EXCEPT(pexExcept::RuntimeError, "Gpu will not process this kernel");
546  }
547  }
548  }
549 
550  (void)kernel.computeImage(kernelImage, doNormalize);
551 
552  for (int inStartY = 0, cnvY = cnvStartY; inStartY < cnvHeight; ++inStartY, ++cnvY) {
553  KernelXIterator kernelXIter = kernelImage.x_at(0, 0);
554  InXIterator inXIter = inImage.x_at(0, inStartY);
555  OutXIterator cnvXIter = convolvedImage.x_at(cnvStartX, cnvY);
556  for (int x = 0; x < cnvWidth; ++x, ++cnvXIter, ++inXIter) {
557  *cnvXIter = kernelDotProduct<OutPixel, InXIterator, KernelXIterator, KernelPixel>(
558  inXIter, kernelXIter, kWidth);
559  }
560  for (int kernelY = 1, inY = inStartY + 1; kernelY < kHeight; ++inY, ++kernelY) {
561  KernelXIterator kernelXIter = kernelImage.x_at(0, kernelY);
562  InXIterator inXIter = inImage.x_at(0, inY);
563  OutXIterator cnvXIter = convolvedImage.x_at(cnvStartX, cnvY);
564  for (int x = 0; x < cnvWidth; ++x, ++cnvXIter, ++inXIter) {
565  *cnvXIter += kernelDotProduct<OutPixel, InXIterator, KernelXIterator, KernelPixel>(
566  inXIter, kernelXIter, kWidth);
567  }
568  }
569  }
570  }
571 }
bool isGpuEnabled()
returns true if GPU acceleration is enabled
ConvolveGpuStatus::ReturnCode convolveSpatiallyInvariantGPU(lsst::afw::image::MaskedImage< OutPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > &convolvedImage, lsst::afw::image::MaskedImage< InPixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
bool isGpuBuild()
Inline function which returns true only when GPU_BUILD macro is defined.
Definition: IsGpuBuild.h:45
int x
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void assertDimensionsOK(OutImageT const &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel)
A class to represent a 2-dimensional array of pixels.
Definition: PSF.h:43
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:158