LSSTApplications
19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
|
#include <BaselineUtils.h>
|
static boost::shared_ptr< lsst::afw::detection::Footprint > | symmetrizeFootprint (lsst::afw::detection::Footprint const &foot, int cx, int cy) |
| Given a Footprint foot and peak cx,cy, returns a Footprint that is symmetric around the peak (with twofold rotational symmetry) – the AND of the two symmetric halves. More...
|
|
static std::pair< ImagePtrT, FootprintPtrT > | buildSymmetricTemplate (MaskedImageT const &img, lsst::afw::detection::Footprint const &foot, lsst::afw::detection::PeakRecord const &pk, double sigma1, bool minZero, bool patchEdges, bool *patchedEdges) |
| Given an img, footprint foot, and peak, creates a symmetric template around the peak; produce a MaskedImage and Footprint describing a footprint where: output pixels (cx + dx, cy + dy) and (cx - dx, cy - dy) = min(input pixels (cx + dx, cy + dy) and (cx - dx, cy - dy)) More...
|
|
static void | medianFilter (ImageT const &img, ImageT &outimg, int halfsize) |
| Run a spatial median filter over the given input img, writing the results to out. More...
|
|
static void | makeMonotonic (ImageT &img, lsst::afw::detection::PeakRecord const &pk) |
| Given an image mimg and Peak location peak, overwrite mimg so that pixels further from the peak have values smaller than those close to the peak; make the profile monotonic-decreasing. More...
|
|
static std::vector< typename boost::shared_ptr< lsst::afw::image::MaskedImage< ImagePixelT > MaskPixelT, VariancePixelT >)> | apportionFlux (MaskedImageT const &img, lsst::afw::detection::Footprint const &foot, std::vector< typename boost::shared_ptr< lsst::afw::image::Image< ImagePixelT > >> templates, std::vector< std::shared_ptr< lsst::afw::detection::Footprint > > templ_footprints, ImagePtrT templ_sum, std::vector< bool > const &ispsf, std::vector< int > const &pkx, std::vector< int > const &pky, std::vector< std::shared_ptr< typename lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > > &strays, int strayFluxOptions, double clipStrayFluxFraction) |
| Splits flux in a given image img, within a given footprint foot, among a number of templates timgs,tfoots. More...
|
|
static bool | hasSignificantFluxAtEdge (ImagePtrT, std::shared_ptr< lsst::afw::detection::Footprint >, ImagePixelT threshold) |
| Returns true if the given Footprint sfoot in image img has flux above value thresh at its edge. More...
|
|
static std::shared_ptr< lsst::afw::detection::Footprint > | getSignificantEdgePixels (ImagePtrT, std::shared_ptr< lsst::afw::detection::Footprint >, ImagePixelT threshold) |
| Returns a list of pixels that are on the edge of the given Footprint sfoot* in image img, above threshold thresh. More...
|
|
static void | _sum_templates (std::vector< ImagePtrT > timgs, ImagePtrT tsum) |
|
static void | _find_stray_flux (lsst::afw::detection::Footprint const &foot, ImagePtrT tsum, MaskedImageT const &img, int strayFluxOptions, std::vector< std::shared_ptr< lsst::afw::detection::Footprint > > tfoots, std::vector< bool > const &ispsf, std::vector< int > const &pkx, std::vector< int > const &pky, double clipStrayFluxFraction, std::vector< std::shared_ptr< typename lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > > &strays) |
|
template<typename ImagePixelT, typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
class lsst::meas::deblender::BaselineUtils< ImagePixelT, MaskPixelT, VariancePixelT >
Definition at line 22 of file BaselineUtils.h.
◆ FootprintPtrT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ FootprintT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ HeavyFootprintPtrT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ HeavyFootprintT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ ImagePtrT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ ImageT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ MaskedImagePtrT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ MaskedImageT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ MaskPtrT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ MaskT
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
◆ _find_stray_flux()
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
void lsst::meas::deblender::BaselineUtils< ImagePixelT, MaskPixelT, VariancePixelT >::_find_stray_flux |
( |
lsst::afw::detection::Footprint const & |
foot, |
|
|
ImagePtrT |
tsum, |
|
|
MaskedImageT const & |
img, |
|
|
int |
strayFluxOptions, |
|
|
std::vector< std::shared_ptr< lsst::afw::detection::Footprint > > |
tfoots, |
|
|
std::vector< bool > const & |
ispsf, |
|
|
std::vector< int > const & |
pkx, |
|
|
std::vector< int > const & |
pky, |
|
|
double |
clipStrayFluxFraction, |
|
|
std::vector< std::shared_ptr< typename lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > > & |
strays |
|
) |
| |
|
static |
Hmm, this is a little bit dangerous: we're assuming that the HeavyFootprint stores its pixels in the same order that we iterate over them above (ie, lexicographic).
Definition at line 393 of file BaselineUtils.cc.
417 int ix0 = img.getX0();
418 int iy0 = img.getY0();
423 for (
size_t i=0; i<tfoots.
size(); ++i) {
445 if (!always && ispsf.
size()) {
448 auto empty = std::make_shared<det::Footprint>();
449 empty->setPeakSchema(foot.getPeaks().getSchema());
450 for (
size_t i=0; i<tfoots.
size(); ++i) {
457 footlist = &templist;
459 nearestFootprint(*footlist, nearest, dist);
469 tsum->row_begin(
y - sumy0) + (x0 - sumx0);
471 img.row_begin(
y - iy0) + (x0 - ix0);
472 double contrib[tfoots.
size()];
474 for (
int x = x0;
x <= x1; ++
x, ++tsum_it, ++in_it) {
478 if ((*tsum_it > 0) || (*in_it).image() <= 0) {
484 for (
size_t i=0; i<tfoots.
size(); ++i) {
488 for (
size_t i=0; i<tfoots.
size(); ++i) {
495 for (
size_t i=0; i<tfoots.
size(); ++i) {
500 contrib[i] = 1. / (1. + dx*dx + dy*dy);
506 bool ptsrcs = always;
508 for (
size_t i=0; i<tfoots.
size(); ++i) {
510 if ((!ptsrcs) && ispsf.
size() && ispsf[i]) {
513 if (contrib[i] == -1.0) {
514 contrib[i] = _get_contrib_r_to_footprint(
x,
y, tfoots[i]);
524 for (
size_t i=0; i<tfoots.
size(); ++i) {
525 if (contrib[i] == -1.0) {
526 contrib[i] = _get_contrib_r_to_footprint(
x,
y, tfoots[i]);
533 double strayclip = (clipStrayFluxFraction * csum);
535 for (
size_t i=0; i<tfoots.
size(); ++i) {
537 if ((!ptsrcs) && ispsf.
size() && ispsf[i]) {
542 if (contrib[i] < strayclip) {
549 for (
size_t i=0; i<tfoots.
size(); ++i) {
550 if (contrib[i] == 0.) {
554 double p = (contrib[i] / csum) * (*in_it).image();
557 strayfoot[i] = std::make_shared<det::Footprint>();
558 strayfoot[i]->setPeakSchema(foot.getPeaks().getSchema());
563 strayvar[i].
push_back((*in_it).variance());
569 for (
size_t i=0; i<tfoots.
size(); ++i) {
571 strayfoot[i]->setSpans(std::make_shared<afwGeom::SpanSet>(straySpans[i]));
580 ndarray::Array<ImagePixelT,1,1> himg = heavy->getImageArray();
588 assert((
size_t)strayfoot[i]->getArea() == straypix[i].size());
590 for (spix = straypix[i].
begin(),
591 smask = straymask[i].
begin(),
592 svar = strayvar [i].
begin(),
594 mpix = heavy->getMaskArray().begin(),
595 vpix = heavy->getVarianceArray().begin();
596 spix != straypix[i].end();
597 ++spix, ++smask, ++svar, ++hpix, ++mpix, ++vpix) {
◆ _sum_templates()
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
Definition at line 609 of file BaselineUtils.cc.
617 for (
size_t i=0; i<timgs.
size(); ++i) {
633 tsum->row_begin(
y - sumy0) + (copyx0 - sumx0);
634 for (; in_it != inend; ++in_it, ++tsum_it) {
635 *tsum_it +=
std::max((ImagePixelT)0.,
static_cast<ImagePixelT
>(*in_it));
◆ apportionFlux()
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
std::vector< typename boost::shared_ptr< image::MaskedImage< ImagePixelT > MaskPixelT, VariancePixelT >)> lsst::meas::deblender::BaselineUtils< ImagePixelT, MaskPixelT, VariancePixelT >::apportionFlux |
( |
MaskedImageT const & |
img, |
|
|
lsst::afw::detection::Footprint const & |
foot, |
|
|
std::vector< typename boost::shared_ptr< lsst::afw::image::Image< ImagePixelT > >> |
templates, |
|
|
std::vector< std::shared_ptr< lsst::afw::detection::Footprint > > |
templ_footprints, |
|
|
ImagePtrT |
templ_sum, |
|
|
std::vector< bool > const & |
ispsf, |
|
|
std::vector< int > const & |
pkx, |
|
|
std::vector< int > const & |
pky, |
|
|
std::vector< std::shared_ptr< typename lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > > & |
strays, |
|
|
int |
strayFluxOptions, |
|
|
double |
clipStrayFluxFraction |
|
) |
| |
|
static |
Splits flux in a given image img, within a given footprint foot, among a number of templates timgs,tfoots.
This is where actual "deblending" takes place.
timgs* and tfoots MUST be the same length.
Flux is assigned to templates according to their relative heights at each pixel.
If strayFluxOptions includes ASSIGN_STRAYFLUX, then "stray flux" – flux in the parent footprint that is not covered by any of the template footprints – is assigned to templates based on their 1/(1+r^2) distance.
If strayFluxOptions includes STRAYFLUX_R_TO_FOOTPRINT, the stray flux is distributed to the footprints based on 1/(1+r^2) of the minimum distance from the stray flux to footprint.
If strayFluxOptions includes "STRAYFLUX_NEAREST_FOOTPRINT*, the stray flux is assigned to the footprint with lowest L-1 (Manhattan) distance to the stray flux.
Otherwise, stray flux is assigned based on (1/(1+r^2) from the peaks.
If strayFluxOptions includes STRAYFLUX_TO_POINT_SOURCES_ALWAYS, then point sources are always included in the 1/(1+r^2) splitting. Otherwise, if STRAYFLUX_TO_POINT_SOURCES_WHEN_NECESSARY, point sources are included only if there are no extended sources nearby.
If any stray-flux portion is less than clipStrayFluxFraction, it is clipped to zero.
When doing stray flux, the "strays" arg is used as an extra return value, the stray flux assigned to each template.
When doing stray flux, the ispsf, pkx, and pky arrays are required. They give the peak x,y coords plus whether the peak is believed (by the deblender) to be a point source. pkx and pky MUST be the same length as timgs. If ispsf has nonzero length, it MUST be the same length as timgs.
If tsum is given, is it set to the sum of max(0, template).
The return value is a vector of MaskedImages containing the flux assigned to each template.
Definition at line 692 of file BaselineUtils.cc.
706 if (timgs.size() != tfoots.size()) {
708 (
boost::format(
"Template images must be the same length as template footprints (%d vs %d)")
709 % timgs.size() % tfoots.size()).str());
712 for (
size_t i=0; i<timgs.size(); ++i) {
713 if (!timgs[i]->getBBox().
contains(tfoots[i]->getBBox())) {
715 "Template image MUST contain template footprint");
717 if (!img.getBBox().contains(foot.getBBox())) {
719 "Image bbox MUST contain parent footprint");
732 int ix0 = img.getX0();
733 int iy0 = img.getY0();
741 if (!tsum->getBBox().contains(foot.getBBox())) {
743 "Template sum image MUST contain parent footprint");
753 for (
size_t i=0; i<timgs.size(); ++i) {
757 port->setXY0(timg->getXY0());
769 img.row_begin(
y - iy0) + (copyx0 - ix0);
771 timg->row_begin(
y - ty0) + (copyx0 - tx0);
774 tsum->row_begin(
y - sumy0) + (copyx0 - sumx0);
776 port->row_begin(
y - ty0) + (copyx0 - tx0);
777 for (; tptr != tend; ++tptr, ++in_it, ++out_it, ++tsum_it) {
781 double frac =
std::max((ImagePixelT)0.,
static_cast<ImagePixelT
>(*tptr)) / (*tsum_it);
785 out_it.mask() = (*in_it).mask();
786 out_it.variance() = (*in_it).variance();
787 out_it.image() = (*in_it).image() * frac;
793 if ((ispsf.
size() > 0) && (ispsf.
size() != timgs.size())) {
795 (
boost::format(
"'ispsf' must be the same length as templates (%d vs %d)")
796 % ispsf.
size() % timgs.size()).str());
798 if ((pkx.
size() != timgs.size()) || (pky.
size() != timgs.size())) {
800 (
boost::format(
"'pkx' and 'pky' must be the same length as templates (%d,%d vs %d)")
801 % pkx.
size() % pky.
size() % timgs.size()).str());
804 ispsf, pkx, pky, clipStrayFluxFraction, strays);
◆ buildSymmetricTemplate()
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
Given an img, footprint foot, and peak, creates a symmetric template around the peak; produce a MaskedImage and Footprint describing a footprint where: output pixels (cx + dx, cy + dy) and (cx - dx, cy - dy) = min(input pixels (cx + dx, cy + dy) and (cx - dx, cy - dy))
If patchEdge is true and if the footprint touches pixels with the EDGE bit set, then for spans whose symmetric mirror are outside the image, the symmetric footprint is grown to include them and their pixel values are stored.
Definition at line 1189 of file BaselineUtils.cc.
1201 *patchedEdges =
false;
1203 int cx =
peak.getIx();
1204 int cy =
peak.getIy();
1218 if (!img.getBBox(
image::PARENT).contains(sfoot->getBBox())) {
1220 "Image too small for symmetrized footprint");
1225 bool touchesEdge =
false;
1227 LOGL_DEBUG(_log,
"Checking footprint for EDGE bits");
1230 MaskPixelT edgebit =
mask->getPlaneBitMask(
"EDGE");
1232 fwd != spans.
end(); ++fwd) {
1233 int x0 = fwd->getX0();
1234 int x1 = fwd->getX1();
1236 mask->x_at(x0 -
mask->getX0(), fwd->getY() -
mask->getY0());
1237 for (
int x=x0;
x<=x1; ++
x, ++xiter) {
1238 if ((*xiter) & edgebit) {
1247 LOGL_DEBUG(_log,
"Footprint includes an EDGE pixel.");
1260 for (; fwd <= back; fwd++, back--) {
1261 int fy = fwd->getY();
1262 int by = back->getY();
1264 for (
int fx=fwd->getX0(), bx=back->getX1();
1281 ImagePixelT pix =
std::min(pixf, pixb);
1283 pix =
std::max(pix,
static_cast<ImagePixelT
>(0));
1302 LOGL_DEBUG(_log,
"Footprint touches EDGE: start bbox [%i,%i],[%i,%i]",
1306 for (fwd = ospans.
begin(); fwd != ospans.
end(); ++fwd) {
1307 int y = fwd->getY();
1308 int x = fwd->getX0();
1310 int ym = cy + (cy -
y);
1311 int xm = cx + (cx -
x);
1321 LOGL_DEBUG(_log,
"Footprint touches EDGE: grown bbox [%i,%i],[%i,%i]",
1326 sfoot->getSpans()->copyImage(*targetimg, *targetimg2);
1328 LOGL_DEBUG(_log,
"Symmetric footprint spans:");
1330 for (fwd = sspans.
begin(); fwd != sspans.
end(); ++fwd) {
1331 LOGL_DEBUG(_log,
" %s", fwd->toString().c_str());
1337 for (fwd = ospans.
begin(); fwd != ospans.
end(); ++fwd) {
1338 int y = fwd->getY();
1339 int x0 = fwd->getX0();
1340 int x1 = fwd->getX1();
1342 int ym = cy + (cy -
y);
1343 int xm0 = cx + (cx - x0);
1344 int xm1 = cx + (cx - x1);
1355 x0 = cx + (cx - (imbb.
getMinX() - 1));
1358 x1 = cx + (cx - (imbb.
getMaxX() + 1));
1360 LOGL_DEBUG(_log,
"Span y=%i, x=[%i,%i] has mirror (%i,[%i,%i]) out-of-bounds; clipped to %i,[%i,%i]",
1361 y, fwd->getX0(), fwd->getX1(), ym, xm1, xm0,
y, x0, x1);
1363 img.x_at(x0 - img.getX0(),
y - img.getY0());
1365 targetimg2->x_at(x0 - targetimg2->getX0(),
y - targetimg2->getY0());
1366 for (
int x=x0;
x<=x1; ++
x, ++outiter, ++initer) {
1367 *outiter = initer.image();
1371 sfoot->setSpans(std::make_shared<afwGeom::SpanSet>(
std::move(newSpans)));
1372 targetimg = targetimg2;
1375 *patchedEdges = touchesEdge;
◆ getSignificantEdgePixels()
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
Returns a list of pixels that are on the edge of the given Footprint sfoot* in image img, above threshold thresh.
Definition at line 1418 of file BaselineUtils.cc.
1425 auto significant = std::make_shared<det::Footprint>();
1426 significant->setPeakSchema(sfoot->getPeaks().getSchema());
1428 int const x0 = img->getX0(), y0 = img->getY0();
1433 int const y = span.
getY();
1436 bool onSpan =
false;
1439 if (*
iter >= thresh) {
1442 }
else if (onSpan) {
1451 significant->setSpans(std::make_shared<afwGeom::SpanSet>(
std::move(tmpSpans)));
◆ hasSignificantFluxAtEdge()
template<typename ImagePixelT , typename MaskPixelT = lsst::afw::image::MaskPixel, typename VariancePixelT = lsst::afw::image::VariancePixel>
Returns true if the given Footprint sfoot in image img has flux above value thresh at its edge.
Definition at line 1385 of file BaselineUtils.cc.
1398 int const y = sp->getY();
1399 int const x0 = sp->getX0();
1400 int const x1 = sp->getX1();
1403 for (xiter = img->x_at(x0 - img->getX0(),
y - img->getY0()),
x=x0;
x<=x1; ++
x, ++xiter) {
1404 if (*xiter >= thresh) {
◆ makeMonotonic()
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
Given an image mimg and Peak location peak, overwrite mimg so that pixels further from the peak have values smaller than those close to the peak; make the profile monotonic-decreasing.
The exact algorithm is a little more complicated than that. The basic idea is of "casting a shadow" from a pixel to pixels farther from the peak in the same direction. Done naively, this results in very narrow "shadows" and ragged profiles. A tweak is to make the shadows "fatter" – make a pixel shadow a wedge of pixels – but if one does this naively, the wedge gets wider and wider too quickly. The algorithm works out from the peak in square "rings" of pixels, so if a pixel shadows a wedge 30 degrees wide, in the next ring of pixels the shadowed pixel at largest angle from the shadowing pixel will shade a yet-larger wedge, expanding the shadowing angle. To reduce this effect, we work in chunks of 5 pixels in radius, only copying the intermediate pixels to the "shadowing" image at the end of each chunk.
Currently the mask and variance planes of the input are totally ignored.
For illustration, run tests/monotonic.py and look at im*.png
Definition at line 225 of file BaselineUtils.cc.
230 int cx =
peak.getIx();
231 int cy =
peak.getIy();
232 int ix0 = img.getX0();
233 int iy0 = img.getY0();
234 int iW = img.getWidth();
235 int iH = img.getHeight();
239 int DW =
std::max(cx - img.getX0(), img.getX0() + img.getWidth() - cx);
240 int DH =
std::max(cy - img.getY0(), img.getY0() + img.getHeight() - cy);
246 for (s = 0; s <
std::max(DW,DH); s += S) {
248 for (p=0; p<S; p++) {
288 for (
int i=0; i<(8*L); i++,
x += dx,
y += dy) {
292 if (i % (2*L) == 0) {
295 dx = ( leg % 2) * (-1 + 2*(leg/2));
297 dy = ((leg+1) % 2) * ( 1 - 2*(leg/2));
300 int px = cx +
x - ix0;
301 int py = cy +
y - iy0;
303 if (px < 0 || px >= iW || py < 0 || py >= iH)
306 ImagePixelT pix = (*shadowingImg)(px,
py);
313 const double A = 0.3;
319 ds0 = (double(
y) / double(
x)) - A;
322 for (shx=1; shx<=S; shx++) {
323 int xsign = (
x>0?1:-1);
325 psx = cx +
x + (xsign*shx) - ix0;
326 if (psx < 0 || psx >= iW)
329 for (shy =
lround(shx * ds0);
330 shy <=
lround(shx * ds1); shy++) {
331 psy = cy +
y + xsign*shy - iy0;
332 if (psy < 0 || psy >= iH)
334 img(psx, psy) =
std::min(img(psx, psy), pix);
340 ds0 = (double(
x) / double(
y)) - A;
343 for (shy=1; shy<=S; shy++) {
344 int ysign = (
y>0?1:-1);
345 psy = cy +
y + (ysign*shy) - iy0;
346 if (psy < 0 || psy >= iH)
349 for (shx =
lround(shy * ds0);
350 shx <=
lround(shy * ds1); shx++) {
351 psx = cx +
x + ysign*shx - ix0;
352 if (psx < 0 || psx >= iW)
354 img(psx, psy) =
std::min(img(psx, psy), pix);
360 shadowingImg->assign(img);
◆ medianFilter()
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
Run a spatial median filter over the given input img, writing the results to out.
halfsize is half the box size of the filter; ie, a halfsize of 50 means that each output ixel will be the median of the pixels in a 101 x 101-pixel box in the input image.
Margins are handled horribly: the median is computed only for pixels more than halfsize away from the edges; pixels near the edges are simply copied from the input img to out.
Mask and variance planes are, likewise, simply copied from img to out*.
Definition at line 147 of file BaselineUtils.cc.
151 int S = halfsize*2 + 1;
154 xy_loc pix = img.xy_at(halfsize,halfsize);
156 for (
int i=0; i<S; ++i) {
157 for (
int j=0; j<S; ++j) {
158 locs.
push_back(pix.cache_location(j-halfsize, i-halfsize));
161 int W = img.getWidth();
162 int H = img.getHeight();
163 ImagePixelT vals[S*S];
164 for (
int y=halfsize;
y<H-halfsize; ++
y) {
165 xy_loc inpix = img.xy_at(halfsize,
y),
end = img.xy_at(W-halfsize,
y);
167 inpix !=
end; ++inpix.x(), ++optr) {
168 for (
int i=0; i<SS; ++i)
169 vals[i] = inpix[locs[i]];
176 for (
int y=0;
y<2*halfsize; ++
y) {
179 iy = H - 1 - (
y-halfsize);
182 for (; iptr !=
end; ++iptr,++optr)
185 for (
int y=halfsize;
y<H-halfsize; ++
y) {
188 for (; iptr !=
end; ++iptr,++optr)
190 iptr = img.row_begin(
y) + ((W-1) - halfsize);
191 end = img.row_begin(
y) + (W-1);
192 optr = out.row_begin(
y) + ((W-1) - halfsize);
193 for (; iptr !=
end; ++iptr,++optr)
◆ symmetrizeFootprint()
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
Given a Footprint foot and peak cx,cy, returns a Footprint that is symmetric around the peak (with twofold rotational symmetry) – the AND of the two symmetric halves.
Definition at line 974 of file BaselineUtils.cc.
979 auto sfoot = std::make_shared<det::Footprint>();
980 sfoot->setPeakSchema(foot.getPeaks().getSchema());
994 if (peakspan == spans.
begin()) {
998 "Failed to find span containing (%i,%i): before the beginning of this footprint", cx, cy);
1010 LOGL_WARN(_log,
"Failed to find span containing (%i,%i): nearest is %i, [%i,%i]. "
1011 "Footprint bbox is [%i,%i],[%i,%i]",
1018 LOGL_DEBUG(_log,
"Span containing (%i,%i): (x=[%i,%i], y=%i)",
1054 while (fwd.notDone() && back.notDone()) {
1059 int fdxlo = fwd.dxlo();
1060 int bdxlo = back.dxlo();
1067 for (fend = fwd; fend.
notDone(); ++fend) {
1068 if (fend.
dy() != dy)
1071 for (bend = back; bend.
notDone(); ++bend) {
1072 if (bend.
dy() != dy)
1076 LOGL_DEBUG(_log,
"dy=%i, fy=%i, fx=[%i, %i], by=%i, fx=[%i, %i], fdx=%i, bdx=%i",
1077 dy, fy, fwd.x0(), fwd.x1(), by, back.x0(), back.x1(),
1081 if (bdxlo > fdxlo) {
1086 while ((fwd != fend) && (fwd.dxhi() < bdxlo)) {
1091 LOGL_DEBUG(_log,
"Advanced to forward span %i, [%i, %i]",
1092 fy, fwd.x0(), fwd.x1());
1095 }
else if (fdxlo > bdxlo) {
1100 while ((back != bend) && (back.dxhi() < fdxlo)) {
1105 LOGL_DEBUG(_log,
"Advanced to backward span %i, [%i, %i]",
1106 by, back.x0(), back.x1());
1111 if ((back == bend) || (fwd == fend)) {
1127 int dxlo =
std::max(fwd.dxlo(), back.dxlo());
1128 int dxhi =
std::min(fwd.dxhi(), back.dxhi());
1130 LOGL_DEBUG(_log,
"Adding span fwd %i, [%i, %i], back %i, [%i, %i]",
1131 fy, cx+dxlo, cx+dxhi, by, cx-dxhi, cx-dxlo);
1137 if (fwd.dxhi() < back.dxhi()) {
1142 LOGL_DEBUG(_log,
"Stepped forward to span %i, [%i, %i]",
1143 fwd.y(), fwd.x0(), fwd.x1());
1150 LOGL_DEBUG(_log,
"Stepped backward to span %i, [%i, %i]",
1151 back.y(), back.x0(), back.x1());
1155 if ((back == bend) || (fwd == fend)) {
1170 sfoot->setSpans(std::make_shared<afwGeom::SpanSet>(
std::move(tmpSpans)));
◆ ASSIGN_STRAYFLUX
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
◆ STRAYFLUX_NEAREST_FOOTPRINT
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
◆ STRAYFLUX_R_TO_FOOTPRINT
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
◆ STRAYFLUX_TO_POINT_SOURCES_ALWAYS
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
◆ STRAYFLUX_TO_POINT_SOURCES_WHEN_NECESSARY
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
◆ STRAYFLUX_TRIM
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
The documentation for this class was generated from the following files:
- /j/snowflake/release/lsstsw/stack/cb4e2dc/Linux64/meas_deblender/20.0.0-3-g8f21e14+4fd2c12c9a/include/lsst/meas/deblender/BaselineUtils.h
- /j/snowflake/release/lsstsw/stack/cb4e2dc/Linux64/meas_deblender/20.0.0-3-g8f21e14+4fd2c12c9a/src/BaselineUtils.cc
static const int STRAYFLUX_R_TO_FOOTPRINT
static const int ASSIGN_STRAYFLUX
A range of pixels within one row of an Image.
Extent2I const getDimensions() const noexcept
int getX1() const noexcept
Return the ending x-value.
static void _find_stray_flux(lsst::afw::detection::Footprint const &foot, ImagePtrT tsum, MaskedImageT const &img, int strayFluxOptions, std::vector< std::shared_ptr< lsst::afw::detection::Footprint > > tfoots, std::vector< bool > const &ispsf, std::vector< int > const &pkx, std::vector< int > const &pky, double clipStrayFluxFraction, std::vector< std::shared_ptr< typename lsst::afw::detection::HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > > &strays)
static void _sum_templates(std::vector< ImagePtrT > timgs, ImagePtrT tsum)
#define LOGL_WARN(logger, message...)
boost::shared_ptr< lsst::afw::image::Mask< MaskPixelT > > MaskPtrT
static const int STRAYFLUX_TO_POINT_SOURCES_WHEN_NECESSARY
static boost::shared_ptr< lsst::afw::detection::Footprint > symmetrizeFootprint(lsst::afw::detection::Footprint const &foot, int cx, int cy)
Given a Footprint foot and peak cx,cy, returns a Footprint that is symmetric around the peak (with tw...
_view_t::xy_locator xy_locator
An xy_locator.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
std::vector< Span >::const_iterator const_iterator
static const int STRAYFLUX_TO_POINT_SOURCES_ALWAYS
A compact representation of a collection of pixels.
int getWidth() const noexcept
int getY() const noexcept
Return the y-value.
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
This is a convenience class used in symmetrizeFootprint, wrapping the idea of iterating through a Spa...
Reports attempts to exceed implementation-defined length limits for some classes.
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
bool contains(int x) const noexcept
FastFinder::Iterator Iterator
boost::shared_ptr< lsst::afw::detection::Footprint > FootprintPtrT
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
int getX0() const noexcept
Return the starting x-value.
Key< Flag > const & target
const_MaskedImageLocator< typename Image::xy_locator, typename Mask::xy_locator, typename Variance::xy_locator > const_xy_locator
A const_locator for a MaskedImage.
lsst::afw::image::Image< ImagePixelT > ImageT
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
int getMaxY() const noexcept
#define LOGL_DEBUG(logger, message...)
int getMaxX() const noexcept
const_iterator end() const
An integer coordinate rectangle.
int getMinX() const noexcept
boost::shared_ptr< lsst::afw::detection::HeavyFootprint< ImagePixelT > MaskPixelT, VariancePixelT > HeavyFootprintPtrT
const_iterator begin() const
A class to represent a 2-dimensional array of pixels.
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
MaskedImageIterator< typename Image::x_iterator, typename Mask::x_iterator, typename Variance::x_iterator > x_iterator
An iterator to a row of a MaskedImage.
Reports errors that are due to events beyond the control of the program.
static const int STRAYFLUX_NEAREST_FOOTPRINT
int getMinY() const noexcept
boost::shared_ptr< lsst::afw::image::Image< ImagePixelT > > ImagePtrT
lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > MaskedImageT
boost::shared_ptr< lsst::afw::image::MaskedImage< ImagePixelT > MaskPixelT, VariancePixelT > MaskedImagePtrT