SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
ReplaceUndefImage.cpp
Go to the documentation of this file.
1
17
19
20namespace SourceXtractor {
21
22template<typename T>
23static 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
62template<typename T>
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
74template std::shared_ptr<VectorImage<SeFloat>> ReplaceUndef(const VectorImage<SeFloat>&, SeFloat);
75
76} // end of namespace SourceXtractor
77
Image implementation which keeps the pixel values in memory.
Definition VectorImage.h:52
int getWidth() const final
Returns the width of the image in pixels.
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
int getHeight() const final
Returns the height of the image in pixels.
T getValue(int x, int y) const
T count(T... args)
T distance(T... args)
T epsilon(T... args)
T max(T... args)
static T getMaskedValue(int x, int y, const VectorImage< T > &img, T invalid)
SeFloat32 SeFloat
Definition Types.h:32
std::shared_ptr< VectorImage< T > > ReplaceUndef(const VectorImage< T > &original, T mask)