SourceXtractorPlusPlus  0.11
Please provide a description of the project.
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 
58  if (value > half_peak_threshold) {
59  nb_of_pixels_above_half++;
60  }
61 
62  x_2 += (pixel_coord.m_x - centroid_x) * (pixel_coord.m_x - centroid_x) * value;
63  y_2 += (pixel_coord.m_y - centroid_y) * (pixel_coord.m_y - centroid_y) * value;
64  x_y += (pixel_coord.m_x - centroid_x) * (pixel_coord.m_y - centroid_y) * value;
65 
66  total_intensity += value;
67  }
68 
69  x_2 /= total_intensity;
70  y_2 /= total_intensity;
71  x_y /= total_intensity;
72 
73  SeFloat theta;
74  if (fabs(x_2 - y_2) > 0.0) {
75  theta = atan2(2.0 * x_y, x_2 - y_2) / 2.0;
76  } else {
77  theta = M_PI/4.0;
78  }
79 
80  float temp = x_2 - y_2;
81  temp = sqrt(0.25 * temp * temp + x_y * x_y);
82  SeFloat a = sqrt((x_2 + y_2) / 2 + temp);
83  SeFloat b = ((x_2 + y_2) / 2) > temp ? sqrt((x_2 + y_2) / 2 - temp) : 0;
84 
85  // From original SExtractor: Handle fully correlated x/y (which cause a singularity...)
86  SeFloat tmp = x_2 * y_2 - x_y * x_y;
87 
88  if (tmp < 0.00694) {
89  x_2 += 0.0833333;
90  y_2 += 0.0833333;
91  tmp = x_2 * y_2 - x_y * x_y;
92  }
93 
94  SeFloat cxx = y_2 / tmp;
95  SeFloat cyy = x_2 / tmp;
96  SeFloat cxy = -2.0 * x_y / tmp;
97 
98  SeFloat area_under_half = (double) pixel_values.size() - nb_of_pixels_above_half;
99  SeFloat t1t2 = min_value / half_peak_threshold;
100 
101  //std::cout << "a "<< a << " b " << b << " t1t2 " << t1t2 << " area " << area_under_half << " " << min_value << " " << half_peak_threshold << std::endl;
102 
103  SeFloat abcor = 1.0;
104  if (t1t2 > 0.0) { // && !prefs.dweight_flag
105  abcor = (area_under_half > 0.0 ? area_under_half : 1.0) / (2 * M_PI * -log(t1t2 < 1.0 ? t1t2 : 0.99) * a * b);
106  if (abcor > 1.0) {
107  abcor = 1.0;
108  }
109  }
110 
111  //std::cout << "abcor " << abcor << std::endl;
112  source.setProperty<ShapeParameters>(a, b, theta, abcor, cxx, cyy, cxy, nb_of_pixels);
113 }
114 
115 
116 }
PixelCoordinateList.h
SourceXtractor::PixelCoordinateList
Definition: PixelCoordinateList.h:31
std::fabs
T fabs(T... args)
SourceXtractor::Image< SeFloat >::PixelType
SeFloat PixelType
Definition: Image.h:47
std::atan2
T atan2(T... args)
SourceXtractor::PixelCentroid
The centroid of all the pixels in the source, weighted by their DetectionImage pixel values.
Definition: PixelCentroid.h:37
PeakValue.h
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition: Types.h:32
DetectionFramePixelValues.h
std::sqrt
T sqrt(T... args)
SourceXtractor
Definition: Aperture.h:30
ShapeParametersTask.h
SourceXtractor::PeakValue
Definition: PeakValue.h:32
log
auto log
SourceXtractor::ShapeParametersTask::computeProperties
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition: ShapeParametersTask.cpp:36
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::DetectionFramePixelValues
The values of a Source's pixels in the detection image. They are returned as a vector in the same ord...
Definition: DetectionFramePixelValues.h:39
ShapeParameters.h
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
SourceXtractor::SourceInterface::setProperty
void setProperty(Args... args)
Definition: SourceInterface.h:72
SourceXtractor::ShapeParameters
Definition: ShapeParameters.h:32
PixelCentroid.h