SourceXtractorPlusPlus  0.10
Please provide a description of the project.
ApertureFlagTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * ApertureFlagTask.cpp
19  *
20  * Created on: Oct 09, 2018
21  * Author: Alejandro Alvarez Ayllon
22  */
23 
24 #include <iostream>
25 
39 
40 namespace SourceXtractor {
41 
42 namespace {
43 const SeFloat CROWD_THRESHOLD_APER = 0.1;
45 }
46 
49 
50  // get the detection frame
51  const auto& detection_frame = source.getProperty<DetectionFrame>().getFrame();
52 
53  // get the images and image information from the frame
54  const auto& detection_image = detection_frame->getSubtractedImage();
55  const auto& detection_variance = detection_frame->getVarianceMap();
56  const auto& variance_threshold = detection_frame->getVarianceThreshold();
57  const auto& threshold_image = detection_frame->getThresholdedImage();
58 
59  // get the object center
60  const auto& centroid_x = source.getProperty<PixelCentroid>().getCentroidX();
61  const auto& centroid_y = source.getProperty<PixelCentroid>().getCentroidY();
62 
63  // get the pixel list
64  const auto& pix_list = source.getProperty<PixelCoordinateList>().getCoordinateList();
65 
66  std::map<float, Flags> all_flags;
67 
68  for (auto aperture_diameter : m_apertures) {
69  auto aperture = CircularAperture(aperture_diameter / 2.);
70 
71  // get the aperture borders on the image
72  auto min_pixel = aperture.getMinPixel(centroid_x, centroid_y);
73  auto max_pixel = aperture.getMaxPixel(centroid_x, centroid_y);
74 
75  // get the neighbourhood information
76  NeighbourInfo neighbour_info(min_pixel, max_pixel, pix_list, threshold_image);
77 
78  Flags flag = Flags::NONE;
79  SeFloat total_area = 0.0;
80  SeFloat bad_area = 0;
81  SeFloat full_area = 0;
82 
83  // iterate over the aperture pixels
84  for (int pixel_y = min_pixel.m_y; pixel_y <= max_pixel.m_y; pixel_y++) {
85  for (int pixel_x = min_pixel.m_x; pixel_x <= max_pixel.m_x; pixel_x++) {
86 
87  // get the area coverage and continue if there is overlap
88  auto area = aperture.getArea(centroid_x, centroid_y, pixel_x, pixel_y);
89  if (area > 0) {
90 
91  // make sure the pixel is inside the image
92  if (pixel_x >= 0 && pixel_y >= 0 && pixel_x < detection_image->getWidth() &&
93  pixel_y < detection_image->getHeight()) {
94 
95  // enhance the area
96  total_area += area;
97 
98  auto variance_tmp = detection_variance ? detection_variance->getValue(pixel_x, pixel_y) : 1;
99  if (neighbour_info.isNeighbourObjectPixel(pixel_x, pixel_y) || variance_tmp > variance_threshold) {
100 
101  if (neighbour_info.isNeighbourObjectPixel(pixel_x, pixel_y))
102  full_area += 1;
103  if (variance_tmp > variance_threshold)
104  bad_area += 1;
105  }
106  } else {
107  flag |= Flags::BOUNDARY;
108  }
109  }
110  }
111  }
112 
113  if (total_area > 0) {
114  // check/set the bad area flag
115  if (bad_area / total_area > BADAREA_THRESHOLD_APER)
116  flag |= Flags::BIASED;
117 
118  // check/set the crowded area flag
119  if (full_area / total_area > CROWD_THRESHOLD_APER)
120  flag |= Flags::NEIGHBORS;
121  }
122 
123  all_flags.emplace(std::make_pair(aperture_diameter, flag));
124  }
125 
126  // set the source properties
127  source.setProperty<ApertureFlag>(all_flags);
128 
129  // Draw the checkimage for the last aperture on the detection image
130  auto aperture_check_img = CheckImages::getInstance().getApertureImage();
131  if (aperture_check_img) {
132  auto src_id = source.getProperty<SourceID>().getId();
133 
134  auto aperture = CircularAperture(m_apertures[0] / 2.);
135  auto min_pixel = aperture.getMinPixel(centroid_x, centroid_y);
136  auto max_pixel = aperture.getMaxPixel(centroid_x, centroid_y);
137 
138  for (int y = min_pixel.m_y; y <= max_pixel.m_y; ++y) {
139  for (int x = min_pixel.m_x; x <= max_pixel.m_x; ++x) {
140  if (aperture.getArea(centroid_x, centroid_y, x, y) > 0) {
141  if (x >= 0 && y >= 0 && x < aperture_check_img->getWidth() && y < aperture_check_img->getHeight()) {
142  aperture_check_img->setValue(x, y, src_id);
143  }
144  }
145  }
146  }
147  }
148 }
149 
150 }
151 
PixelCoordinateList.h
SourceXtractor::PixelCoordinateList
Definition: PixelCoordinateList.h:30
SourceXtractor::CheckImages::getApertureImage
std::shared_ptr< WriteableImage< unsigned int > > getApertureImage() const
Definition: CheckImages.h:68
std::lock
T lock(T... args)
ApertureFlagTask.h
SourceXtractor::Flags::NEIGHBORS
@ NEIGHBORS
The object has neighbors, bright and close enough.
CheckImages.h
SourceXtractor::PixelCentroid
The centroid of all the pixels in the source, weighted by their DetectionImage pixel values.
Definition: PixelCentroid.h:37
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition: Types.h:32
SourceFlags.h
std::map::emplace
T emplace(T... args)
DetectionFrame.h
std::lock_guard
STL class.
SourceXtractor::Flags
Flags
Flagging of bad sources.
Definition: SourceFlags.h:34
SourceXtractor::MultithreadedMeasurement::g_global_mutex
static std::recursive_mutex g_global_mutex
Definition: MultithreadedMeasurement.h:54
SourceXtractor::CircularAperture
Definition: CircularAperture.h:31
SourceID.h
SourceFlags.h
SourceXtractor::SourceID
Definition: SourceID.h:33
SourceXtractor::NeighbourInfo::isNeighbourObjectPixel
bool isNeighbourObjectPixel(int x, int y) const
Definition: NeighbourInfo.cpp:69
SourceXtractor::Flags::BOUNDARY
@ BOUNDARY
The object is truncated (too close to an image boundary)
CircularAperture.h
SourceXtractor::CheckImages::getInstance
static CheckImages & getInstance()
Definition: CheckImages.h:114
NeighbourInfo.h
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::BADAREA_THRESHOLD_APER
const SeFloat BADAREA_THRESHOLD_APER
Definition: FluxMeasurement.cpp:29
SourceXtractor::NeighbourInfo
Definition: NeighbourInfo.h:34
SourceXtractor::DetectionFrame
Definition: DetectionFrame.h:33
std::map< float, Flags >
AperturePhotometry.h
SourceXtractor::Flags::NONE
@ NONE
No flag is set.
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:93
SourceXtractor::Flags::BIASED
@ BIASED
The object has bad pixels.
MultithreadedMeasurement.h
SourceXtractor::ApertureFlagTask::computeProperties
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition: ApertureFlagTask.cpp:47
ApertureFlag.h
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
std::make_pair
T make_pair(T... args)
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:93
SourceXtractor::SourceInterface::setProperty
void setProperty(Args... args)
Definition: SourceInterface.h:72
PixelCentroid.h
SourceXtractor::ApertureFlag
Aperture photometry flag.
Definition: ApertureFlag.h:38
SourceXtractor::ApertureFlagTask::m_apertures
std::vector< SeFloat > m_apertures
Definition: ApertureFlagTask.h:43