SourceXtractorPlusPlus
0.11
Please provide a description of the project.
SEImplementation
src
lib
Background
SE
ReplaceUndefImage.cpp
Go to the documentation of this file.
1
18
#include "
SEImplementation/Background/SE/ReplaceUndefImage.h
"
19
20
namespace
SourceXtractor
{
21
22
template
<
typename
T>
23
ReplaceUndefImage<T>::ReplaceUndefImage
(
const
std::shared_ptr
<
VectorImage<T>
>& image, T invalid)
24
: m_image{image}, m_invalid{invalid} {
25
}
26
27
template
<
typename
T>
28
std::string
ReplaceUndefImage<T>::getRepr
()
const
{
29
return
std::string
(
"ReplaceUndef("
+ m_image->getRepr() +
")"
);
30
}
31
32
template
<
typename
T>
33
int
ReplaceUndefImage<T>::getWidth
()
const
{
34
return
m_image->getWidth();
35
}
36
37
template
<
typename
T>
38
int
ReplaceUndefImage<T>::getHeight
()
const
{
39
return
m_image->getHeight();
40
}
41
42
template
<
typename
T>
43
T
ReplaceUndefImage<T>::getValue
(
int
x
,
int
y
)
const
{
44
auto
v = m_image->getValue(
x
,
y
);
45
if
(v != m_invalid)
46
return
v;
47
48
auto
min_distance =
std::numeric_limits<T>::max
();
49
50
T acc = 0;
51
size_t
count
= 0;
52
53
for
(
int
iy = 0; iy < m_image->getHeight(); ++iy) {
54
for
(
int
ix = 0; ix < m_image->getWidth(); ++ix) {
55
v = m_image->getValue(ix, iy);
56
if
(v != m_invalid) {
57
auto
dx
=
x
- ix;
58
auto
dy
=
y
- iy;
59
auto
distance
=
dx
*
dx
+
dy
*
dy
;
60
// This pixel is closer than the last close one, so restart
61
if
(
distance
< min_distance) {
62
acc = v;
63
count
= 1;
64
min_distance =
distance
;
65
}
66
// This pixel is as close as the closest one, so take it into account
67
else
if
(
distance
- min_distance <=
std::numeric_limits<T>::epsilon
()) {
68
acc += v;
69
++
count
;
70
}
71
}
72
}
73
}
74
75
// Take the average
76
if
(
count
> 0)
77
acc /=
count
;
78
79
return
acc;
80
}
81
82
template
83
class
ReplaceUndefImage<SeFloat>
;
84
85
}
// end of namespace SourceXtractor
std::string
STL class.
std::shared_ptr
STL class.
SourceXtractor::ReplaceUndefImage::getWidth
int getWidth() const final
Returns the width of the image in pixels.
Definition:
ReplaceUndefImage.cpp:33
std::distance
T distance(T... args)
SourceXtractor::ReplaceUndefImage::getRepr
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
Definition:
ReplaceUndefImage.cpp:28
SourceXtractor::ReplaceUndefImage::getValue
T getValue(int x, int y) const final
Returns the value of the pixel with the coordinates (x,y)
Definition:
ReplaceUndefImage.cpp:43
SourceXtractor
Definition:
Aperture.h:30
dy
std::shared_ptr< EngineParameter > dy
Definition:
MoffatModelFittingTask.cpp:92
SourceXtractor::ReplaceUndefImage::getHeight
int getHeight() const final
Returns the height of the image in pixels.
Definition:
ReplaceUndefImage.cpp:38
ReplaceUndefImage.h
SourceXtractor::ReplaceUndefImage
Definition:
ReplaceUndefImage.h:31
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition:
MoffatModelFittingTask.cpp:93
SourceXtractor::VectorImage
Image implementation which keeps the pixel values in memory.
Definition:
VectorImage.h:53
SourceXtractor::ReplaceUndefImage::ReplaceUndefImage
ReplaceUndefImage(const std::shared_ptr< VectorImage< T >> &image, T invalid)
Definition:
ReplaceUndefImage.cpp:23
std::count
T count(T... args)
std::numeric_limits::max
T max(T... args)
dx
std::shared_ptr< EngineParameter > dx
Definition:
MoffatModelFittingTask.cpp:92
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition:
MoffatModelFittingTask.cpp:93
std::numeric_limits
Generated by
1.8.18