32 template <
typename PixelT>
42 mi != detBadMaskPlanes.
end(); ++mi){
46 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelCandidateDetection",
47 "Cannot update bad bit mask with %s", (*mi).c_str());
48 LOGL_DEBUG(
"TRACE4.ip.diffim.KernelCandidateDetection",
52 LOGL_DEBUG(
"TRACE2.ip.diffim.KernelCandidateDetection",
53 "Using bad bit mask %d", _badBitMask);
76 template <
typename PixelT>
83 int fpNpixMin = _policy.
getInt(
"fpNpixMin");
84 int fpGrowPix = _policy.
getInt(
"fpGrowPix");
86 bool detOnTemplate = _policy.
getBool(
"detOnTemplate");
87 double detThreshold = _policy.
getDouble(
"detThreshold");
98 afwDetect::createThreshold(detThreshold, detThresholdType);
100 if (detOnTemplate ==
true) {
102 *(templateMaskedImage),
109 LOGL_DEBUG(
"TRACE2.ip.diffim.KernelCandidateDetection.apply",
110 "Found %d total footprints in template above %.3f %s",
111 footprintListInPtr->size(), detThreshold, detThresholdType.
c_str());
115 *(scienceMaskedImage),
121 LOGL_DEBUG(
"TRACE2.ip.diffim.KernelCandidateDetection.apply",
122 "Found %d total footprints in science image above %.3f %s",
123 footprintListInPtr->size(), detThreshold, detThresholdType.
c_str());
128 i != footprintListInPtr->end(); ++i) {
130 growCandidate((*i), fpGrowPix, templateMaskedImage, scienceMaskedImage);
133 if (_footprints.
size() == 0) {
135 "Unable to find any footprints for Psf matching");
138 LOGL_DEBUG(
"TRACE1.ip.diffim.KernelCandidateDetection.apply",
139 "Found %d clean footprints above threshold %.3f",
140 _footprints.
size(), detThreshold);
144 template <
typename PixelT>
151 int fpNpixMax = _policy.
getInt(
"fpNpixMax");
159 afwGeom::Box2I fpBBox = fp->getBBox();
167 if (fp->getArea() >
static_cast<std::size_t>(fpNpixMax)) {
168 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelCandidateDetection.apply",
169 "Footprint has too many pix: %d (max =%d)",
170 fp->getArea(), fpNpixMax);
172 int xc = int(0.5 * (fpBBox.getMinX() + fpBBox.getMaxX()));
173 int yc = int(0.5 * (fpBBox.getMinY() + fpBBox.getMaxY()));
176 std::make_shared<afwGeom::SpanSet>(afwGeom::Box2I(afwGeom::Point2I(xc, yc),
177 afwGeom::Extent2I(1,1))))
179 return growCandidate(fpCore, fpGrowPix, templateMaskedImage, scienceMaskedImage);
182 LOGL_DEBUG(
"TRACE5.ip.diffim.KernelCandidateDetection.apply",
183 "Original footprint in parent : %d,%d -> %d,%d -> %d,%d",
184 fpBBox.getMinX(), fpBBox.getMinY(),
185 int(0.5 * (fpBBox.getMinX() + fpBBox.getMaxX())),
186 int(0.5 * (fpBBox.getMinY() + fpBBox.getMaxY())),
187 fpBBox.getMaxX(), fpBBox.getMaxY());
208 fp->getSpans()->dilated(fpGrowPix, afwGeom::Stencil::MANHATTAN)
213 afwGeom::Box2I fpGrowBBox = fpGrow->getBBox();
214 LOGL_DEBUG(
"TRACE5.ip.diffim.KernelCandidateDetection.apply",
215 "Grown footprint in parent : %d,%d -> %d,%d -> %d,%d",
216 fpGrowBBox.getMinX(), fpGrowBBox.getMinY(),
217 int(0.5 * (fpGrowBBox.getMinX() + fpGrowBBox.getMaxX())),
218 int(0.5 * (fpGrowBBox.getMinY() + fpGrowBBox.getMaxY())),
219 fpGrowBBox.getMaxX(), fpGrowBBox.getMaxY());
224 if (!(templateMaskedImage->getBBox().contains(fpGrowBBox))) {
225 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelCandidateDetection.apply",
226 "Footprint grown off image");
231 bool subimageHasFailed =
false;
238 if (fsb.
getBits() & _badBitMask) {
239 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelCandidateDetection.apply",
240 "Footprint has masked pix (vals=%d) in image to convolve",
242 subimageHasFailed =
true;
246 if (fsb.
getBits() & _badBitMask) {
247 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelCandidateDetection.apply",
248 "Footprint has masked pix (vals=%d) in image not to convolve",
250 subimageHasFailed =
true;
254 LOGL_DEBUG(
"TRACE3.ip.diffim.KernelCandidateDetection.apply",
255 "Exception caught extracting Footprint");
256 LOGL_DEBUG(
"TRACE4.ip.diffim.KernelCandidateDetection.apply",
258 subimageHasFailed =
true;
260 if (subimageHasFailed) {
Image Subtraction helper functions.
virtual char const * what(void) const noexcept
void apply(MaskT const &mask)
void apply(MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage)
Runs Detection on a single image for significant peaks, and checks returned Footprints for Masked pix...
Detect candidates for kernels within 2 images.
KernelCandidateDetection(lsst::pex::policy::Policy const &policy)
Class to accumulate Mask bits.
StringArray getStringArray(const std::string &name) const
bool getBool(const std::string &name) const
Search through images for Footprints with no masked pixels.
int getInt(const std::string &name) const
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
const std::string getString(const std::string &name) const
double getDouble(const std::string &name) const
#define LSST_EXCEPT(type,...)
bool growCandidate(std::shared_ptr< lsst::afw::detection::Footprint > fp, int fpGrowPix, MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage)
#define LOGL_DEBUG(logger, message...)
MaskT::Pixel getBits() const