SourceXtractorPlusPlus  0.16
Please provide a description of the project.
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 
30 namespace SourceXtractor {
31 
33  double pixel_scale, std::shared_ptr<VectorImage<SeFloat>> image, double down_scaling)
34  : m_down_scaling(down_scaling) {
35 
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 
51  auto new_image = Traits::factory(new_size, new_size);
52  Traits::addImageToImage(new_image, image, down_scaling, new_size / 2.0, new_size / 2.0);
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 
60  m_psf = std::make_shared<ImagePsf>(pixel_scale / down_scaling, new_image);
61  } else {
62  m_psf = std::make_shared<ImagePsf>(pixel_scale, image);
63  }
64 }
65 
67  return m_psf->getPixelScale();
68 }
69 
71  return m_psf->getWidth();
72 }
73 
75  return m_psf->getScaledKernel(scale);
76 }
77 
79  m_psf->convolve(image);
80 }
81 
83  const std::shared_ptr<const Image<SeFloat>>& model_ptr) const {
84  return m_psf->prepare(model_ptr);
85 }
86 
89  m_psf->convolve(image, context);
90 }
91 
92 
93 }
94 
const double pixel_scale
Definition: TestImage.cpp:74
T accumulate(T... args)
void convolve(std::shared_ptr< WriteableImage< float >> image) const
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
DownSampledImagePsf(double pixel_scale, std::shared_ptr< VectorImage< SeFloat >> image, double down_scaling=1.0)
Interface representing an image.
Definition: Image.h:43
Image implementation which keeps the pixel values in memory.
Definition: VectorImage.h:52
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)