SourceXtractorPlusPlus  0.11
Please provide a description of the project.
Frame.cpp
Go to the documentation of this file.
1 
25 
26 
27 namespace SourceXtractor {
28 
29 template<typename T>
31  std::shared_ptr<WeightImage> variance_map,
32  WeightImage::PixelType variance_threshold,
33  std::shared_ptr<CoordinateSystem> coordinate_system,
34  SeFloat gain, SeFloat saturation, int interpolation_gap
35 ):
36  m_image(detection_image),
37  m_variance_map(variance_map),
38  m_coordinate_system(coordinate_system),
39  m_gain(gain),
40  m_saturation(saturation),
41  m_background_rms(0),
42  m_detection_threshold(0),
43  m_variance_threshold(variance_threshold),
44  m_interpolation_gap(interpolation_gap) {}
45 
46 
47 template<typename T>
49  std::shared_ptr<CoordinateSystem> coordinate_system,
50  std::shared_ptr<WeightImage> variance_map
51 ):
52  m_image(detection_image),
53  m_variance_map(variance_map),
54  m_coordinate_system(coordinate_system),
55  m_gain(0),
56  m_saturation(0),
57  m_background_rms(0),
58  m_detection_threshold(0),
59  m_variance_threshold(1e6),
60  m_interpolation_gap(0) {
61  if (variance_map == nullptr && detection_image != nullptr) {
63  detection_image->getHeight(), .0001);
64  }
65 }
66 
67 
68 template<typename T>
70  if (m_interpolation_gap > 0) {
71  if (m_interpolated_image == nullptr) {
72  const_cast<Frame<T> *>(this)->m_interpolated_image = BufferedImage<T>::create(
73  std::make_shared<InterpolatedImageSource<T >>(getOriginalImage(), getOriginalVarianceMap(),
74  getVarianceThreshold(), m_interpolation_gap)
75  );
76  }
77  return m_interpolated_image;
78  }
79  else {
80  return getOriginalImage();
81  }
82 }
83 
84 
85 template<typename T>
87  return SubtractImage<T>::create(getInterpolatedImage(), getBackgroundLevelMap());
88 }
89 
90 
91 template<typename T>
93  if (m_filtered_image == nullptr) {
94  const_cast<Frame<T> *>(this)->applyFilter();
95  }
96  return m_filtered_image;
97 }
98 
99 
100 template<typename T>
102  return ThresholdedImage<T>::create(getFilteredImage(), getVarianceMap(), m_detection_threshold);
103 }
104 
105 
106 template<typename T>
108  return SnrImage<T>::create(getFilteredImage(), getVarianceMap());
109 }
110 
111 
112 template<typename T>
114  if (m_filtered_variance_map == nullptr) {
115  const_cast<Frame<T> *>(this)->applyFilter();
116  }
117  return m_filtered_variance_map;
118 }
119 
120 
121 template<typename T>
123  if (m_interpolation_gap > 0) {
124  if (!m_interpolated_variance) {
125  const_cast<Frame *>(this)->m_interpolated_variance = BufferedImage<WeightImage::PixelType>::create(
127  getVarianceThreshold(), m_interpolation_gap)
128  );
129  }
130  return m_interpolated_variance;
131  }
132  else {
133  return m_variance_map;
134  }
135 }
136 
137 
138 template<typename T>
140  struct ThresholdOperation {
141  static T process(const T& a, const T& b) { return sqrt(a) * b; }
142  };
143 
144  using ThresholdImage = ProcessedImage<T, ThresholdOperation>;
145  return ThresholdImage::create(m_variance_map, m_detection_threshold);
146 }
147 
148 
149 template<typename T>
151  m_variance_map = variance_map;
152 
153  // resets the interpolated image cache and filtered image
154  m_interpolated_image = nullptr;
155  m_filtered_image = nullptr;
156  m_filtered_variance_map = nullptr;
157 }
158 
159 
160 template<typename T>
162  m_variance_threshold = threshold;
163 
164  // resets the interpolated image cache and filtered image
165  m_interpolated_image = nullptr;
166  m_filtered_image = nullptr;
167  m_filtered_variance_map = nullptr;
168 }
169 
170 
171 template<typename T>
173  if (m_background_level_map != nullptr) {
174  return m_background_level_map;
175  }
176  else {
177  // background level = 0 by default
178  return ConstantImage<T>::create(m_image->getWidth(), m_image->getHeight(), 0);
179  }
180 }
181 
182 
183 template<typename T>
184 void Frame<T>::setDetectionThreshold(T detection_threshold) {
185  m_detection_threshold = detection_threshold;
186 }
187 
188 
189 template<typename T>
190 void Frame<T>::setBackgroundLevel(T background_level) {
191  setBackgroundLevel(ConstantImage<T>::create(m_image->getWidth(), m_image->getHeight(), background_level), 0.);
192 }
193 
194 
195 template<typename T>
196 void Frame<T>::setBackgroundLevel(std::shared_ptr<Image<T>> background_level_map, T background_rms) {
197  m_background_level_map = background_level_map;
198  m_background_rms = background_rms;
199  m_filtered_image = nullptr;
200 }
201 
202 
203 template<typename T>
205  m_filter = filter;
206  m_filtered_image = nullptr;
207  m_filtered_variance_map = nullptr;
208 }
209 
210 
211 template<typename T>
212 void Frame<T>::setLabel(const std::string& label) {
213  m_label = label;
214 }
215 
216 
217 template<typename T>
219  if (m_filter != nullptr) {
220  m_filtered_image = m_filter->processImage(getSubtractedImage(), getUnfilteredVarianceMap(), getVarianceThreshold());
221  auto filtered_variance_map = m_filter->processImage(getUnfilteredVarianceMap(), getUnfilteredVarianceMap(),
222  getVarianceThreshold());
223  m_filtered_variance_map = FunctionalImage<T>::create(
224  m_filtered_image->getWidth(), m_filtered_image->getHeight(),
225  [filtered_variance_map](int x, int y) -> T {
226  return std::max(filtered_variance_map->getValue(x, y), 0.f);
227  }
228  );
229 
230  }
231  else {
232  m_filtered_image = getSubtractedImage();
233  m_filtered_variance_map = getUnfilteredVarianceMap();
234  }
235 }
236 
237 
238 template
239 class Frame<SeFloat>;
240 
241 } // end namespace SourceXtractor
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)
static std::shared_ptr< ImageBase< T > > create(Args &&... args)
std::shared_ptr< Image< T > > getInterpolatedImage() const
Definition: Frame.cpp:69
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< Image< T > > getSnrImage() const
Definition: Frame.cpp:107
std::shared_ptr< WeightImage > getVarianceMap() const
Definition: Frame.cpp:113
SeFloat32 SeFloat
Definition: Types.h:32
std::shared_ptr< WeightImage > m_variance_map
Definition: Frame.h:152
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
STL class.
std::shared_ptr< WeightImage > getUnfilteredVarianceMap() const
Definition: Frame.cpp:122
std::shared_ptr< Image< T > > getBackgroundLevelMap() const
Definition: Frame.cpp:172
void setVarianceThreshold(WeightImage::PixelType threshold)
Definition: Frame.cpp:161
void setLabel(const std::string &label)
Definition: Frame.cpp:212
T max(T... args)
void setVarianceMap(std::shared_ptr< WeightImage > variance_map)
Definition: Frame.cpp:150
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:30
T make_shared(T... args)
void setDetectionThreshold(T detection_threshold)
Definition: Frame.cpp:184
std::shared_ptr< Image< T > > getThresholdedImage() const
Definition: Frame.cpp:101
static std::shared_ptr< ConstantImage< T > > create(int width, int height, T constant_value)
Definition: ConstantImage.h:42
Interface representing an image.
Definition: Image.h:43
T sqrt(T... args)
void setFilter(std::shared_ptr< ImageFilter > filter)
Definition: Frame.cpp:204
std::shared_ptr< Image< T > > getSubtractedImage() const
Definition: Frame.cpp:86
void setBackgroundLevel(T background_level)
Definition: Frame.cpp:190
std::shared_ptr< Image< T > > getDetectionThresholdMap() const
Definition: Frame.cpp:139
Processes two images to create a third combining them by using any function.
std::shared_ptr< Image< T > > getFilteredImage() const
Definition: Frame.cpp:92
static std::shared_ptr< ProcessedImage< T, P > > create(std::shared_ptr< const Image< T >> image_a, std::shared_ptr< const Image< T >> image_b)