LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | List of all members
lsst::ip::diffim::KernelCandidateDetection< PixelT > Class Template Reference

Search through images for Footprints with no masked pixels. More...

#include <KernelCandidateDetection.h>

Public Types

typedef boost::shared_ptr
< KernelCandidateDetection
Ptr
 
typedef boost::shared_ptr
< lsst::afw::image::MaskedImage
< PixelT > > 
MaskedImagePtr
 

Public Member Functions

 KernelCandidateDetection (lsst::pex::policy::Policy const &policy)
 
virtual ~KernelCandidateDetection ()
 
void apply (MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage)
 Runs Detection on a single image for significant peaks, and checks returned Footprints for Masked pixels. More...
 
bool growCandidate (lsst::afw::detection::Footprint::Ptr fp, int fpGrowPix, MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage)
 
std::vector
< lsst::afw::detection::Footprint::Ptr
getFootprints ()
 

Private Attributes

lsst::pex::policy::Policy _policy
 
lsst::afw::image::MaskPixel _badBitMask
 
std::vector
< lsst::afw::detection::Footprint::Ptr
_footprints
 

Detailed Description

template<typename PixelT>
class lsst::ip::diffim::KernelCandidateDetection< PixelT >

Search through images for Footprints with no masked pixels.

Note
Runs detection on the template; searches through both images for masked pixels
Parameters
templateMaskedImageMaskedImage that will be convolved with kernel
scienceMaskedImageMaskedImage to subtract convolved template from
policyPolicy for operations; in particular object detection

Definition at line 35 of file KernelCandidateDetection.h.

Member Typedef Documentation

template<typename PixelT >
typedef boost::shared_ptr<lsst::afw::image::MaskedImage<PixelT> > lsst::ip::diffim::KernelCandidateDetection< PixelT >::MaskedImagePtr

Definition at line 38 of file KernelCandidateDetection.h.

template<typename PixelT >
typedef boost::shared_ptr<KernelCandidateDetection> lsst::ip::diffim::KernelCandidateDetection< PixelT >::Ptr

Definition at line 37 of file KernelCandidateDetection.h.

Constructor & Destructor Documentation

Definition at line 34 of file KernelCandidateDetection.cc.

36  :
37  _policy(policy),
38  _badBitMask(0),
39  _footprints(std::vector<lsst::afw::detection::Footprint::Ptr>()) {
40 
41  std::vector<std::string> detBadMaskPlanes = _policy.getStringArray("badMaskPlanes");
42  for (std::vector<std::string>::iterator mi = detBadMaskPlanes.begin();
43  mi != detBadMaskPlanes.end(); ++mi){
44  try {
46  } catch (pexExcept::Exception& e) {
47  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection",
48  "Cannot update bad bit mask with %s", (*mi).c_str());
49  pexLog::TTrace<7>("lsst.ip.diffim.KernelCandidateDetection",
50  e.what());
51  }
52  }
53  pexLog::TTrace<4>("lsst.ip.diffim.KernelCandidateDetection",
54  "Using bad bit mask %d", _badBitMask);
55  }
std::vector< lsst::afw::detection::Footprint::Ptr > _footprints
StringArray getStringArray(const std::string &name) const
Definition: Policy.h:1023
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR&#39;d together.
Definition: Mask.cc:860
virtual char const * what(void) const
Definition: Exception.cc:112
template<typename PixelT >
virtual lsst::ip::diffim::KernelCandidateDetection< PixelT >::~KernelCandidateDetection ( )
inlinevirtual

Definition at line 42 of file KernelCandidateDetection.h.

42 {};

Member Function Documentation

template<typename PixelT >
void lsst::ip::diffim::KernelCandidateDetection< PixelT >::apply ( MaskedImagePtr const &  templateMaskedImage,
MaskedImagePtr const &  scienceMaskedImage 
)

Runs Detection on a single image for significant peaks, and checks returned Footprints for Masked pixels.

Note
Accepts two MaskedImages, one of which is to be convolved to match the other. The Detection package is run on either the image to be convolved (assumed to be higher S/N than the other image), or the image to not be convolved (assumed lower S/N; however if you run detection on a very deep template, you might not have significant S/N objects in the science image). The subimages associated with each returned Footprint in both images are checked for Masked pixels; Footprints containing Masked pixels are rejected. The Footprints are grown by an amount specified in the Policy. The acceptible Footprints are returned in a vector.
Returns
Vector of "clean" Footprints around which Image Subtraction Kernels will be built.

Definition at line 78 of file KernelCandidateDetection.cc.

81  {
82 
83  // Parse the Policy
84  int fpNpixMin = _policy.getInt("fpNpixMin");
85  int fpGrowPix = _policy.getInt("fpGrowPix");
86 
87  bool detOnTemplate = _policy.getBool("detOnTemplate");
88  double detThreshold = _policy.getDouble("detThreshold");
89  std::string detThresholdType = _policy.getString("detThresholdType");
90 
91  /* reset private variables */
92  _footprints.clear();
93 
94  // List of Footprints
95  boost::shared_ptr<std::vector<afwDetect::Footprint::Ptr> > footprintListInPtr;
96 
97  // Find detections
98  afwDetect::Threshold threshold =
99  afwDetect::createThreshold(detThreshold, detThresholdType);
100 
101  if (detOnTemplate == true) {
102  afwDetect::FootprintSet footprintSet(
103  *(templateMaskedImage),
104  threshold,
105  "",
106  fpNpixMin);
107  // Get the associated footprints
108 
109  footprintListInPtr = footprintSet.getFootprints();
110  pexLog::TTrace<4>("lsst.ip.diffim.KernelCandidateDetection.apply",
111  "Found %d total footprints in template above %.3f %s",
112  footprintListInPtr->size(), detThreshold, detThresholdType.c_str());
113  }
114  else {
115  afwDetect::FootprintSet footprintSet(
116  *(scienceMaskedImage),
117  threshold,
118  "",
119  fpNpixMin);
120 
121  footprintListInPtr = footprintSet.getFootprints();
122  pexLog::TTrace<4>("lsst.ip.diffim.KernelCandidateDetection.apply",
123  "Found %d total footprints in science image above %.3f %s",
124  footprintListInPtr->size(), detThreshold, detThresholdType.c_str());
125  }
126 
127  // Iterate over footprints, look for "good" ones
128  for (std::vector<afwDetect::Footprint::Ptr>::iterator i = footprintListInPtr->begin();
129  i != footprintListInPtr->end(); ++i) {
130 
131  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection.apply",
132  "Processing footprint %d", (*i)->getId());
133  growCandidate((*i), fpGrowPix, templateMaskedImage, scienceMaskedImage);
134  }
135 
136  if (_footprints.size() == 0) {
138  "Unable to find any footprints for Psf matching");
139  }
140 
141  pexLog::TTrace<1>("lsst.ip.diffim.KernelCandidateDetection.apply",
142  "Found %d clean footprints above threshold %.3f",
143  _footprints.size(), detThreshold);
144 
145  }
int getInt(const std::string &name) const
Definition: Policy.h:603
std::vector< lsst::afw::detection::Footprint::Ptr > _footprints
bool getBool(const std::string &name) const
Definition: Policy.h:589
const std::string getString(const std::string &name) const
Definition: Policy.h:631
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:44
bool growCandidate(lsst::afw::detection::Footprint::Ptr fp, int fpGrowPix, MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage)
Threshold createThreshold(const double value, const std::string type="value", const bool polarity=true)
Factory method for creating Threshold objects.
Definition: Threshold.cc:138
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53
double getDouble(const std::string &name) const
Definition: Policy.h:617
template<typename PixelT >
std::vector<lsst::afw::detection::Footprint::Ptr> lsst::ip::diffim::KernelCandidateDetection< PixelT >::getFootprints ( )
inline

Definition at line 52 of file KernelCandidateDetection.h.

52 {return _footprints;};
std::vector< lsst::afw::detection::Footprint::Ptr > _footprints
template<typename PixelT >
bool lsst::ip::diffim::KernelCandidateDetection< PixelT >::growCandidate ( lsst::afw::detection::Footprint::Ptr  fp,
int  fpGrowPix,
MaskedImagePtr const &  templateMaskedImage,
MaskedImagePtr const &  scienceMaskedImage 
)

Definition at line 148 of file KernelCandidateDetection.cc.

153  {
154  int fpNpixMax = _policy.getInt("fpNpixMax");
155 
156  /* Functor to search through the images for masked pixels within *
157  * candidate footprints. Might want to consider changing the default
158  * mask planes it looks through.
159  */
160  FindSetBits<afwImage::Mask<afwImage::MaskPixel> > fsb;
161 
162  afwGeom::Box2I fpBBox = fp->getBBox();
163  /* Failure Condition 1)
164  *
165  * Footprint has too many pixels off the bat. We don't want to throw
166  * away these guys, they have alot of signal! Lets just use the core of
167  * it.
168  *
169  */
170  if (fp->getNpix() > fpNpixMax) {
171  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection.apply",
172  "Footprint has too many pix: %d (max =%d)",
173  fp->getNpix(), fpNpixMax);
174 
175  int xc = int(0.5 * (fpBBox.getMinX() + fpBBox.getMaxX()));
176  int yc = int(0.5 * (fpBBox.getMinY() + fpBBox.getMaxY()));
179  );
180  return growCandidate(fpCore, fpGrowPix, templateMaskedImage, scienceMaskedImage);
181  }
182 
183  pexLog::TTrace<8>("lsst.ip.diffim.KernelCandidateDetection.apply",
184  "Original footprint in parent : %d,%d -> %d,%d -> %d,%d",
185  fpBBox.getMinX(), fpBBox.getMinY(),
186  int(0.5 * (fpBBox.getMinX() + fpBBox.getMaxX())),
187  int(0.5 * (fpBBox.getMinY() + fpBBox.getMaxY())),
188  fpBBox.getMaxX(), fpBBox.getMaxY());
189 
190  /* Grow the footprint
191  * flag true = isotropic grow = slow
192  * flag false = 'manhattan grow' = fast
193  *
194  * The manhattan masks are rotated 45 degree w.r.t. the coordinate
195  * system. They intersect the vertices of the rectangle that would
196  * connect pixels (X0,Y0) (X1,Y0), (X0,Y1), (X1,Y1).
197  *
198  * The isotropic masks do take considerably longer to grow and are
199  * basically elliptical. X0, X1, Y0, Y1 delimit the extent of the
200  * ellipse.
201  *
202  * In both cases, since the masks aren't rectangles oriented with
203  * the image coordinate system, when we DO extract such rectangles
204  * as subimages for kernel fitting, some corner pixels can be found
205  * in multiple subimages.
206  *
207  */
208  afwDetect::Footprint::Ptr fpGrow =
209  afwDetect::growFootprint(fp, fpGrowPix, false);
210 
211  /* Next we look at the image within this Footprint.
212  */
213  afwGeom::Box2I fpGrowBBox = fpGrow->getBBox();
214  pexLog::TTrace<8>("lsst.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());
220 
221  /* Failure Condition 2)
222  * Grown off the image
223  */
224  if (!(templateMaskedImage->getBBox().contains(fpGrowBBox))) {
225  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection.apply",
226  "Footprint grown off image");
227  return false;
228  }
229 
230  /* Grab subimages; report any exception */
231  bool subimageHasFailed = false;
232  try {
233  afwImage::MaskedImage<PixelT> templateSubimage(*templateMaskedImage, fpGrowBBox);
234  afwImage::MaskedImage<PixelT> scienceSubimage(*scienceMaskedImage, fpGrowBBox);
235 
236  // Search for any masked pixels within the footprint
237  fsb.apply(*(templateSubimage.getMask()));
238  if (fsb.getBits() & _badBitMask) {
239  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection.apply",
240  "Footprint has masked pix (vals=%d) in image to convolve",
241  fsb.getBits());
242  subimageHasFailed = true;
243  }
244 
245  fsb.apply(*(scienceSubimage.getMask()));
246  if (fsb.getBits() & _badBitMask) {
247  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection.apply",
248  "Footprint has masked pix (vals=%d) in image not to convolve",
249  fsb.getBits());
250  subimageHasFailed = true;
251  }
252 
253  } catch (pexExcept::Exception& e) {
254  pexLog::TTrace<6>("lsst.ip.diffim.KernelCandidateDetection.apply",
255  "Exception caught extracting Footprint");
256  pexLog::TTrace<7>("lsst.ip.diffim.KernelCandidateDetection.apply",
257  e.what());
258  subimageHasFailed = true;
259  }
260  if (subimageHasFailed) {
261  return false;
262  } else {
263  /* We have a good candidate */
264  _footprints.push_back(fpGrow);
265  return true;
266  }
267  }
int getInt(const std::string &name) const
Definition: Policy.h:603
int getMaxY() const
Definition: Box.h:129
std::vector< lsst::afw::detection::Footprint::Ptr > _footprints
boost::shared_ptr< Footprint > Ptr
Definition: Footprint.h:67
An integer coordinate rectangle.
Definition: Box.h:53
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool isotropic=true)
int getMinY() const
Definition: Box.h:125
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
int getMinX() const
Definition: Box.h:124
bool growCandidate(lsst::afw::detection::Footprint::Ptr fp, int fpGrowPix, MaskedImagePtr const &templateMaskedImage, MaskedImagePtr const &scienceMaskedImage)
A set of pixels in an Image.
Definition: Footprint.h:62
virtual char const * what(void) const
Definition: Exception.cc:112
int getMaxX() const
Definition: Box.h:128

Member Data Documentation

template<typename PixelT >
lsst::afw::image::MaskPixel lsst::ip::diffim::KernelCandidateDetection< PixelT >::_badBitMask
private

Definition at line 56 of file KernelCandidateDetection.h.

template<typename PixelT >
std::vector<lsst::afw::detection::Footprint::Ptr> lsst::ip::diffim::KernelCandidateDetection< PixelT >::_footprints
private

Definition at line 57 of file KernelCandidateDetection.h.

template<typename PixelT >
lsst::pex::policy::Policy lsst::ip::diffim::KernelCandidateDetection< PixelT >::_policy
private

Definition at line 52 of file KernelCandidateDetection.h.


The documentation for this class was generated from the following files: