SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
DownSampledImagePsf.cpp
Go to the documentation of this file.
1
17/*
18 * DownSampledImagePsf.cpp
19 *
20 * Created on: Nov 9, 2021
21 * Author: mschefer
22 */
23
24#include <numeric>
25#include <iostream>
26
29
30namespace SourceXtractor {
31
34 : m_down_scaling(down_scaling) {
35 if (image != nullptr) {
37
38 if (image->getWidth() != image->getHeight()) {
39 throw Elements::Exception() << "PSF kernel must be square but was "
40 << image->getWidth() << " x " << image->getHeight();
41 }
42 if (image->getWidth() % 2 == 0) {
43 throw Elements::Exception() << "PSF kernel must have odd size, but got "
44 << image->getWidth();
45 }
46
47 if (down_scaling != 1.0) {
48 int new_size = image->getWidth() * down_scaling;
49 new_size += (new_size % 2 == 0) ? 1 : 0;
50
53
54 // 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;
58 }
59
61 } else {
63 }
64 } else {
65 m_down_scaling = 1.0;
66 }
67}
68
70 if (m_psf != nullptr) {
71 return m_psf->getPixelScale();
72 } else {
73 return 1.0;
74 }
75}
76
78 if (m_psf != nullptr) {
79 return m_psf->getWidth();
80 } else {
81 return 1;
82 }
83}
84
86 if (m_psf != nullptr) {
87 return m_psf->getScaledKernel(scale);
88 } else {
89 return nullptr;
90 }
91}
92
94 if (m_psf != nullptr) {
95 m_psf->convolve(image);
96 }
97}
98
100 const std::shared_ptr<const Image<SeFloat>>& model_ptr) const {
101 if (m_psf != nullptr) {
102 return m_psf->prepare(model_ptr);
103 } else {
104 return nullptr;
105 }
106}
107
114
115
116}
117
const double pixel_scale
Definition TestImage.cpp:74
T accumulate(T... args)
std::shared_ptr< ImagePsf > m_psf
std::shared_ptr< VectorImage< SourceXtractor::SeFloat > > getScaledKernel(SeFloat scale) const
std::unique_ptr< DFTConvolution< SeFloat >::ConvolutionContext > prepare(const std::shared_ptr< const Image< SeFloat > > &model_ptr) const
void convolve(std::shared_ptr< WriteableImage< float > > image) const
DownSampledImagePsf(double pixel_scale, std::shared_ptr< VectorImage< SeFloat > > image, double down_scaling=1.0)
SeFloat32 SeFloat
Definition Types.h:32
static void addImageToImage(ImageInterfaceTypePtr &target_image, const ImageInterfaceTypePtr &source_image, double scale_factor, double x, double y)
static ImageInterfaceTypePtr factory(std::size_t width, std::size_t height)