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;
60 T operator()(T x)
const {
return x; }
65 andMask(T mask) : _mask(mask) {}
66 T operator()(T x)
const {
return (x & _mask); }
73andMask<T> makeAndMask(T val) {
74 return andMask<T>(val);
80template <
typename LhsT,
typename RhsT>
89 for (
int y = 0; y != lhs->getHeight(); ++y) {
93 lhsEnd = lhs->row_end(y);
94 lhsPtr != lhsEnd; ++rhsPtr, ++lhsPtr) {
95 *lhsPtr = func(*rhsPtr);
111template <
typename MaskT>
112class BlendedFunctor {
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);
127 iter != end; ++iter) {
128 double const dist2 = distanceSquared(x, y, *iter);
129 if (dist2 < 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();
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);
210 others.reserve(peaks.size() - 1);
211 for (PeakCatalog::const_iterator iter = peaks.begin(), end = peaks.end(); iter != end; ++iter) {
212 std::shared_ptr<afw::detection::PeakRecord> ptr(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());
229 std::shared_ptr<afw::image::Image<int>> mim = makeImageFromMask<int>(*
image->getMask(), makeAndMask(detected));
230 std::shared_ptr<afw::detection::FootprintSet>
232 std::shared_ptr<FootprintList const> feet = fs->getFootprints();
234 if (feet->size() > 1) {
239 for (FootprintList::const_iterator fiter = feet->begin(); fiter != feet->end(); ++fiter) {
240 std::shared_ptr<afw::detection::Footprint> foot = *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);
254 std::shared_ptr<afw::detection::FootprintSet const>
257 for (FootprintList::const_iterator fpIter = fpSet->getFootprints()->begin();
258 fpIter != fpSet->getFootprints()->end(); ++fpIter) {
259 std::shared_ptr<afw::detection::Footprint const> fp = *fpIter;
260 if (!fp->contains(cen)) {
261 fp->getSpans()->clearMask(*
image->getMask(), detected);
262 fp->getSpans()->setMask(*
image->getMask(), intrp);
275template <
typename PixelT>
276std::shared_ptr<afw::image::MaskedImage<PixelT>
const>
278 if (!_image || (width != _image->getWidth() || height != _image->getHeight())) {
279 _image = extractImage(width, height);
289template <
typename PixelT>
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>
339 if (_offsetImage &&
static_cast<unsigned int>(_offsetImage->getWidth()) == width + 2 * buffer &&
340 static_cast<unsigned int>(_offsetImage->getHeight()) == height + 2 * buffer) {
#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.
Record class that represents a peak in a Footprint.
@ PIXEL_STDEV
Use number of sigma given per-pixel s.d.
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
lsst::geom::Point2I getXY0() const
Return the image's origin.
A class to represent a 2-dimensional array of pixels.
Represent a 2-dimensional array of bitmask pixels.
float getYCenter() const
Return the object's row-centre.
float getXCenter() const
Return the object's column-centre.
static int getWidth()
Return the width of the image that getImage should return.
static int getHeight()
Return the height of the image that getImage should return.
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...
afw::image::MaskedImage< PixelT > MaskedImageT
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.
Reports attempts to exceed implementation-defined length limits for some classes.
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.
Extent< int, 2 > Extent2I
float PsfCandidate< PixelT >::_pixelThreshold
A functor class equivalent to std::function<ValT (ValT)>, but with a virtual operator()