LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | List of all members
lsst::meas::algorithms::PsfImagePca< ImageT > Class Template Reference

#include <ImagePca.h>

Inheritance diagram for lsst::meas::algorithms::PsfImagePca< ImageT >:
lsst::afw::image::ImagePca< ImageT >

Public Types

using ImageList = std::vector< std::shared_ptr< ImageT > >
 

Public Member Functions

 PsfImagePca (bool constantWeight=true, int border=3)
 Ctor. More...
 
virtual void analyze ()
 Generate eigenimages that are normalised and background-subtracted. More...
 
void addImage (std::shared_ptr< ImageT > img, double flux=0.0)
 Add an image to the set to be analyzed. More...
 
ImageList getImageList () const
 Return the list of images being analyzed. More...
 
lsst::geom::Extent2I const getDimensions () const
 Return the dimension of the images being analyzed. More...
 
std::shared_ptr< ImageT > getMean () const
 Return the mean of the images in ImagePca's list. More...
 
virtual double updateBadPixels (unsigned long mask, int const ncomp)
 Update the bad pixels (i.e. More...
 
std::vector< double > const & getEigenValues () const
 Return Eigen values. More...
 
ImageList const & getEigenImages () const
 Return Eigen images. More...
 

Detailed Description

template<typename ImageT>
class lsst::meas::algorithms::PsfImagePca< ImageT >

Definition at line 45 of file ImagePca.h.

Member Typedef Documentation

◆ ImageList

template<typename ImageT >
using lsst::afw::image::ImagePca< ImageT >::ImageList = std::vector<std::shared_ptr<ImageT> >
inherited

Definition at line 47 of file ImagePca.h.

Constructor & Destructor Documentation

◆ PsfImagePca()

template<typename ImageT >
lsst::meas::algorithms::PsfImagePca< ImageT >::PsfImagePca ( bool  constantWeight = true,
int  border = 3 
)
inlineexplicit

Ctor.

Definition at line 49 of file ImagePca.h.

50  : Super(constantWeight), _border(border) {}

Member Function Documentation

◆ addImage()

template<typename ImageT >
void lsst::afw::image::ImagePca< ImageT >::addImage ( std::shared_ptr< ImageT >  img,
double  flux = 0.0 
)
inherited

Add an image to the set to be analyzed.

Parameters
imgImage to add to set
fluxImage's flux
Exceptions
lsst::pex::exceptions::LengthErrorif all the images aren't the same size

Definition at line 64 of file ImagePca.cc.

64  {
65  if (_imageList.empty()) {
66  _dimensions = img->getDimensions();
67  } else {
68  if (getDimensions() != img->getDimensions()) {
70  (boost::format("Dimension mismatch: saw %dx%d; expected %dx%d") %
71  img->getWidth() % img->getHeight() % _dimensions.getX() % _dimensions.getY())
72  .str());
73  }
74  }
75 
76  if (flux == 0.0) {
77  throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError, "Flux may not be zero");
78  }
79 
80  _imageList.push_back(img);
81  _fluxList.push_back(flux);
82 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::geom::Extent2I const getDimensions() const
Return the dimension of the images being analyzed.
Definition: ImagePca.h:75
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
Reports attempts to access elements outside a valid range of indices.
Definition: Runtime.h:89
T empty(T... args)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
T push_back(T... args)

◆ analyze()

template<typename ImageT >
void lsst::meas::algorithms::PsfImagePca< ImageT >::analyze
virtual

Generate eigenimages that are normalised and background-subtracted.

The background subtraction ensures PSF variation doesn't couple with small background errors.

Reimplemented from lsst::afw::image::ImagePca< ImageT >.

Definition at line 41 of file ImagePca.cc.

41  {
43 
44  typename Super::ImageList const &eImageList = this->getEigenImages();
45  typename Super::ImageList::const_iterator iter = eImageList.begin(), end = eImageList.end();
46  for (size_t i = 0; iter != end; ++i, ++iter) {
47  std::shared_ptr<ImageT> eImage = *iter;
48 
49  /*
50  * Normalise eigenImages to have a maximum of 1.0. For n > 0 they
51  * (should) have mean == 0, so we can't use that to normalize
52  */
53  afw::math::Statistics stats = afw::math::makeStatistics(*eImage, (afw::math::MIN | afw::math::MAX));
54  double const min = stats.getValue(afw::math::MIN);
55  double const max = stats.getValue(afw::math::MAX);
56 
57  double const extreme = (fabs(min) > max) ? min : max;
58  if (extreme != 0.0) {
59  *eImage /= extreme;
60  }
61 
62  /*
63  * Estimate and subtract the mean background level from the i > 0
64  * eigen images; if we don't do that then PSF variation can get mixed
65  * with subtle variations in the background and potentially amplify
66  * them disasterously.
67  *
68  * It is not at all clear that doing this is a good idea; it'd be
69  * better to get the sky level right in the first place.
70  */
71  if (i > 0 && _border > 0) { /* not the zeroth KL component */
72  int const height = eImage->getHeight();
73  int const width = eImage->getWidth();
74  double background;
75  if (2 * _border >= std::min(height, width)) {
76  // _Border consumes the entire image
77  background = afw::math::makeStatistics(*afw::image::GetImage<ImageT>::getImage(eImage),
79  .getValue();
80  } else {
81  // Use the median of the edge pixels
82 
83  // If ImageT is a MaskedImage, unpack the Image
85  afw::image::GetImage<ImageT>::getImage(eImage);
86 
87  int const nEdge = width * height - (width - 2 * _border) * (height - 2 * _border);
88  std::vector<double> edgePixels(nEdge);
89 
90  std::vector<double>::iterator bi = edgePixels.begin();
91 
92  typedef typename afw::image::GetImage<ImageT>::type::x_iterator imIter;
93  int y = 0;
94  for (; y != _border; ++y) { // Bottom border of eImage
95  for (imIter ptr = eImageIm->row_begin(y), end = eImageIm->row_end(y); ptr != end;
96  ++ptr, ++bi) {
97  *bi = *ptr;
98  }
99  }
100  for (; y != height - _border; ++y) { // Left and right borders of eImage
101  for (imIter ptr = eImageIm->row_begin(y), end = eImageIm->x_at(_border, y); ptr != end;
102  ++ptr, ++bi) {
103  *bi = *ptr;
104  }
105  for (imIter ptr = eImageIm->x_at(width - _border, y), end = eImageIm->row_end(y);
106  ptr != end; ++ptr, ++bi) {
107  *bi = *ptr;
108  }
109  }
110  for (; y != height; ++y) { // Top border of eImage
111  for (imIter ptr = eImageIm->row_begin(y), end = eImageIm->row_end(y); ptr != end;
112  ++ptr, ++bi) {
113  *bi = *ptr;
114  }
115  }
116  assert(std::distance(edgePixels.begin(), bi) == nEdge);
117 
119  }
120  *eImage -= background;
121  }
122  }
123 }
int min
int end
int max
uint64_t * ptr
Definition: RangeSet.cc:88
int y
Definition: SpanSet.cc:48
T begin(T... args)
ImageList const & getEigenImages() const
Return Eigen images.
Definition: ImagePca.h:100
std::vector< std::shared_ptr< ImageT > > ImageList
Definition: ImagePca.h:47
virtual void analyze()
Definition: ImagePca.cc:123
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Definition: Statistics.cc:1047
T distance(T... args)
T fabs(T... args)
T min(T... args)
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition: Statistics.h:359
@ MIN
estimate sample minimum
Definition: Statistics.h:75
@ MEDIAN
estimate sample median
Definition: Statistics.h:69
@ MAX
estimate sample maximum
Definition: Statistics.h:76

◆ getDimensions()

template<typename ImageT >
lsst::geom::Extent2I const lsst::afw::image::ImagePca< ImageT >::getDimensions ( ) const
inlineinherited

Return the dimension of the images being analyzed.

Definition at line 75 of file ImagePca.h.

75 { return _dimensions; }

◆ getEigenImages()

template<typename ImageT >
ImageList const& lsst::afw::image::ImagePca< ImageT >::getEigenImages ( ) const
inlineinherited

Return Eigen images.

Definition at line 100 of file ImagePca.h.

100 { return _eigenImages; }

◆ getEigenValues()

template<typename ImageT >
std::vector<double> const& lsst::afw::image::ImagePca< ImageT >::getEigenValues ( ) const
inlineinherited

Return Eigen values.

Definition at line 98 of file ImagePca.h.

98 { return _eigenValues; }

◆ getImageList()

template<typename ImageT >
ImagePca< ImageT >::ImageList lsst::afw::image::ImagePca< ImageT >::getImageList
inherited

Return the list of images being analyzed.

Definition at line 85 of file ImagePca.cc.

85  {
86  return _imageList;
87 }

◆ getMean()

template<typename ImageT >
std::shared_ptr< ImageT > lsst::afw::image::ImagePca< ImageT >::getMean
inherited

Return the mean of the images in ImagePca's list.

Definition at line 90 of file ImagePca.cc.

90  {
91  if (_imageList.empty()) {
92  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError, "You haven't provided any images");
93  }
94 
95  std::shared_ptr<ImageT> mean(new ImageT(getDimensions()));
96  *mean = static_cast<typename ImageT::Pixel>(0);
97 
98  for (typename ImageList::const_iterator ptr = _imageList.begin(), end = _imageList.end(); ptr != end;
99  ++ptr) {
100  *mean += **ptr;
101  }
102  *mean /= _imageList.size();
103 
104  return mean;
105 }
T end(T... args)
float Pixel
Typedefs to be used for pixel values.
Definition: common.h:37
T size(T... args)

◆ updateBadPixels()

template<typename ImageT >
double lsst::afw::image::ImagePca< ImageT >::updateBadPixels ( unsigned long  mask,
int const  ncomp 
)
virtualinherited

Update the bad pixels (i.e.

those for which (value & mask) != 0) based on the current PCA decomposition; if none is available, use the mean of the good pixels

Parameters
maskMask defining bad pixels
ncompNumber of components to use in estimate
Returns
the maximum change made to any pixel

N.b. the work is actually done in do_updateBadPixels as the code only makes sense and compiles when we are doing a PCA on a set of MaskedImages

Definition at line 386 of file ImagePca.cc.

386  {
387  return do_updateBadPixels<ImageT>(typename ImageT::image_category(), _imageList, _fluxList, _eigenImages,
388  mask, ncomp);
389 }
afw::table::Key< afw::table::Array< MaskPixelT > > mask

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