47template <
typename PixelT>
48int PsfCandidate<PixelT>::_border = 0;
49template <
typename PixelT>
50int PsfCandidate<PixelT>::_defaultWidth = 21;
51template <
typename PixelT>
52float PsfCandidate<PixelT>::_pixelThreshold = 0.0;
53template <
typename PixelT>
54bool PsfCandidate<PixelT>::_doMaskBlends =
true;
59struct noop :
public afw::image::pixelOp1<T> {
60 T operator()(T
x)
const {
return x; }
64struct andMask :
public afw::image::pixelOp1<T> {
66 T operator()(T
x)
const {
return (
x & _mask); }
73andMask<T> makeAndMask(T
val) {
74 return andMask<T>(
val);
80template <
typename LhsT,
typename RhsT>
82 afw::image::Mask<RhsT>
const& rhs,
83 afw::image::pixelOp1<RhsT>
const& func = noop<RhsT>()
86 std::make_shared<afw::image::Image<LhsT>>(rhs.getDimensions());
87 lhs->setXY0(rhs.getXY0());
89 for (
int y = 0;
y != lhs->getHeight(); ++
y) {
93 lhsEnd = lhs->row_end(
y);
94 lhsPtr != lhsEnd; ++rhsPtr, ++lhsPtr) {
95 *lhsPtr = func(*rhsPtr);
103double distanceSquared(
double x,
double y, afw::detection::PeakRecord
const& peak) {
111template <
typename MaskT>
112class BlendedFunctor {
114 BlendedFunctor(afw::detection::PeakRecord
const& central,
119 : _central(central), _peaks(peaks), _turnOff(~turnOff), _turnOn(turnOn) {}
123 int x = point.getX();
124 int y = point.getY();
125 double const central = distanceSquared(
x,
y, _central);
128 double const dist2 = distanceSquared(
x,
y, *iter);
129 if (dist2 < central) {
137 afw::detection::PeakRecord
const& _central;
163template <
typename PixelT>
165PsfCandidate<PixelT>::extractImage(
unsigned int width,
170 geom::Point2I const llc(cen[0] - width / 2 - _parentExposure->getX0(),
171 cen[1] - height / 2 - _parentExposure->getY0());
177 MaskedImageT mimg = _parentExposure->getMaskedImage();
179 }
catch (pex::exceptions::LengthError& e) {
188 MaskedImageT::Mask::getPlaneBitMask(
"INTRP");
192 if (getMaskBlends()) {
195 PeakCatalog
const& peaks = foot->getPeaks();
196 if (peaks.size() > 1) {
200 for (PeakCatalog::const_iterator iter = peaks.begin(),
end = peaks.end();
iter !=
end; ++
iter) {
201 double const dist2 = distanceSquared(getXCenter(), getYCenter(), *iter);
209 PeakCatalog others(peaks.getTable());
210 others.reserve(peaks.size() - 1);
211 for (PeakCatalog::const_iterator iter = peaks.begin(),
end = peaks.end();
iter !=
end; ++
iter) {
213 if (central !=
ptr) {
214 others.push_back(
ptr);
218 BlendedFunctor<typename MaskedImageT::Mask::Pixel> functor(*central, others, detected, intrp);
219 foot->getSpans()->clippedTo(
image->getBBox())->applyFunctor(functor, *
image->getMask());
231 fs = std::make_shared<afw::detection::FootprintSet>(*mim, afw::detection::Threshold(1));
234 if (feet->size() > 1) {
239 for (FootprintList::const_iterator fiter = feet->begin(); fiter != feet->end(); ++fiter) {
241 if (foot->contains(cen)) {
246 auto bigSpan = foot->getSpans()->dilated(ngrow)->clippedTo(
image->getBBox());
247 bigSpan->clearMask(*
image->getMask(), detected);
248 bigSpan->setMask(*
image->getMask(), intrp);
253 if (_pixelThreshold > 0.0) {
255 fpSet = std::make_shared<afw::detection::FootprintSet>(
257 for (FootprintList::const_iterator fpIter = fpSet->getFootprints()->begin();
258 fpIter != fpSet->getFootprints()->end(); ++fpIter) {
260 if (!fp->contains(cen)) {
261 fp->getSpans()->clearMask(*
image->getMask(), detected);
262 fp->getSpans()->setMask(*
image->getMask(), intrp);
275template <
typename PixelT>
278 if (!_image || (width != _image->getWidth() || height != _image->getHeight())) {
279 _image = extractImage(width, height);
289template <
typename PixelT>
292 int const width = getWidth() == 0 ? _defaultWidth : getWidth();
293 int const height = getHeight() == 0 ? _defaultWidth : getHeight();
294 return getMaskedImage(width, height);
297template <
typename PixelT>
302template <
typename PixelT>
307template <
typename PixelT>
309 _pixelThreshold = threshold;
312template <
typename PixelT>
314 return _pixelThreshold;
317template <
typename PixelT>
319 _doMaskBlends = doMaskBlends;
322template <
typename PixelT>
324 return _doMaskBlends;
332template <
typename PixelT>
337 unsigned int const width = getWidth() == 0 ? _defaultWidth : getWidth();
338 unsigned int const height = getHeight() == 0 ? _defaultWidth : getHeight();
339 if (_offsetImage &&
static_cast<unsigned int>(_offsetImage->getWidth()) == width + 2 * buffer &&
340 static_cast<unsigned int>(_offsetImage->getHeight()) == height + 2 * buffer) {
346 double const xcen = getXCenter(), ycen = getYCenter();
354 _offsetImage.reset(
new MaskedImageT(*offset, box, afw::image::LOCAL,
true));
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
Class used by SpatialCell for spatial PSF fittig.
@ PIXEL_STDEV
Use number of sigma given per-pixel s.d.
typename _const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
typename _view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
CatalogIterator< typename Internal::const_iterator > const_iterator
An integer coordinate rectangle.
Class stored in SpatialCells for spatial Psf fitting.
static float getPixelThreshold()
Get threshold for rejecting pixels unconnected with the central footprint.
static bool getMaskBlends()
Get whether blends are masked.
static void setBorderWidth(int border)
Set the number of pixels to ignore around the candidate image's edge.
static int getBorderWidth()
Return the number of pixels being ignored around the candidate image's edge.
static void setPixelThreshold(float threshold)
Set threshold for rejecting pixels unconnected with the central footprint.
std::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 void setMaskBlends(bool doMaskBlends)
Set whether blends are masked.
std::shared_ptr< afw::image::MaskedImage< PixelT > > getOffsetImage(std::string const algorithm, unsigned int buffer) const
Return an offset version of the image of the source.
afw::table::CatalogT< PeakRecord > PeakCatalog
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
int positionToIndex(double pos)
Convert image position to nearest integer index.
std::shared_ptr< ImageT > offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Return an image offset by (dx, dy) using the specified algorithm.