SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NeighbourInfo.cpp
Go to the documentation of this file.
1 
17 /*
18  * NeighbourInfo.cpp
19  *
20  * Created on: Oct 12, 2018
21  * Author: Alejandro Alvarez
22  */
23 
25 
26 namespace SourceXtractor {
27 
31  : m_offset{min_pixel} {
32  auto width = max_pixel.m_x - min_pixel.m_x + 1;
33  auto height = max_pixel.m_y - min_pixel.m_y + 1;
34  m_neighbour_image = VectorImage<int>::create(width, height);
35 
36  for (auto& pixel_coord : pixel_list) {
37  auto act_x = pixel_coord.m_x - m_offset.m_x;
38  auto act_y = pixel_coord.m_y - m_offset.m_y;
39 
40  if (act_x >= 0 && act_y >= 0 && act_x < width && act_y < height) {
41  m_neighbour_image->setValue(act_x, act_y, -1);
42  }
43  }
44 
45  for (int act_y = 0; act_y < height; ++act_y) {
46  for (int act_x = 0; act_x < width; ++act_x) {
47  int offset_x = act_x + m_offset.m_x;
48  int offset_y = act_y + m_offset.m_y;
49 
50  // set surrounding pixels that do not belong to the image and are above the threshold to 1, all others to 0
51  if (offset_x >= 0 && offset_y >= 0 && offset_x < threshold_image->getWidth() &&
52  offset_y < threshold_image->getHeight()) {
53  if (threshold_image->getValue(offset_x, offset_y) > 0) {
54  if (m_neighbour_image->getValue(act_x, act_y) != -1) {
55  m_neighbour_image->setValue(act_x, act_y, 1);
56  }
57  else {
58  m_neighbour_image->setValue(act_x, act_y, 0);
59  }
60  }
61  else {
62  m_neighbour_image->setValue(act_x, act_y, 0);
63  }
64  }
65  }
66  }
67 }
68 
70  int act_x = x - m_offset.m_x;
71  int act_y = y - m_offset.m_y;
72  assert(act_x >= 0 && act_y >= 0 && act_x < m_neighbour_image->getWidth() && act_y < m_neighbour_image->getHeight());
73  return m_neighbour_image->getValue(act_x, act_y);
74 }
75 
76 } // end SourceXtractor
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< VectorImage< int > > m_neighbour_image
Definition: NeighbourInfo.h:46
static std::shared_ptr< VectorImage< T > > create(Args &&...args)
Definition: VectorImage.h:89
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
bool isNeighbourObjectPixel(int x, int y) const
NeighbourInfo(const PixelCoordinate &min_pixel, const PixelCoordinate &max_pixel, const std::vector< PixelCoordinate > &pixel_list, const std::shared_ptr< Image< SeFloat >> &threshold_image)
A pixel coordinate made of two integers m_x and m_y.
Interface representing an image.
Definition: Image.h:43