SourceXtractorPlusPlus  0.15
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
98  source.setIndexedProperty<Vignet>(m_instance,
99  VectorImage<DetectionImage::PixelType>::create(m_vignet_size[0], m_vignet_size[1], std::move(vignet_vector)));
100 }
101 } // namespace SourceXtractor
PixelCoordinateList.h
DetectionFrameCoordinates.h
SourceXtractor::PixelCoordinateList
Definition: PixelCoordinateList.h:31
MeasurementFrameInfo.h
SourceXtractor::DetectionFrameImages
Definition: DetectionFrameImages.h:30
SourceXtractor::DetectionFrameImages::getLockedImage
std::shared_ptr< ImageAccessor< SeFloat > > getLockedImage(FrameImageLayer layer) const
Definition: DetectionFrameImages.h:38
std::move
T move(T... args)
MeasurementFramePixelCentroid.h
SourceXtractor::MeasurementFramePixelCentroid
Definition: MeasurementFramePixelCentroid.h:31
SourceXtractor::MeasurementFrameCoordinates
Definition: MeasurementFrameCoordinates.h:26
std::vector< SeFloat >
SourceXtractor::DetectionFrameCoordinates
Definition: DetectionFrameCoordinates.h:26
Vignet.h
VignetSourceTask.h
SourceXtractor::LayerVarianceMap
@ LayerVarianceMap
Definition: Frame.h:44
SourceXtractor::Vignet
Definition: Vignet.h:33
SourceXtractor::MeasurementFrameImages
Definition: MeasurementFrameImages.h:31
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::MeasurementFrameInfo
Definition: MeasurementFrameInfo.h:28
MeasurementFrameCoordinates.h
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:100
SourceXtractor::VignetSourceTask::m_vignet_default_pixval
SeFloat m_vignet_default_pixval
Definition: VignetSourceTask.h:45
SourceXtractor::VignetSourceTask::m_instance
unsigned m_instance
Definition: VignetSourceTask.h:43
SourceXtractor::VignetSourceTask::m_vignet_size
std::array< int, 2 > m_vignet_size
Definition: VignetSourceTask.h:44
SourceXtractor::VignetSourceTask::computeProperties
virtual void computeProperties(SourceInterface &source) const
Computes one or more properties for the Source.
Definition: VignetSourceTask.cpp:38
SourceXtractor::SourceInterface::getProperty
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
Definition: SourceInterface.h:57
SourceXtractor::LayerSubtractedImage
@ LayerSubtractedImage
Definition: Frame.h:38
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
PixelCentroid.h
MeasurementFrameImages.h
DetectionFrameImages.h
SourceXtractor::LayerThresholdedImage
@ LayerThresholdedImage
Definition: Frame.h:40