51 template <
typename PixelT>
53 template <
typename PixelT>
55 template <
typename PixelT>
57 template <
typename PixelT>
64 T operator()(T x)
const {
return x; }
69 andMask(T mask) : _mask(mask) {}
70 T operator()(T x)
const {
return (x & _mask); }
76 andMask<T> makeAndMask(T
val) {
77 return andMask<T>(
val);
83 template<
typename LhsT,
typename RhsT>
90 std::make_shared<afwImage::Image<LhsT> >(rhs.
getDimensions());
93 for (
int y = 0;
y != lhs->getHeight(); ++
y) {
97 lhsEnd = lhs->row_end(y); lhsPtr != lhsEnd; ++rhsPtr, ++lhsPtr) {
98 *lhsPtr = func(*rhsPtr);
114 template <
typename MaskT>
115 class BlendedFunctor {
131 int x = point.getX();
132 int y = point.getY();
133 double const central = distanceSquared(x, y, _central);
135 iter !=
end; ++iter) {
136 double const dist2 = distanceSquared(x, y, *iter);
137 if (dist2 < central) {
172 template <
typename PixelT>
179 afwImage::positionToIndex(getYCenter()));
181 cen[1] - height/2 - _parentExposure->getY0());
187 MaskedImageT mimg = _parentExposure->getMaskedImage();
188 image.reset(
new MaskedImageT(mimg,
bbox, afwImage::LOCAL,
true));
201 if (getMaskBlends()) {
204 PeakCatalog
const& peaks = foot->getPeaks();
205 if (peaks.size() > 1) {
209 for (PeakCatalog::const_iterator iter = peaks.begin(),
end = peaks.end(); iter !=
end; ++iter) {
210 double const dist2 = distanceSquared(getXCenter(), getYCenter(), *iter);
218 PeakCatalog others(peaks.getTable());
219 others.reserve(peaks.size() - 1);
220 for (PeakCatalog::const_iterator iter = peaks.begin(),
end = peaks.end(); iter !=
end; ++iter) {
222 if (central != ptr) {
223 others.push_back(ptr);
227 BlendedFunctor<typename MaskedImageT::Mask::Pixel> functor(*central, others, detected, intrp);
228 foot->getSpans()->clippedTo(
image->getBBox())->applyFunctor(functor, *
image->getMask());
241 CONST_PTR(FootprintList) feet = fs->getFootprints();
243 if (feet->size() > 1) {
248 for (FootprintList::const_iterator fiter = feet->begin(); fiter != feet->end(); ++fiter) {
250 if (foot->contains(cen)) {
255 auto bigSpan = foot->getSpans()->dilated(ngrow)->clippedTo(
image->getBBox());
256 bigSpan->clearMask(*
image->getMask(), detected);
257 bigSpan->setMask(*
image->getMask(), intrp);
262 if (_pixelThreshold > 0.0) {
264 std::make_shared<afwDetection::FootprintSet>(*
image,
266 for (FootprintList::const_iterator fpIter = fpSet->getFootprints()->begin();
267 fpIter != fpSet->getFootprints()->end(); ++fpIter) {
269 if (!fp->contains(cen)) {
270 fp->getSpans()->clearMask(*image->getMask(), detected);
271 fp->getSpans()->setMask(*image->getMask(), intrp);
285 template <
typename PixelT>
288 if (!_image || (width != _image->getWidth() || height != _image->getHeight())) {
289 _image = extractImage(width, height);
299 template <
typename PixelT>
301 int const width = getWidth() == 0 ? _defaultWidth : getWidth();
302 int const height = getHeight() == 0 ? _defaultWidth : getHeight();
303 return getMaskedImage(width, height);
306 template <
typename PixelT>
311 template <
typename PixelT>
316 template <
typename PixelT>
318 _pixelThreshold = threshold;
321 template <
typename PixelT>
323 return _pixelThreshold;
326 template <
typename PixelT>
328 _doMaskBlends = doMaskBlends;
331 template <
typename PixelT>
333 return _doMaskBlends;
341 template <
typename PixelT>
344 std::
string const algorithm,
347 unsigned int const width = getWidth() == 0 ? _defaultWidth : getWidth();
348 unsigned int const height = getHeight() == 0 ? _defaultWidth : getHeight();
349 if (_offsetImage && static_cast<unsigned int>(_offsetImage->getWidth()) == width + 2*buffer &&
350 static_cast<unsigned int>(_offsetImage->getHeight()) == height + 2*buffer) {
354 PTR(
MaskedImageT) image = extractImage(width + 2*buffer, height + 2*buffer);
356 double const xcen = getXCenter(), ycen = getYCenter();
357 double const dx = afwImage::positionToIndex(xcen,
true).second;
358 double const dy = afwImage::positionToIndex(ycen,
true).second;
360 PTR(
MaskedImageT) offset = afwMath::offsetImage(*image, -dx, -dy, algorithm);
364 _offsetImage.reset(
new MaskedImageT(*offset, box, afwImage::LOCAL,
true));
static void setMaskBlends(bool doMaskBlends)
Set whether blends are masked.
boost::shared_ptr< afw::image::MaskedImage< PixelT > const > getMaskedImage() const
Return the image at the position of the Source, without any sub-pixel shifts to put the centre of the...
static float getPixelThreshold()
Get threshold for rejecting pixels unconnected with the central footprint.
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
x_iterator row_begin(int y) const
static void setBorderWidth(int border)
Set the number of pixels to ignore around the candidate image's edge.
geom::Extent2I getDimensions() const
afw::table::CatalogT< PeakRecord > PeakCatalog
Class used by SpatialCell for spatial PSF fittig.
static void setPixelThreshold(float threshold)
Set threshold for rejecting pixels unconnected with the central footprint.
static int getBorderWidth()
Return the number of pixels being ignored around the candidate image's edge.
CatalogIterator< typename Internal::const_iterator > const_iterator
static bool getMaskBlends()
Get whether blends are masked.
#define LSST_EXCEPT_ADD(e, m)
Class stored in SpatialCells for spatial Psf fitting.
geom::Point2I getXY0() const