LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
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.
 
virtual void analyze ()
 Generate eigenimages that are normalised and background-subtracted.
 
void addImage (std::shared_ptr< ImageT > img, double flux=0.0)
 Add an image to the set to be analyzed.
 
ImageList getImageList () const
 Return the list of images being analyzed.
 
lsst::geom::Extent2I const getDimensions () const
 Return the dimension of the images being analyzed.
 
std::shared_ptr< ImageT > getMean () const
 Return the mean of the images in ImagePca's list.
 
virtual double updateBadPixels (unsigned long mask, int const ncomp)
 Update the bad pixels (i.e.
 
std::vector< double > const & getEigenValues () const
 Return Eigen values.
 
ImageList const & getEigenImages () const
 Return Eigen images.
 

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)
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) {
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
118 background = afw::math::makeStatistics(edgePixels, afw::math::MEDIAN).getValue();
119 }
120 *eImage -= background;
121 }
122 }
123}
int min
int end
int max
uint64_t * ptr
Definition RangeSet.cc:95
int y
Definition SpanSet.cc:48
ImageList const & getEigenImages() const
Return Eigen images.
Definition ImagePca.h:100
std::vector< std::shared_ptr< ImageT > > ImageList
Definition ImagePca.h:47
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
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:361
@ MIN
estimate sample minimum
Definition Statistics.h:66
@ MEDIAN
estimate sample median
Definition Statistics.h:60
@ MAX
estimate sample maximum
Definition Statistics.h:67

◆ 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 ( ) const
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 ( ) const
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 begin(T... args)
T end(T... args)
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 385 of file ImagePca.cc.

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

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