38 #include "lsst/pex/exceptions.h"
39 #include "lsst/log/Log.h"
45 namespace pexExcept = lsst::pex::exceptions;
65 template <
typename OutImageT,
typename InImageT>
66 inline void setEdgePixels(OutImageT& outImage, Kernel
const& kernel, InImageT
const& inImage,
bool doCopyEdge,
67 image::detail::Image_tag) {
68 const unsigned int imWidth = outImage.getWidth();
69 const unsigned int imHeight = outImage.getHeight();
70 const unsigned int kWidth = kernel.getWidth();
71 const unsigned int kHeight = kernel.getHeight();
72 const unsigned int kCtrX = kernel.getCtrX();
73 const unsigned int kCtrY = kernel.getCtrY();
75 const typename OutImageT::SinglePixel
edgePixel =
77 std::vector<geom::Box2I> bboxList;
82 int const numHeight = kHeight - (1 + kCtrY);
83 int const numWidth = kWidth - (1 + kCtrX);
88 bboxList.push_back(geom::Box2I(
geom::Point2I(imWidth - numWidth, kCtrY),
91 for (std::vector<geom::Box2I>::const_iterator bboxIter = bboxList.begin(); bboxIter != bboxList.end();
97 outView.assign(OutImageT(InImageT(inImage, *bboxIter,
image::LOCAL),
true));
116 template <
typename OutImageT,
typename InImageT>
117 inline void setEdgePixels(OutImageT& outImage, Kernel
const& kernel, InImageT
const& inImage,
bool doCopyEdge,
118 image::detail::MaskedImage_tag) {
119 const unsigned int imWidth = outImage.getWidth();
120 const unsigned int imHeight = outImage.getHeight();
121 const unsigned int kWidth = kernel.getWidth();
122 const unsigned int kHeight = kernel.getHeight();
123 const unsigned int kCtrX = kernel.getCtrX();
124 const unsigned int kCtrY = kernel.getCtrY();
126 const typename OutImageT::SinglePixel edgePixel =
128 std::vector<geom::Box2I> bboxList;
133 int const numHeight = kHeight - (1 + kCtrY);
134 int const numWidth = kWidth - (1 + kCtrX);
139 bboxList.push_back(geom::Box2I(
geom::Point2I(imWidth - numWidth, kCtrY),
143 for (std::vector<geom::Box2I>::const_iterator bboxIter = bboxList.begin(); bboxIter != bboxList.end();
149 outView.assign(OutImageT(InImageT(inImage, *bboxIter,
image::LOCAL),
true));
150 *(outView.getMask()) |= edgeMask;
159 template <
typename OutImageT,
typename InImageT>
160 void scaledPlus(OutImageT& outImage,
double c1, InImageT
const& inImage1,
double c2,
161 InImageT
const& inImage2) {
162 if (outImage.getDimensions() != inImage1.getDimensions()) {
163 std::ostringstream os;
164 os <<
"outImage dimensions = ( " << outImage.getWidth() <<
", " << outImage.getHeight() <<
") != ("
165 << inImage1.getWidth() <<
", " << inImage1.getHeight() <<
") = inImage1 dimensions";
166 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
167 }
else if (inImage1.getDimensions() != inImage2.getDimensions()) {
168 std::ostringstream os;
169 os <<
"inImage1 dimensions = ( " << inImage1.getWidth() <<
", " << inImage1.getHeight() <<
") != ("
170 << inImage2.getWidth() <<
", " << inImage2.getHeight() <<
") = inImage2 dimensions";
171 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
174 typedef typename InImageT::const_x_iterator InConstXIter;
175 typedef typename OutImageT::x_iterator OutXIter;
176 for (
int y = 0; y != inImage1.getHeight(); ++y) {
177 InConstXIter
const end1 = inImage1.row_end(y);
178 InConstXIter inIter1 = inImage1.row_begin(y);
179 InConstXIter inIter2 = inImage2.row_begin(y);
180 OutXIter outIter = outImage.row_begin(y);
181 for (; inIter1 != end1; ++inIter1, ++inIter2, ++outIter) {
182 *outIter = (*inIter1 * c1) + (*inIter2 * c2);
187 template <
typename OutImageT,
typename InImageT,
typename KernelT>
188 void convolve(OutImageT& convolvedImage, InImageT
const& inImage, KernelT
const& kernel,
191 setEdgePixels(convolvedImage, kernel, inImage, convolutionControl.
getDoCopyEdge(),
193 convolvedImage.setXY0(inImage.getXY0());
196 template <
typename OutImageT,
typename InImageT,
typename KernelT>
197 void convolve(OutImageT& convolvedImage, InImageT
const& inImage, KernelT
const& kernel,
bool doNormalize,
202 convolve(convolvedImage, inImage, kernel, convolutionControl);
212 #define IMAGE(PIXTYPE) image::Image<PIXTYPE>
213 #define MASKEDIMAGE(PIXTYPE) image::MaskedImage<PIXTYPE, image::MaskPixel, image::VariancePixel>
227 #define INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, INPIXTYPE, KERNELTYPE) \
228 template void convolve(IMGMACRO(OUTPIXTYPE)&, IMGMACRO(INPIXTYPE) const&, KERNELTYPE const&, bool, \
230 NL template void convolve(IMGMACRO(OUTPIXTYPE)&, IMGMACRO(INPIXTYPE) const&, KERNELTYPE const&, \
231 ConvolutionControl const&); \
238 #define INSTANTIATE_IM_OR_MI(IMGMACRO, OUTPIXTYPE, INPIXTYPE) \
239 template void scaledPlus(IMGMACRO(OUTPIXTYPE)&, double, IMGMACRO(INPIXTYPE) const&, double, \
240 IMGMACRO(INPIXTYPE) const&); \
241 NL INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, INPIXTYPE, \
242 AnalyticKernel) INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, \
244 DeltaFunctionKernel) \
245 INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, INPIXTYPE, FixedKernel) \
246 INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, INPIXTYPE, LinearCombinationKernel) \
247 INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, INPIXTYPE, SeparableKernel) \
248 INSTANTIATE_IM_OR_MI_KERNEL(IMGMACRO, OUTPIXTYPE, INPIXTYPE, Kernel) //
251 #define INSTANTIATE(OUTPIXTYPE, INPIXTYPE) \
252 INSTANTIATE_IM_OR_MI(IMAGE, OUTPIXTYPE, INPIXTYPE) \
253 INSTANTIATE_IM_OR_MI(MASKEDIMAGE, OUTPIXTYPE, INPIXTYPE)
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
Compute the scaled sum of two images.
Parameters to control convolution.
void setDoCopyEdge(bool doCopyEdge)
Extent< int, 2 > Extent2I
void setDoNormalize(bool doNormalize)
ImageT::SinglePixel edgePixel(lsst::afw::image::detail::Image_tag)
Return an off-the-edge pixel appropriate for a given Image type.
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR'd together.
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...
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
ImageT::image_category image_category
bool getDoCopyEdge() const
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.
#define INSTANTIATE(FROMSYS, TOSYS)