Skip to content

Commit 9db6de7

Browse files
committed
DownSampledImagePsf renormalization
1 parent db67dd8 commit 9db6de7

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

SEImplementation/SEImplementation/Image/DownSampledImagePsf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ namespace SourceXtractor {
4141
class DownSampledImagePsf {
4242
public:
4343

44-
DownSampledImagePsf(double pixel_scale, std::shared_ptr<VectorImage<SeFloat>> image, double down_scaling=1.0);
44+
DownSampledImagePsf(double pixel_scale, std::shared_ptr<VectorImage<SeFloat>> image,
45+
double down_scaling=1.0, bool normalize_psf = true);
4546

4647
virtual ~DownSampledImagePsf() = default;
4748

4849
double getPixelScale() const;
50+
4951
std::size_t getSize() const;
5052
std::shared_ptr<VectorImage<SourceXtractor::SeFloat>> getScaledKernel(SeFloat scale) const;
5153
void convolve(std::shared_ptr<WriteableImage<float>> image) const;
@@ -57,6 +59,7 @@ class DownSampledImagePsf {
5759
private:
5860
double m_down_scaling;
5961
std::shared_ptr<ImagePsf> m_psf;
62+
bool m_normalize_psf { true };
6063
};
6164

6265
} // end of SourceXtractor

SEImplementation/src/lib/Image/DownSampledImagePsf.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
namespace SourceXtractor {
3131

3232
DownSampledImagePsf::DownSampledImagePsf(
33-
double pixel_scale, std::shared_ptr<VectorImage<SeFloat>> image, double down_scaling)
34-
: m_down_scaling(down_scaling) {
33+
double pixel_scale, std::shared_ptr<VectorImage<SeFloat>> image, double down_scaling, bool normalize_psf)
34+
: m_down_scaling(down_scaling), m_normalize_psf(normalize_psf) {
3535
if (image != nullptr) {
3636
using Traits = ::ModelFitting::ImageTraits<std::shared_ptr<VectorImage<SeFloat>>>;
3737

@@ -52,9 +52,16 @@ DownSampledImagePsf::DownSampledImagePsf(
5252
Traits::addImageToImage(new_image, image, down_scaling, new_size / 2.0, new_size / 2.0);
5353

5454
// renormalize psf
55-
auto psf_sum = std::accumulate(new_image->getData().begin(), new_image->getData().end(), 0.);
56-
for (auto& pixel : new_image->getData()) {
57-
pixel /= psf_sum;
55+
if (m_normalize_psf) {
56+
auto psf_sum = std::accumulate(new_image->getData().begin(), new_image->getData().end(), 0.);
57+
for (auto& pixel : new_image->getData()) {
58+
pixel /= psf_sum;
59+
}
60+
} else {
61+
double area_factor = 1.0 / (down_scaling * down_scaling);
62+
for (auto& pixel : new_image->getData()) {
63+
pixel *= area_factor;
64+
}
5865
}
5966

6067
m_psf = std::make_shared<ImagePsf>(pixel_scale / down_scaling, new_image);

0 commit comments

Comments
 (0)