SourceXtractorPlusPlus
0.15
Please provide a description of the project.
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
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
static
T
getMaskedValue
(
int
x
,
int
y
,
const
VectorImage<T>
& img, T invalid) {
24
auto
v = img.
getValue
(x, y);
25
if
(v != invalid)
26
return
v;
27
28
auto
min_distance =
std::numeric_limits<T>::max
();
29
30
T acc = 0;
31
size_t
count
= 0;
32
33
for
(
int
iy = 0; iy < img.
getHeight
(); ++iy) {
34
for
(
int
ix = 0; ix < img.
getWidth
(); ++ix) {
35
v = img.
getValue
(ix, iy);
36
if
(v != invalid) {
37
auto
dx
= x - ix;
38
auto
dy
= y - iy;
39
auto
distance
=
dx
*
dx
+
dy
*
dy
;
40
// This pixel is closer than the last close one, so restart
41
if
(
distance
< min_distance) {
42
acc = v;
43
count = 1;
44
min_distance =
distance
;
45
}
46
// This pixel is as close as the closest one, so take it into account
47
else
if
(
distance
- min_distance <=
std::numeric_limits<T>::epsilon
()) {
48
acc += v;
49
++count;
50
}
51
}
52
}
53
}
54
55
// Take the average
56
if
(count > 0)
57
acc /= count;
58
59
return
acc;
60
}
61
62
template
<
typename
T>
63
std::shared_ptr<VectorImage<T>
>
ReplaceUndef
(
const
VectorImage<T>
& original, T mask) {
64
auto
output =
VectorImage<T>::create
(original.
getWidth
(), original.
getHeight
());
65
for
(
int
y
= 0;
y
< original.
getHeight
(); ++
y
) {
66
for
(
int
x
= 0;
x
< original.
getWidth
(); ++
x
) {
67
output->at(
x
,
y
) =
getMaskedValue
(
x
,
y
, original, mask);
68
}
69
}
70
return
output;
71
}
72
73
// Instantiation
74
template
std::shared_ptr<VectorImage<SeFloat>
>
ReplaceUndef
(
const
VectorImage<SeFloat>&,
SeFloat
);
75
76
}
// end of namespace SourceXtractor
77
78
#include "
SEFramework/Image/ImageAccessor.h
"
SourceXtractor::ReplaceUndef
std::shared_ptr< VectorImage< T > > ReplaceUndef(const VectorImage< T > &original, T mask)
Definition:
ReplaceUndefImage.cpp:63
std::shared_ptr
std::distance
T distance(T...args)
SourceXtractor::VectorImage::getHeight
int getHeight() const final
Returns the height of the image in pixels.
Definition:
VectorImage.h:108
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition:
MoffatModelFittingTask.cpp:94
ImageAccessor.h
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition:
Types.h:32
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&...args)
Definition:
VectorImage.h:100
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition:
MoffatModelFittingTask.cpp:94
SourceXtractor::VectorImage
Image implementation which keeps the pixel values in memory.
Definition:
VectorImage.h:52
SourceXtractor::VectorImage::getWidth
int getWidth() const final
Returns the width of the image in pixels.
Definition:
VectorImage.h:112
ReplaceUndefImage.h
SourceXtractor::VectorImage::getValue
T getValue(int x, int y) const
Definition:
VectorImage.h:116
std::numeric_limits::max
T max(T...args)
SourceXtractor::getMaskedValue
static T getMaskedValue(int x, int y, const VectorImage< T > &img, T invalid)
Definition:
ReplaceUndefImage.cpp:23
std::count
T count(T...args)
dx
std::shared_ptr< EngineParameter > dx
Definition:
MoffatModelFittingTask.cpp:93
dy
std::shared_ptr< EngineParameter > dy
Definition:
MoffatModelFittingTask.cpp:93
std::numeric_limits
Generated by
1.8.5