SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShapeParametersTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * ShapeParametersTask.cpp
19  *
20  * Created on: Jan 27, 2017
21  * Author: mschefer
22  */
23 
24 #include <iostream>
25 
31 
33 
34 namespace SourceXtractor {
35 
37  const auto& pixel_values = source.getProperty<DetectionFramePixelValues>().getFilteredValues();
38  const auto& centroid_x = source.getProperty<PixelCentroid>().getCentroidX();
39  const auto& centroid_y = source.getProperty<PixelCentroid>().getCentroidY();
40  auto min_value = source.getProperty<PeakValue>().getMinValue();
41  auto peak_value = source.getProperty<PeakValue>().getMaxValue();
42  auto& coordinates = source.getProperty<PixelCoordinateList>().getCoordinateList();
43 
44  SeFloat x_2 = 0.0;
45  SeFloat y_2 = 0.0;
46  SeFloat x_y = 0.0;
47 
48  SeFloat total_intensity = 0;
49 
50  DetectionImage::PixelType half_peak_threshold = (peak_value + min_value) / 2.0;
51  int nb_of_pixels_above_half = 0;
52  int nb_of_pixels = coordinates.size();
53 
54  auto i = pixel_values.begin();
55  for (auto pixel_coord : coordinates) {
56  SeFloat value = *i++;
57  SeFloat x_pos = pixel_coord.m_x - centroid_x;
58  SeFloat y_pos = pixel_coord.m_y - centroid_y;
59 
60  if (value > half_peak_threshold) {
61  nb_of_pixels_above_half++;
62  }
63 
64  x_2 += x_pos * x_pos * value;
65  y_2 += y_pos * y_pos * value;
66  x_y += x_pos * y_pos * value;
67 
68  total_intensity += value;
69  }
70 
71  x_2 /= total_intensity;
72  y_2 /= total_intensity;
73  x_y /= total_intensity;
74 
75  SeFloat theta;
76  if (fabs(x_2 - y_2) > 0.0) {
77  theta = atan2(2.0 * x_y, x_2 - y_2) / 2.0;
78  } else {
79  theta = M_PI/4.0;
80  }
81 
82  float temp = x_2 - y_2;
83  temp = sqrt(0.25 * temp * temp + x_y * x_y);
84  SeFloat a = sqrt((x_2 + y_2) / 2 + temp);
85  SeFloat b = ((x_2 + y_2) / 2) > temp ? sqrt((x_2 + y_2) / 2 - temp) : 0;
86 
87  // From original SExtractor: Handle fully correlated x/y (which cause a singularity...)
88  SeFloat tmp = x_2 * y_2 - x_y * x_y;
89  bool singu=false;
90  if (tmp < 0.00694) {
91  x_2 += 0.0833333;
92  y_2 += 0.0833333;
93  tmp = x_2 * y_2 - x_y * x_y;
94  singu=true;
95  }
96 
97  SeFloat cxx = y_2 / tmp;
98  SeFloat cyy = x_2 / tmp;
99  SeFloat cxy = -2.0 * x_y / tmp;
100 
101  SeFloat area_under_half = (double) pixel_values.size() - nb_of_pixels_above_half;
102  SeFloat t1t2 = min_value / half_peak_threshold;
103 
104  SeFloat abcor = 1.0;
105  if (t1t2 > 0.0) { // && !prefs.dweight_flag
106  abcor = (area_under_half > 0.0 ? area_under_half : 1.0) / (2 * M_PI * -log(t1t2 < 1.0 ? t1t2 : 0.99) * a * b);
107  if (abcor > 1.0) {
108  abcor = 1.0;
109  }
110  }
111 
112  // set the object property
113  source.setProperty<ShapeParameters>(a, b, theta, abcor, cxx, cyy, cxy, nb_of_pixels, total_intensity, singu);
114 }
115 
116 
117 }
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
SeFloat32 SeFloat
Definition: Types.h:32
auto log
The centroid of all the pixels in the source, weighted by their DetectionImage pixel values...
Definition: PixelCentroid.h:37
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
T atan2(T...args)
T fabs(T...args)
The values of a Source&#39;s pixels in the detection image. They are returned as a vector in the same ord...
T sqrt(T...args)
The SourceInterface is an abstract &quot;source&quot; that has properties attached to it.