SourceXtractorPlusPlus
0.22
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Plugin
ExternalFlag
ExternalFlagTask.cpp
Go to the documentation of this file.
1
22
23
#include <mutex>
24
25
#include "
SEFramework/Image/ImageAccessor.h
"
26
27
#include "
SEImplementation/Property/PixelCoordinateList.h
"
28
#include "
SEImplementation/Plugin/DetectionFrameInfo/DetectionFrameInfo.h
"
29
30
#include "
SEImplementation/Plugin/ExternalFlag/ExternalFlagTask.h
"
31
32
namespace
SourceXtractor
{
33
34
template
<
typename
Combine>
35
ExternalFlagTask<Combine>::~ExternalFlagTask
() {
36
}
37
38
template
<
typename
Combine>
39
ExternalFlagTask<Combine>::ExternalFlagTask
(
const
std::vector
<
std::shared_ptr<FlagImage>
>& flag_images,
40
unsigned
int
flag_instance)
41
:
m_flag_images
(flag_images),
42
m_flag_instance
(flag_instance) {
43
}
44
45
46
template
<
typename
Combine>
47
void
ExternalFlagTask<Combine>::computeProperties
(
SourceInterface
&source)
const
{
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()) {
55
throw
Elements::Exception
()
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
61
std::vector<FlagImage::PixelType>
pixel_flags{};
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);
68
source.
setIndexedProperty
<
ExternalFlag
>(m_flag_instance, flag,
count
);
69
}
70
71
72
namespace
ExternalFlagCombineTypes
{
73
74
struct
Or
{
75
static
std::pair<std::int64_t, int>
combine
(
const
std::vector<FlagImage::PixelType>
&pixel_flags) {
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
88
struct
And
{
89
static
std::pair<std::int64_t, int>
combine
(
const
std::vector<FlagImage::PixelType>
&pixel_flags) {
90
std::int64_t
flag =
std::numeric_limits<std::int64_t>::max
();
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
99
struct
Min
{
100
static
std::pair<std::int64_t, int>
combine
(
const
std::vector<FlagImage::PixelType>
&pixel_flags) {
101
std::int64_t
flag =
std::numeric_limits<std::int64_t>::max
();
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
118
struct
Max
{
119
static
std::pair<std::int64_t, int>
combine
(
const
std::vector<FlagImage::PixelType>
&pixel_flags) {
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
137
struct
Most
{
138
static
std::pair<std::int64_t, int>
combine
(
const
std::vector<FlagImage::PixelType>
&pixel_flags) {
139
std::map<FlagImage::PixelType, int>
counters;
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
157
template
class
ExternalFlagTask<ExternalFlagCombineTypes::Or>;
158
template
class
ExternalFlagTask<ExternalFlagCombineTypes::And>;
159
template
class
ExternalFlagTask<ExternalFlagCombineTypes::Min>;
160
template
class
ExternalFlagTask<ExternalFlagCombineTypes::Max>;
161
template
class
ExternalFlagTask<ExternalFlagCombineTypes::Most>;
162
163
}
// SourceXtractor namespace
164
165
166
DetectionFrameInfo.h
ExternalFlagTask.h
ImageAccessor.h
PixelCoordinateList.h
Elements::Exception
SourceXtractor::DetectionFrameInfo
Definition
DetectionFrameInfo.h:29
SourceXtractor::DetectionFrameInfo::getHeight
int getHeight() const
Definition
DetectionFrameInfo.h:55
SourceXtractor::DetectionFrameInfo::getWidth
int getWidth() const
Definition
DetectionFrameInfo.h:51
SourceXtractor::ExternalFlagTask::m_flag_images
std::vector< std::shared_ptr< FlagImage > > m_flag_images
Definition
ExternalFlagTask.h:60
SourceXtractor::ExternalFlagTask::~ExternalFlagTask
virtual ~ExternalFlagTask()
Definition
ExternalFlagTask.cpp:35
SourceXtractor::ExternalFlagTask::m_flag_instance
unsigned int m_flag_instance
Definition
ExternalFlagTask.h:61
SourceXtractor::ExternalFlagTask::ExternalFlagTask
ExternalFlagTask(const std::vector< std::shared_ptr< FlagImage > > &flag_images, unsigned int flag_instance)
Definition
ExternalFlagTask.cpp:39
SourceXtractor::ExternalFlagTask::computeProperties
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition
ExternalFlagTask.cpp:47
SourceXtractor::ExternalFlag
Definition
ExternalFlag.h:46
SourceXtractor::ImageAccessor
Definition
ImageAccessor.h:41
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition
SourceInterface.h:46
SourceXtractor::SourceInterface::setIndexedProperty
void setIndexedProperty(std::size_t index, Args... args)
Convenience template method to call setProperty() with a more user-friendly syntax.
Definition
SourceInterface.h:64
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::count
T count(T... args)
std::int64_t
std::map
std::numeric_limits::max
T max(T... args)
SourceXtractor::ExternalFlagCombineTypes
Definition
ExternalFlagTask.h:34
SourceXtractor
Definition
Aperture.h:30
std::pair
std::shared_ptr
std::vector::size
T size(T... args)
SourceXtractor::ExternalFlagCombineTypes::And
Definition
ExternalFlagTask.cpp:88
SourceXtractor::ExternalFlagCombineTypes::And::combine
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
Definition
ExternalFlagTask.cpp:89
SourceXtractor::ExternalFlagCombineTypes::Max
Definition
ExternalFlagTask.cpp:118
SourceXtractor::ExternalFlagCombineTypes::Max::combine
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
Definition
ExternalFlagTask.cpp:119
SourceXtractor::ExternalFlagCombineTypes::Min
Definition
ExternalFlagTask.cpp:99
SourceXtractor::ExternalFlagCombineTypes::Min::combine
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
Definition
ExternalFlagTask.cpp:100
SourceXtractor::ExternalFlagCombineTypes::Most
Definition
ExternalFlagTask.cpp:137
SourceXtractor::ExternalFlagCombineTypes::Most::combine
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
Definition
ExternalFlagTask.cpp:138
SourceXtractor::ExternalFlagCombineTypes::Or
Definition
ExternalFlagTask.cpp:74
SourceXtractor::ExternalFlagCombineTypes::Or::combine
static std::pair< std::int64_t, int > combine(const std::vector< FlagImage::PixelType > &pixel_flags)
Definition
ExternalFlagTask.cpp:75
std::tie
T tie(T... args)
std::vector
Generated by
1.13.2