LSST Applications g063fba187b+fee0456c91,g0f08755f38+ea96e5a5a3,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+90257ff92a,g20f6ffc8e0+ea96e5a5a3,g217e2c1bcf+937a289c59,g28da252d5a+daa7da44eb,g2bbee38e9b+253935c60e,g2bc492864f+253935c60e,g3156d2b45e+6e55a43351,g32e5bea42b+31359a2a7a,g347aa1857d+253935c60e,g35bb328faa+a8ce1bb630,g3a166c0a6a+253935c60e,g3b1af351f3+a8ce1bb630,g3e281a1b8c+c5dd892a6c,g414038480c+416496e02f,g41af890bb2+afe91b1188,g599934f4f4+0db33f7991,g7af13505b9+e36de7bce6,g80478fca09+da231ba887,g82479be7b0+a4516e59e3,g858d7b2824+ea96e5a5a3,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+bc6ab8dfbd,gb58c049af0+d64f4d3760,gc28159a63d+253935c60e,gcab2d0539d+3f2b72788c,gcf0d15dbbd+4ea9c45075,gda6a2b7d83+4ea9c45075,gdaeeff99f8+1711a396fd,ge79ae78c31+253935c60e,gef2f8181fd+3031e3cf99,gf0baf85859+c1f95f4921,gfa517265be+ea96e5a5a3,gfa999e8aa5+17cd334064,w.2024.50
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
std::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: