SourceXtractorPlusPlus  0.16
Please provide a description of the project.
KronRadiusTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * KronRadiusTask.cpp
19  *
20  * Created on: Sep 12, 2016
21  * Author: mkuemmel@usm.lmu.de
22  */
23 
24 #include <math.h>
25 
28 
36 
39 
40 namespace SourceXtractor {
41 
42 namespace {
43  // the typical radius for determining the Kron-radius
44  const SeFloat KRON_NRADIUS = 3*2.0;
45  const SeFloat CROWD_THRESHOLD_KRON = 0.1;
46  const SeFloat BADAREA_THRESHOLD_KRON = 0.1;
47 }
48 
50 
52  // get the detection frame info
53  const auto& detection_frame_info = source.getProperty<DetectionFrameInfo>();
54  const auto variance_threshold = detection_frame_info.getVarianceThreshold();
55 
56  // get detection frame images
57  const auto& detection_frame_images = source.getProperty<DetectionFrameImages>();
58 
59  const auto detection_image = detection_frame_images.getLockedImage(LayerSubtractedImage);
60  const auto detection_variance = detection_frame_images.getLockedImage(LayerVarianceMap);
61  const auto threshold_image = detection_frame_images.getLockedImage(LayerThresholdedImage);
62 
63 
64  // get the object center
65  const auto& centroid_x = source.getProperty<PixelCentroid>().getCentroidX();
66  const auto& centroid_y = source.getProperty<PixelCentroid>().getCentroidY();
67 
68  // get the shape parameters
69  const auto& cxx = source.getProperty<ShapeParameters>().getEllipseCxx();
70  const auto& cyy = source.getProperty<ShapeParameters>().getEllipseCyy();
71  const auto& cxy = source.getProperty<ShapeParameters>().getEllipseCxy();
72 
73  // create the elliptical aperture
74  auto ell_aper = std::make_shared<EllipticalAperture>(cxx, cyy, cxy, KRON_NRADIUS);
75 
76  // get the aperture borders on the image
77  const auto& min_pixel = ell_aper->getMinPixel(centroid_x, centroid_y);
78  const auto& max_pixel = ell_aper->getMaxPixel(centroid_x, centroid_y);
79 
80  // get the pixel list
81  const auto& pix_list = source.getProperty<PixelCoordinateList>().getCoordinateList();
82 
83  // get the neighbourhood information
84  NeighbourInfo neighbour_info(min_pixel, max_pixel, pix_list, threshold_image);
85 
86  SeFloat radius_flux_sum = 0.;
87  SeFloat flux_sum = 0.;
88  SeFloat area_sum = 0;
89  SeFloat area_bad = 0;
90  SeFloat area_full = 0;
91  long int flag = 0;
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 
97  // check whether the current pixel is inside
98  SeFloat area = ell_aper->getArea(centroid_x, centroid_y, pixel_x, pixel_y);
99  if (area <= 0) {
100  continue;
101  }
102 
103  // make sure the pixel is inside the image
104  if (detection_image->isInside(pixel_x, pixel_y)) {
105  SeFloat value = 0;
106 
107  // enhance the area
108  area_sum += 1;
109 
110  // get the variance value
111  auto pixel_variance = detection_variance->getValue(pixel_x, pixel_y);
112 
113  // check whether the pixel is good
114  bool is_good = pixel_variance < variance_threshold;
115  value = detection_image->getValue(pixel_x, pixel_y) * is_good;
116  area_bad += !is_good;
117 
118  // check whether the pixel is part of another object
119  if (neighbour_info.isNeighbourObjectPixel(pixel_x, pixel_y)) {
120  area_full += 1;
121  }
122  else {
123  // add the pixel quantity
124  radius_flux_sum += value * sqrt(ell_aper->getRadiusSquared(centroid_x, centroid_y, pixel_x, pixel_y));
125  flux_sum += value;
126  }
127  }
128  else {
129  // set the border flag
130  flag |= 0x0008;
131  }
132  }
133  }
134 
135  // check/set the bad area flag
136  bool bad_threshold = area_sum > 0 && area_bad / area_sum > BADAREA_THRESHOLD_KRON;
137  flag |= 0x0001 * bad_threshold;
138 
139  // check/set the crowded area flag
140  bool crowded = area_sum > 0 && area_full / area_sum > CROWD_THRESHOLD_KRON;
141  flag |= crowded;
142 
143  // set the property
144  source.setProperty<KronRadius>(flux_sum > 0 ? radius_flux_sum / flux_sum : 0, flag);
145 }
146 }
147 
std::shared_ptr< ImageAccessor< SeFloat > > getLockedImage(FrameImageLayer layer) const
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
bool isNeighbourObjectPixel(int x, int y) const
The centroid of all the pixels in the source, weighted by their DetectionImage pixel values.
Definition: PixelCentroid.h:37
The SourceInterface is an abstract "source" that has properties attached to it.
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
@ LayerVarianceMap
Definition: Frame.h:44
@ LayerThresholdedImage
Definition: Frame.h:40
@ LayerSubtractedImage
Definition: Frame.h:38
T sqrt(T... args)