SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
ExternalFlagTask.cpp
Go to the documentation of this file.
1
22
23#include <mutex>
24
26
29
31
32namespace SourceXtractor {
33
34template<typename Combine>
37
38template<typename Combine>
40 unsigned int flag_instance)
41 : m_flag_images(flag_images),
42 m_flag_instance(flag_instance) {
43}
44
45
46template<typename Combine>
48 // FIXME: for flag_image access, the external flags image not part of detection frame?!
49 const auto& detection_frame_info = source.getProperty<DetectionFrameInfo>();
50
51 auto flag_image_acc = ImageAccessor<int64_t>(m_flag_images.at(detection_frame_info.getHduIndex()));
52
53 if (flag_image_acc.getWidth() != detection_frame_info.getWidth() ||
54 flag_image_acc.getHeight() != detection_frame_info.getHeight()) {
56 << "The flag image size does not match the detection image size: "
57 << flag_image_acc.getWidth() << "x" << flag_image_acc.getHeight() << " != "
58 << detection_frame_info.getWidth() << "x" << detection_frame_info.getHeight();
59 }
60
62 for (auto& coords : source.getProperty<PixelCoordinateList>().getCoordinateList()) {
63 pixel_flags.push_back(flag_image_acc.getValue(coords.m_x, coords.m_y));
64 }
65 std::int64_t flag = 0;
66 int count = 0;
67 std::tie(flag, count) = Combine::combine(pixel_flags);
69}
70
71
73
74struct Or {
76 std::int64_t flag = 0;
77 int count = 0;
78 for (auto pix_flag : pixel_flags) {
79 if (pix_flag != 0) {
80 flag |= pix_flag;
81 ++count;
82 }
83 }
84 return {flag, count};
85 }
86};
87
88struct And {
91 int count = pixel_flags.size();
92 for (auto pix_flag : pixel_flags) {
93 flag &= pix_flag;
94 }
95 return {flag, count};
96 }
97};
98
99struct Min {
102 int count = 0;
103 for (auto pix_flag : pixel_flags) {
104 if (pix_flag < flag) {
105 flag = pix_flag;
106 count = 1;
107 } else if (pix_flag == flag) {
108 ++count;
109 }
110 }
111 if (count == 0) {
112 flag = 0;
113 }
114 return {flag, count};
115 }
116};
117
118struct Max {
120 std::int64_t flag = 0;
121 int count = 0;
122 for (auto pix_flag : pixel_flags) {
123 if (pix_flag > flag) {
124 flag = pix_flag;
125 count = 1;
126 } else if (pix_flag == flag) {
127 ++count;
128 }
129 }
130 if (count == 0) {
131 flag = 0;
132 }
133 return {flag, count};
134 }
135};
136
137struct Most {
140 for (auto pix_flag : pixel_flags) {
141 counters[pix_flag] += 1;
142 }
143 std::int64_t flag = 0;
144 int count = 0;
145 for (auto& pair : counters) {
146 if (pair.second > count) {
147 flag = pair.first;
148 count = pair.second;
149 }
150 }
151 return {flag, count};
152 }
153};
154
155} // end of namespace ExternalFlagCombineTypes
156
157template class ExternalFlagTask<ExternalFlagCombineTypes::Or>;
158template class ExternalFlagTask<ExternalFlagCombineTypes::And>;
159template class ExternalFlagTask<ExternalFlagCombineTypes::Min>;
160template class ExternalFlagTask<ExternalFlagCombineTypes::Max>;
161template class ExternalFlagTask<ExternalFlagCombineTypes::Most>;
162
163} // SourceXtractor namespace
164
165
166
std::vector< std::shared_ptr< FlagImage > > m_flag_images
ExternalFlagTask(const std::vector< std::shared_ptr< FlagImage > > &flag_images, unsigned int flag_instance)
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
const std::vector< PixelCoordinate > & getCoordinateList() const
The SourceInterface is an abstract "source" that has properties attached to it.
void setIndexedProperty(std::size_t index, Args... args)
Convenience template method to call setProperty() with a more user-friendly syntax.
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
T count(T... args)
T max(T... args)
T push_back(T... args)
T size(T... args)
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
T tie(T... args)