SourceXtractorPlusPlus  0.10
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AutoPhotometryFlagTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * AutoPhotometryFlagTask.cpp
19  *
20  * Created on: Oct 10, 2018
21  * Author: Alejandro Alvarez Ayllon
22  */
23 
38 
39 
40 namespace SourceXtractor {
41 
42 namespace {
43 const SeFloat CROWD_THRESHOLD_AUTO = 0.1;
44 const SeFloat BADAREA_THRESHOLD_AUTO = 0.1;
45 }
46 
48 
51 
52  // get the detection frame
53  const auto& detection_frame = source.getProperty<DetectionFrame>().getFrame();
54 
55  // get the images and image information from the frame
56  const auto& detection_image = detection_frame->getSubtractedImage();
57  const auto& detection_variance = detection_frame->getVarianceMap();
58  const auto& variance_threshold = detection_frame->getVarianceThreshold();
59  const auto& threshold_image = detection_frame->getThresholdedImage();
60 
61  // get the object center
62  const auto& centroid_x = source.getProperty<PixelCentroid>().getCentroidX();
63  const auto& centroid_y = source.getProperty<PixelCentroid>().getCentroidY();
64 
65  // get the shape parameters
66  const auto& cxx = source.getProperty<ShapeParameters>().getEllipseCxx();
67  const auto& cyy = source.getProperty<ShapeParameters>().getEllipseCyy();
68  const auto& cxy = source.getProperty<ShapeParameters>().getEllipseCxy();
69 
70  // get the pixel list
71  const auto& pix_list = source.getProperty<PixelCoordinateList>().getCoordinateList();
72 
73  // get the kron-radius
74  SeFloat kron_radius_auto = m_kron_factor * source.getProperty<KronRadius>().getKronRadius();
75  if (kron_radius_auto < m_kron_minrad)
76  kron_radius_auto = m_kron_minrad;
77 
78  // create the elliptical aperture
79  auto ell_aper = std::make_shared<EllipticalAperture>(cxx, cyy, cxy, kron_radius_auto);
80 
81  // get the aperture borders on the image
82  const auto& min_pixel = ell_aper->getMinPixel(centroid_x, centroid_y);
83  const auto& max_pixel = ell_aper->getMaxPixel(centroid_x, centroid_y);
84 
85  // get the neighbourhood information
86  NeighbourInfo neighbour_info(min_pixel, max_pixel, pix_list, threshold_image);
87 
88  long int area_sum = 0;
89  long int area_bad = 0;
90  long int area_full = 0;
91  Flags global_flag = Flags::NONE;
92 
93  // iterate over the aperture pixels
94  for (int pixel_y = min_pixel.m_y; pixel_y <= max_pixel.m_y; pixel_y++) {
95  for (int pixel_x = min_pixel.m_x; pixel_x <= max_pixel.m_x; pixel_x++) {
96  SeFloat variance_tmp = 0;
97 
98  // check whether the pixel is in the ellipse
99  if (ell_aper->getArea(centroid_x, centroid_y, pixel_x, pixel_y) > 0) {
100 
101  // check whether the pixel is inside the image
102  if (pixel_x >= 0 && pixel_y >= 0 && pixel_x < detection_image->getWidth() &&
103  pixel_y < detection_image->getHeight()) {
104 
105  // enhance the area
106  area_sum += 1;
107 
108  // check whether the pixel is OK
109  variance_tmp = detection_variance ? detection_variance->getValue(pixel_x, pixel_y) : 1;
110  if (neighbour_info.isNeighbourObjectPixel(pixel_x, pixel_y) || variance_tmp > variance_threshold) {
111  // enhance the area affected by a defect
112  if (neighbour_info.isNeighbourObjectPixel(pixel_x, pixel_y))
113  area_full += 1;
114  if (variance_tmp > variance_threshold)
115  area_bad += 1;
116  }
117  } else {
118  // set the border flag
119  global_flag |= Flags::BOUNDARY;
120  }
121  }
122  }
123  }
124 
125  if (area_sum > 0) {
126  // check/set the bad area flag
127  if ((SeFloat) area_bad / (SeFloat) area_sum > BADAREA_THRESHOLD_AUTO)
128  global_flag |= Flags::BIASED;
129 
130  // check/set the crowded area flag
131  if ((SeFloat) area_full / (SeFloat) area_sum > CROWD_THRESHOLD_AUTO)
132  global_flag |= Flags::NEIGHBORS;
133  }
134 
135  // set the source properties
136  source.setProperty<AutoPhotometryFlag>(global_flag);
137 
138  // Draw the aperture
139  auto aperture_check_img = CheckImages::getInstance().getAutoApertureImage();
140  if (aperture_check_img) {
141  auto src_id = source.getProperty<SourceID>().getId();
142 
143  for (int y = min_pixel.m_y; y <= max_pixel.m_y; ++y) {
144  for (int x = min_pixel.m_x; x <= max_pixel.m_x; ++x) {
145  if (ell_aper->getArea(centroid_x, centroid_y, x, y) > 0) {
146  if (x >= 0 && y >= 0 && x < aperture_check_img->getWidth() && y < aperture_check_img->getHeight()) {
147  aperture_check_img->setValue(x, y, src_id);
148  }
149  }
150  }
151  }
152  }
153 }
154 
155 }
std::shared_ptr< WriteableImage< unsigned int > > getAutoApertureImage() const
Definition: CheckImages.h:64
The object has neighbors, bright and close enough.
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
SeFloat32 SeFloat
Definition: Types.h:32
The centroid of all the pixels in the source, weighted by their DetectionImage pixel values...
Definition: PixelCentroid.h:37
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
bool isNeighbourObjectPixel(int x, int y) const
static CheckImages & getInstance()
Definition: CheckImages.h:114
The object is truncated (too close to an image boundary)
T lock(T...args)
The object has bad pixels.
Flags
Flagging of bad sources.
Definition: SourceFlags.h:34
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
The SourceInterface is an abstract &quot;source&quot; that has properties attached to it.