SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Image
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
27
#include "
SEImplementation/Image/ImageInterfaceTraits.h
"
28
#include "
SEImplementation/Image/DownSampledImagePsf.h
"
29
30
namespace
SourceXtractor
{
31
32
DownSampledImagePsf::DownSampledImagePsf
(
33
double
pixel_scale
,
std::shared_ptr
<
VectorImage<SeFloat>
>
image
,
double
down_scaling
)
34
: m_down_scaling(
down_scaling
) {
35
if
(
image
!=
nullptr
) {
36
using
Traits
=
::ModelFitting::ImageTraits<std::shared_ptr<VectorImage<SeFloat>
>>;
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
}
else
{
65
m_down_scaling
= 1.0;
66
}
67
}
68
69
double
DownSampledImagePsf::getPixelScale
()
const
{
70
if
(
m_psf
!=
nullptr
) {
71
return
m_psf
->getPixelScale();
72
}
else
{
73
return
1.0;
74
}
75
}
76
77
std::size_t
DownSampledImagePsf::getSize
()
const
{
78
if
(
m_psf
!=
nullptr
) {
79
return
m_psf
->getWidth();
80
}
else
{
81
return
1;
82
}
83
}
84
85
std::shared_ptr<VectorImage<SourceXtractor::SeFloat>
>
DownSampledImagePsf::getScaledKernel
(
SeFloat
scale)
const
{
86
if
(
m_psf
!=
nullptr
) {
87
return
m_psf
->getScaledKernel(scale);
88
}
else
{
89
return
nullptr
;
90
}
91
}
92
93
void
DownSampledImagePsf::convolve
(
std::shared_ptr
<
WriteableImage<float>
>
image
)
const
{
94
if
(
m_psf
!=
nullptr
) {
95
m_psf
->convolve(
image
);
96
}
97
}
98
99
std::unique_ptr<DFTConvolution<SeFloat>::ConvolutionContext
>
DownSampledImagePsf::prepare
(
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
108
void
DownSampledImagePsf::convolve
(
std::shared_ptr
<
WriteableImage<float>
>
image
,
109
std::unique_ptr
<
DFTConvolution<SeFloat>::ConvolutionContext
>&
context
)
const
{
110
if
(
m_psf
!=
nullptr
) {
111
m_psf
->convolve(
image
,
context
);
112
}
113
}
114
115
116
}
117
DownSampledImagePsf.h
ImageInterfaceTraits.h
pixel_scale
const double pixel_scale
Definition
TestImage.cpp:74
std::accumulate
T accumulate(T... args)
Elements::Exception
SourceXtractor::DownSampledImagePsf::m_psf
std::shared_ptr< ImagePsf > m_psf
Definition
DownSampledImagePsf.h:59
SourceXtractor::DownSampledImagePsf::getPixelScale
double getPixelScale() const
Definition
DownSampledImagePsf.cpp:69
SourceXtractor::DownSampledImagePsf::m_down_scaling
double m_down_scaling
Definition
DownSampledImagePsf.h:58
SourceXtractor::DownSampledImagePsf::getScaledKernel
std::shared_ptr< VectorImage< SourceXtractor::SeFloat > > getScaledKernel(SeFloat scale) const
Definition
DownSampledImagePsf.cpp:85
SourceXtractor::DownSampledImagePsf::prepare
std::unique_ptr< DFTConvolution< SeFloat >::ConvolutionContext > prepare(const std::shared_ptr< const Image< SeFloat > > &model_ptr) const
Definition
DownSampledImagePsf.cpp:99
SourceXtractor::DownSampledImagePsf::convolve
void convolve(std::shared_ptr< WriteableImage< float > > image) const
Definition
DownSampledImagePsf.cpp:93
SourceXtractor::DownSampledImagePsf::getSize
std::size_t getSize() const
Definition
DownSampledImagePsf.cpp:77
SourceXtractor::DownSampledImagePsf::DownSampledImagePsf
DownSampledImagePsf(double pixel_scale, std::shared_ptr< VectorImage< SeFloat > > image, double down_scaling=1.0)
Definition
DownSampledImagePsf.cpp:32
std::function
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition
Types.h:32
std::shared_ptr
std::size_t
ModelFitting::ImageTraits< ImageInterfaceTypePtr >
Definition
ImageInterfaceTraits.h:56
ModelFitting::ImageTraits< ImageInterfaceTypePtr >::addImageToImage
static void addImageToImage(ImageInterfaceTypePtr &target_image, const ImageInterfaceTypePtr &source_image, double scale_factor, double x, double y)
Definition
ImageInterfaceTraits.cpp:318
ModelFitting::ImageTraits< ImageInterfaceTypePtr >::factory
static ImageInterfaceTypePtr factory(std::size_t width, std::size_t height)
Definition
ImageInterfaceTraits.h:60
SourceXtractor::DFTConvolution::ConvolutionContext
Definition
DFT.h:57
std::unique_ptr
Generated by
1.10.0