SourceXtractorPlusPlus  0.12
Please provide a description of the project.
VignetSourceTask.cpp
Go to the documentation of this file.
1 
33 
36 
37 namespace SourceXtractor {
39  const auto& measurement_frame_info = source.getProperty<MeasurementFrameInfo>(m_instance);
40  const auto& measurement_frame_images = source.getProperty<MeasurementFrameImages>(m_instance);
41 
42  auto measurement_var_threshold = measurement_frame_info.getVarianceThreshold();
43 
44  const auto measurement_sub_image = measurement_frame_images.getLockedImage(LayerSubtractedImage);
45  const auto measurement_var_image = measurement_frame_images.getLockedImage(LayerVarianceMap);
46 
47  // neighbor masking from the detection image
48  const auto& detection_frame_images = source.getProperty<DetectionFrameImages>();
49  const auto& detection_thresh_image = detection_frame_images.getLockedImage(LayerThresholdedImage);
50 
51  // get the object pixel coordinates from the detection image
52  const auto& pixel_coords = source.getProperty<PixelCoordinateList>();
53 
54  // coordinate systems
55  auto detection_coordinate_system = source.getProperty<DetectionFrameCoordinates>().getCoordinateSystem();
56  auto measurement_coordinate_system = source.getProperty<MeasurementFrameCoordinates>(m_instance).getCoordinateSystem();
57 
58  // get the central pixel coord
59  const auto& centroid = source.getProperty<MeasurementFramePixelCentroid>(m_instance);
60  const int x_pix = static_cast<int>(centroid.getCentroidX() + 0.5);
61  const int y_pix = static_cast<int>(centroid.getCentroidY() + 0.5);
62 
63  // get the sub-image boundaries
64  int x_start = x_pix - m_vignet_size[0] / 2;
65  int y_start = y_pix - m_vignet_size[1] / 2;
66  int x_end = x_start + m_vignet_size[0];
67  int y_end = y_start + m_vignet_size[1];
68 
69  // create and fill the vignet vector using the measurement frame
71  int index = 0;
72  for (int iy = y_start; iy < y_end; iy++) {
73  for (int ix = x_start; ix < x_end; ix++, index++) {
74 
75  // skip pixels outside of the image
76  if (ix < 0 || iy < 0 || ix >= measurement_sub_image->getWidth() || iy >= measurement_sub_image->getHeight())
77  continue;
78 
79  // translate pixel coordinates to the detection frame
80  auto world_coord = measurement_coordinate_system->imageToWorld({static_cast<double>(ix), static_cast<double>(iy)});
81  auto detection_coord = detection_coordinate_system->worldToImage(world_coord);
82 
83  // copy the pixel value if it is not masked, and if it does not correspond to a detection pixel
84  // if it corresponds to a detection pixel, use it if it belongs to the source
85  int detection_x = static_cast<int>(detection_coord.m_x + 0.5);
86  int detection_y = static_cast<int>(detection_coord.m_y + 0.5);
87 
88  bool is_masked = measurement_var_image->getValue(ix, iy) > measurement_var_threshold;
89  bool is_detection_pixel = detection_thresh_image->getValue(detection_x, detection_y) > 0;
90 
91  if (!is_masked && (!is_detection_pixel || pixel_coords.contains({detection_x, detection_y}))) {
92  vignet_vector[index] = measurement_sub_image->getValue(ix, iy);
93  }
94  }
95  }
96 
97  // set the property
100 }
101 } // namespace SourceXtractor
std::shared_ptr< Image< SeFloat > > getLockedImage(FrameImageLayer layer) const
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:89
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
T move(T... args)
void setIndexedProperty(std::size_t index, Args... args)
Convenience template method to call setProperty() with a more user-friendly syntax.
std::array< int, 2 > m_vignet_size
virtual void computeProperties(SourceInterface &source) const
Computes one or more properties for the Source.
The SourceInterface is an abstract "source" that has properties attached to it.