SourceXtractorPlusPlus
1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEFramework
src
lib
Frame
Frame.cpp
Go to the documentation of this file.
1
17
18
#include "
SEFramework/Frame/Frame.h
"
19
#include "
SEFramework/Image/ImageAccessor.h
"
20
#include "
SEFramework/Image/BufferedImage.h
"
21
#include "
SEFramework/Image/ConstantImage.h
"
22
#include "
SEFramework/Image/FunctionalImage.h
"
23
#include "
SEFramework/Image/InterpolatedImageSource.h
"
24
#include "
SEFramework/Image/ProcessedImage.h
"
25
#include "
SEFramework/Image/ThresholdedImage.h
"
26
27
28
namespace
SourceXtractor
{
29
30
template
<
typename
T>
31
Frame<T>::Frame
(
std::shared_ptr
<
Image<T>
> detection_image,
32
std::shared_ptr<WeightImage>
variance_map,
33
WeightImage::PixelType
variance_threshold,
34
std::shared_ptr<CoordinateSystem>
coordinate_system,
35
SeFloat
gain,
SeFloat
saturation,
int
interpolation_gap
36
):
37
m_image
(detection_image),
38
m_variance_map
(variance_map),
39
m_coordinate_system
(coordinate_system),
40
m_gain
(gain),
41
m_saturation
(saturation),
42
m_background_rms
(0),
43
m_detection_threshold
(0),
44
m_variance_threshold
(variance_threshold),
45
m_interpolation_gap
(interpolation_gap) {
46
applyInterpolation
();
47
applyFilter
();
48
}
49
50
51
template
<
typename
T>
52
Frame<T>::Frame
(
std::shared_ptr
<
Image<T>
> detection_image,
53
std::shared_ptr<CoordinateSystem>
coordinate_system,
54
std::shared_ptr<WeightImage>
variance_map
55
):
56
m_image
(detection_image),
57
m_variance_map
(variance_map),
58
m_coordinate_system
(coordinate_system),
59
m_gain
(0),
60
m_saturation
(0),
61
m_background_rms
(0),
62
m_detection_threshold
(0),
63
m_variance_threshold
(1e6),
64
m_interpolation_gap
(0) {
65
if
(variance_map ==
nullptr
&& detection_image !=
nullptr
) {
66
m_variance_map
=
ConstantImage<WeightImage::PixelType>::create
(detection_image->getWidth(),
67
detection_image->getHeight(), .0001);
68
}
69
applyInterpolation
();
70
applyFilter
();
71
}
72
73
template
<
typename
T>
74
std::shared_ptr<Image<T>
>
Frame<T>::getImage
(
FrameImageLayer
layer)
const
{
75
// FIXME replace switch with a better system
76
switch
(layer) {
77
default
:
78
case
LayerOriginalImage
:
79
return
getOriginalImage
();
80
break
;
81
case
LayerInterpolatedImage
:
82
return
getInterpolatedImage
();
83
break
;
84
case
LayerSubtractedImage
:
85
return
getSubtractedImage
();
86
break
;
87
case
LayerFilteredImage
:
88
return
getFilteredImage
();
89
break
;
90
case
LayerThresholdedImage
:
91
return
getThresholdedImage
();
92
break
;
93
case
LayerSignalToNoiseMap
:
94
return
getSnrImage
();
95
break
;
96
case
LayerOriginalVarianceMap
:
97
return
getOriginalVarianceMap
();
98
break
;
99
case
LayerUnfilteredVarianceMap
:
100
return
getUnfilteredVarianceMap
();
101
break
;
102
case
LayerVarianceMap
:
103
return
getVarianceMap
();
104
break
;
105
case
LayerDetectionThresholdMap
:
106
return
getDetectionThresholdMap
();
107
break
;
108
}
109
}
110
111
template
<
typename
T>
112
std::shared_ptr<Image<T>
>
Frame<T>::getInterpolatedImage
()
const
{
113
if
(
m_interpolated_image
> 0) {
114
return
m_interpolated_image
;
115
}
116
else
{
117
return
m_image
;
118
}
119
}
120
121
122
template
<
typename
T>
123
std::shared_ptr<Image<T>
>
Frame<T>::getSubtractedImage
()
const
{
124
return
SubtractImage<T>::create
(
getInterpolatedImage
(),
getBackgroundLevelMap
());
125
}
126
127
128
template
<
typename
T>
129
std::shared_ptr<Image<T>
>
Frame<T>::getFilteredImage
()
const
{
130
return
m_filtered_image
;
131
}
132
133
134
template
<
typename
T>
135
std::shared_ptr<Image<T>
>
Frame<T>::getThresholdedImage
()
const
{
136
return
ThresholdedImage<T>::create
(
getFilteredImage
(),
getVarianceMap
(),
m_detection_threshold
);
137
}
138
139
140
template
<
typename
T>
141
std::shared_ptr<Image<T>
>
Frame<T>::getSnrImage
()
const
{
142
return
SnrImage<T>::create
(
getFilteredImage
(),
getVarianceMap
());
143
}
144
145
146
template
<
typename
T>
147
std::shared_ptr<WeightImage>
Frame<T>::getVarianceMap
()
const
{
148
return
m_filtered_variance_map
;
149
}
150
151
152
template
<
typename
T>
153
std::shared_ptr<WeightImage>
Frame<T>::getUnfilteredVarianceMap
()
const
{
154
if
(
m_interpolated_variance
) {
155
return
m_interpolated_variance
;
156
}
157
else
{
158
return
m_variance_map
;
159
}
160
}
161
162
163
template
<
typename
T>
164
std::shared_ptr<Image<T>
>
Frame<T>::getDetectionThresholdMap
()
const
{
165
struct
ThresholdOperation {
166
static
T process(
const
T& a,
const
T& b) {
return
sqrt
(a) * b; }
167
};
168
169
using
ThresholdImage =
ProcessedImage<T, ThresholdOperation>
;
170
return
ThresholdImage::create(
m_variance_map
,
m_detection_threshold
);
171
}
172
173
174
template
<
typename
T>
175
void
Frame<T>::setVarianceMap
(
std::shared_ptr<WeightImage>
variance_map) {
176
m_variance_map
= variance_map;
177
178
// resets the interpolated image cache and filtered image
179
m_interpolated_image
=
nullptr
;
180
m_interpolated_variance
=
nullptr
;
181
m_filtered_image
=
nullptr
;
182
m_filtered_variance_map
=
nullptr
;
183
184
applyInterpolation
();
185
applyFilter
();
186
}
187
188
189
template
<
typename
T>
190
void
Frame<T>::setVarianceThreshold
(
WeightImage::PixelType
threshold) {
191
192
// set the variance threshold if it make sense
193
if
(
m_variance_threshold
<
std::numeric_limits<WeightImage::PixelType>::max
()){
194
m_variance_threshold
= threshold;
195
}
196
else
{
197
return
;
198
}
199
200
// resets the interpolated image cache and filtered image
201
m_interpolated_image
=
nullptr
;
202
m_interpolated_variance
=
nullptr
;
203
m_filtered_image
=
nullptr
;
204
m_filtered_variance_map
=
nullptr
;
205
206
applyInterpolation
();
207
applyFilter
();
208
}
209
210
211
template
<
typename
T>
212
std::shared_ptr<Image<T>
>
Frame<T>::getBackgroundLevelMap
()
const
{
213
if
(
m_background_level_map
!=
nullptr
) {
214
return
m_background_level_map
;
215
}
216
else
{
217
// background level = 0 by default
218
return
ConstantImage<T>::create
(
m_image
->getWidth(),
m_image
->getHeight(), 0);
219
}
220
}
221
222
223
template
<
typename
T>
224
void
Frame<T>::setDetectionThreshold
(T detection_threshold) {
225
m_detection_threshold
= detection_threshold;
226
}
227
228
229
template
<
typename
T>
230
void
Frame<T>::setBackgroundLevel
(T background_level) {
231
setBackgroundLevel
(
ConstantImage<T>::create
(
m_image
->getWidth(),
m_image
->getHeight(), background_level), 0.);
232
}
233
234
235
template
<
typename
T>
236
void
Frame<T>::setBackgroundLevel
(
std::shared_ptr
<
Image<T>
> background_level_map, T background_rms) {
237
m_background_level_map
= background_level_map;
238
m_background_rms
= background_rms;
239
m_filtered_image
=
nullptr
;
240
m_filtered_variance_map
=
nullptr
;
241
242
applyFilter
();
243
}
244
245
246
template
<
typename
T>
247
void
Frame<T>::setFilter
(
std::shared_ptr<ImageFilter>
filter) {
248
m_filter
= filter;
249
m_filtered_image
=
nullptr
;
250
m_filtered_variance_map
=
nullptr
;
251
applyFilter
();
252
}
253
254
255
template
<
typename
T>
256
void
Frame<T>::setLabel
(
const
std::string
& label) {
257
m_label
= label;
258
}
259
260
261
template
<
typename
T>
262
void
Frame<T>::applyFilter
() {
263
if
(
m_filter
!=
nullptr
) {
264
m_filtered_image
=
m_filter
->processImage(
getSubtractedImage
(),
getUnfilteredVarianceMap
(),
265
m_variance_threshold
);
266
auto
filtered_variance_map =
m_filter
->processImage(
getUnfilteredVarianceMap
(),
267
getUnfilteredVarianceMap
(),
268
m_variance_threshold
);
269
m_filtered_variance_map
=
FunctionalImage<T>::create
(
270
filtered_variance_map, [](
int
,
int
,
WeightImage::PixelType
v) {
271
return
std::max
(v, 0.f);
272
}
273
);
274
}
275
else
{
276
m_filtered_image
=
getSubtractedImage
();
277
m_filtered_variance_map
=
getUnfilteredVarianceMap
();
278
}
279
}
280
281
template
<
typename
T>
282
void
Frame<T>::applyInterpolation
() {
283
if
(!
m_interpolated_variance
) {
284
m_interpolated_variance
=
BufferedImage<WeightImage::PixelType>::create
(
285
std::make_shared
<
InterpolatedImageSource<WeightImage::PixelType>
>(
286
m_variance_map
,
m_variance_map
,
m_variance_threshold
,
m_interpolation_gap
)
287
);
288
}
289
if
(!
m_interpolated_image
) {
290
m_interpolated_image
=
BufferedImage<T>::create
(
291
std::make_shared
<
InterpolatedImageSource<T>
>(
292
m_image
,
m_variance_map
,
m_variance_threshold
,
m_interpolation_gap
)
293
);
294
}
295
}
296
297
template
298
class
Frame<SeFloat>
;
299
300
}
// end namespace SourceXtractor
BufferedImage.h
ConstantImage.h
Frame.h
FunctionalImage.h
ImageAccessor.h
InterpolatedImageSource.h
ProcessedImage.h
ThresholdedImage.h
std::string
SourceXtractor::BufferedImage::create
static std::shared_ptr< BufferedImage< T > > create(std::shared_ptr< const ImageSource > source, std::shared_ptr< TileManager > tile_manager=TileManager::getInstance())
Definition
BufferedImage.cpp:32
SourceXtractor::ConstantImage::create
static std::shared_ptr< ConstantImage< T > > create(int width, int height, T constant_value)
Definition
ConstantImage.h:42
SourceXtractor::Frame
Definition
Frame.h:50
SourceXtractor::Frame::getSnrImage
std::shared_ptr< Image< T > > getSnrImage() const
Definition
Frame.cpp:141
SourceXtractor::Frame::setBackgroundLevel
void setBackgroundLevel(T background_level)
Definition
Frame.cpp:230
SourceXtractor::Frame::m_gain
SeFloat m_gain
Definition
Frame.h:188
SourceXtractor::Frame::applyInterpolation
void applyInterpolation()
Definition
Frame.cpp:282
SourceXtractor::Frame::getDetectionThresholdMap
std::shared_ptr< Image< T > > getDetectionThresholdMap() const
Definition
Frame.cpp:164
SourceXtractor::Frame::setFilter
void setFilter(std::shared_ptr< ImageFilter > filter)
Definition
Frame.cpp:247
SourceXtractor::Frame::m_variance_map
std::shared_ptr< WeightImage > m_variance_map
Definition
Frame.h:183
SourceXtractor::Frame::m_label
std::string m_label
Definition
Frame.h:203
SourceXtractor::Frame::m_background_rms
SeFloat m_background_rms
Definition
Frame.h:190
SourceXtractor::Frame::m_interpolated_image
std::shared_ptr< Image< T > > m_interpolated_image
Definition
Frame.h:198
SourceXtractor::Frame::getImage
std::shared_ptr< Image< T > > getImage(FrameImageLayer layer) const
Definition
Frame.cpp:74
SourceXtractor::Frame::m_background_level_map
std::shared_ptr< Image< T > > m_background_level_map
Definition
Frame.h:184
SourceXtractor::Frame::applyFilter
void applyFilter()
Definition
Frame.cpp:262
SourceXtractor::Frame::m_interpolation_gap
int m_interpolation_gap
Definition
Frame.h:195
SourceXtractor::Frame::setDetectionThreshold
void setDetectionThreshold(T detection_threshold)
Definition
Frame.cpp:224
SourceXtractor::Frame::setLabel
void setLabel(const std::string &label)
Definition
Frame.cpp:256
SourceXtractor::Frame::m_filter
std::shared_ptr< ImageFilter > m_filter
Definition
Frame.h:197
SourceXtractor::Frame::setVarianceMap
void setVarianceMap(std::shared_ptr< WeightImage > variance_map)
Definition
Frame.cpp:175
SourceXtractor::Frame::getBackgroundLevelMap
std::shared_ptr< Image< T > > getBackgroundLevelMap() const
Definition
Frame.cpp:212
SourceXtractor::Frame::m_filtered_variance_map
std::shared_ptr< Image< T > > m_filtered_variance_map
Definition
Frame.h:201
SourceXtractor::Frame::getOriginalVarianceMap
std::shared_ptr< WeightImage > getOriginalVarianceMap() const
Definition
Frame.h:123
SourceXtractor::Frame::m_variance_threshold
WeightImage::PixelType m_variance_threshold
Definition
Frame.h:193
SourceXtractor::Frame::m_interpolated_variance
std::shared_ptr< Image< WeightImage::PixelType > > m_interpolated_variance
Definition
Frame.h:199
SourceXtractor::Frame::Frame
Frame(std::shared_ptr< Image< T > > detection_image, std::shared_ptr< WeightImage > variance_map, WeightImage::PixelType variance_threshold, std::shared_ptr< CoordinateSystem > coordinate_system, SeFloat gain, SeFloat saturation, int interpolation_gap)
Definition
Frame.cpp:31
SourceXtractor::Frame::m_coordinate_system
std::shared_ptr< CoordinateSystem > m_coordinate_system
Definition
Frame.h:186
SourceXtractor::Frame::getInterpolatedImage
std::shared_ptr< Image< T > > getInterpolatedImage() const
Definition
Frame.cpp:112
SourceXtractor::Frame::getUnfilteredVarianceMap
std::shared_ptr< WeightImage > getUnfilteredVarianceMap() const
Definition
Frame.cpp:153
SourceXtractor::Frame::m_saturation
SeFloat m_saturation
Definition
Frame.h:189
SourceXtractor::Frame::getOriginalImage
std::shared_ptr< Image< T > > getOriginalImage() const
Definition
Frame.h:79
SourceXtractor::Frame::m_filtered_image
std::shared_ptr< Image< T > > m_filtered_image
Definition
Frame.h:200
SourceXtractor::Frame::m_detection_threshold
T m_detection_threshold
Definition
Frame.h:192
SourceXtractor::Frame::getThresholdedImage
std::shared_ptr< Image< T > > getThresholdedImage() const
Definition
Frame.cpp:135
SourceXtractor::Frame::getFilteredImage
std::shared_ptr< Image< T > > getFilteredImage() const
Definition
Frame.cpp:129
SourceXtractor::Frame::getSubtractedImage
std::shared_ptr< Image< T > > getSubtractedImage() const
Definition
Frame.cpp:123
SourceXtractor::Frame::getVarianceMap
std::shared_ptr< WeightImage > getVarianceMap() const
Definition
Frame.cpp:147
SourceXtractor::Frame::m_image
std::shared_ptr< Image< T > > m_image
Definition
Frame.h:182
SourceXtractor::Frame::setVarianceThreshold
void setVarianceThreshold(WeightImage::PixelType threshold)
Definition
Frame.cpp:190
SourceXtractor::FunctionalImage::create
static std::shared_ptr< FunctionalImage< T, I > > create(Args &&... args)
Definition
FunctionalImage.h:56
SourceXtractor::Image
Interface representing an image.
Definition
Image.h:44
SourceXtractor::Image< SeFloat >::PixelType
SeFloat PixelType
Definition
Image.h:48
SourceXtractor::InterpolatedImageSource
Definition
InterpolatedImageSource.h:35
SourceXtractor::ProcessedImage
Processes two images to create a third combining them by using any function.
Definition
ProcessedImage.h:36
SourceXtractor::ProcessedImage< T, SubtractOperation< T > >::create
static std::shared_ptr< ProcessedImage< T, SubtractOperation< T > > > create(std::shared_ptr< const Image< T > > image_a, std::shared_ptr< const Image< T > > image_b)
Definition
ProcessedImage.h:53
SourceXtractor::ThresholdedImage::create
static std::shared_ptr< ThresholdedImage< T > > create(std::shared_ptr< const Image< T > > image, std::shared_ptr< const Image< T > > variance_map, T threshold_multiplier)
Definition
ThresholdedImage.h:58
std::make_shared
T make_shared(T... args)
std::numeric_limits::max
T max(T... args)
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::FrameImageLayer
FrameImageLayer
Definition
Frame.h:36
SourceXtractor::LayerVarianceMap
@ LayerVarianceMap
Definition
Frame.h:45
SourceXtractor::LayerFilteredImage
@ LayerFilteredImage
Definition
Frame.h:40
SourceXtractor::LayerOriginalImage
@ LayerOriginalImage
Definition
Frame.h:37
SourceXtractor::LayerDetectionThresholdMap
@ LayerDetectionThresholdMap
Definition
Frame.h:46
SourceXtractor::LayerUnfilteredVarianceMap
@ LayerUnfilteredVarianceMap
Definition
Frame.h:44
SourceXtractor::LayerThresholdedImage
@ LayerThresholdedImage
Definition
Frame.h:41
SourceXtractor::LayerInterpolatedImage
@ LayerInterpolatedImage
Definition
Frame.h:38
SourceXtractor::LayerOriginalVarianceMap
@ LayerOriginalVarianceMap
Definition
Frame.h:43
SourceXtractor::LayerSubtractedImage
@ LayerSubtractedImage
Definition
Frame.h:39
SourceXtractor::LayerSignalToNoiseMap
@ LayerSignalToNoiseMap
Definition
Frame.h:42
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition
Types.h:32
std::shared_ptr
std::sqrt
T sqrt(T... args)
Generated by
1.15.0