SourceXtractorPlusPlus  0.15
Please provide a description of the project.
ReplaceUndefImage.cpp
Go to the documentation of this file.
1 
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>
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 
std::shared_ptr< EngineParameter > dx
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
std::shared_ptr< EngineParameter > dy
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.
Definition: VectorImage.h:112
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:100
int getHeight() const final
Returns the height of the image in pixels.
Definition: VectorImage.h:108
T getValue(int x, int y) const
Definition: VectorImage.h:116
T count(T... args)
T distance(T... args)
T max(T... args)
SeFloat32 SeFloat
Definition: Types.h:32
static T getMaskedValue(int x, int y, const VectorImage< T > &img, T invalid)
std::shared_ptr< VectorImage< T > > ReplaceUndef(const VectorImage< T > &original, T mask)