SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectionFrameConfig.cpp
Go to the documentation of this file.
1 
18 #include <iostream>
19 
20 #include <boost/filesystem.hpp>
21 
23 
26 
31 
33 
35 
36 using namespace Euclid::Configuration;
37 namespace po = boost::program_options;
38 
39 namespace SourceXtractor {
40 
41 DetectionFrameConfig::DetectionFrameConfig(long manager_id) : Configuration(manager_id) {
42  declareDependency<WeightImageConfig>();
43  declareDependency<DetectionImageConfig>();
44  declareDependency<BackgroundConfig>();
45  declareDependency<BackgroundAnalyzerFactory>();
46 }
47 
48 void DetectionFrameConfig::initialize(const UserValues& ) {
49 
50  for (size_t i=0; i<getDependency<DetectionImageConfig>().getExtensionsNb(); i++) {
51  auto detection_image = getDependency<DetectionImageConfig>().getDetectionImage(i);
52  auto detection_image_path = getDependency<DetectionImageConfig>().getDetectionImagePath();
53  auto detection_image_coordinate_system = getDependency<DetectionImageConfig>().getCoordinateSystem(i);
54  auto detection_image_gain = getDependency<DetectionImageConfig>().getGain(i);
55  auto detection_image_saturation = getDependency<DetectionImageConfig>().getSaturation(i);
56  auto interpolation_gap = getDependency<DetectionImageConfig>().getInterpolationGap(i);
57 
58  auto weight_image = getDependency<WeightImageConfig>().getWeightImage(i);
59  auto weight_threshold = getDependency<WeightImageConfig>().getWeightThreshold(i);
60  bool is_weight_absolute = getDependency<WeightImageConfig>().isWeightAbsolute();
61 
62  auto detection_frame = std::make_shared<DetectionImageFrame>(detection_image, weight_image,
63  weight_threshold, detection_image_coordinate_system, detection_image_gain,
64  detection_image_saturation, interpolation_gap);
65  detection_frame->setLabel(boost::filesystem::basename(detection_image_path));
66 
67  auto background_analyzer = getDependency<BackgroundAnalyzerFactory>().createBackgroundAnalyzer();
68  auto background_model = background_analyzer->analyzeBackground(detection_frame->getOriginalImage(), weight_image,
69  ConstantImage<unsigned char>::create(detection_image->getWidth(), detection_image->getHeight(), false), detection_frame->getVarianceThreshold());
70 
71  detection_frame->setBackgroundLevel(background_model.getLevelMap(), background_model.getMedianRms());
72 
73  if (weight_image != nullptr) {
74  if (is_weight_absolute) {
75  detection_frame->setVarianceMap(weight_image);
76  } else {
77  // apply the rms scaling factor from the background
78  auto bck_scaling_factor = background_model.getScalingFactor();
79  auto scaled_image = MultiplyImage<SeFloat>::create(weight_image, bck_scaling_factor);
80  detection_frame->setVarianceMap(scaled_image);
81  detection_frame->setVarianceThreshold(detection_frame->getVarianceThreshold()*bck_scaling_factor);
82  }
83  } else {
84  // re-set the variance check image to what's in the detection_frame()
85  detection_frame->setVarianceMap(background_model.getVarianceMap());
86  }
87 
88  const auto& background_config = getDependency<BackgroundConfig>();
89  // Override background level and threshold if requested by the user
90  if (background_config.isBackgroundLevelAbsolute()) {
92  detection_image->getWidth(), detection_image->getHeight(), background_config.getBackgroundLevel());
93 
94  detection_frame->setBackgroundLevel(background, background_model.getMedianRms());
95 
97  } else {
98  CheckImages::getInstance().addBackgroundCheckImage(background_model.getLevelMap());
99  }
100 
101  if (background_config.isDetectionThresholdAbsolute()) {
102  detection_frame->setDetectionThreshold(background_config.getDetectionThreshold());
103  }
104 
105  auto img_source = getDependency<DetectionImageConfig>().getImageSource(i);
106  detection_frame->setMetadata(img_source->getMetadata());
107 
108  detection_frame->setHduIndex(i);
109 
114 
115  m_frames.emplace_back(detection_frame);
116  }
117 }
118 
119 }
void addFilteredCheckImage(std::shared_ptr< Image< SeFloat >> filtered_image)
Definition: CheckImages.h:132
std::vector< std::shared_ptr< DetectionImageFrame > > m_frames
void addBackgroundCheckImage(std::shared_ptr< Image< SeFloat >> background_image)
Definition: CheckImages.h:124
static CheckImages & getInstance()
Definition: CheckImages.h:150
void addVarianceCheckImage(std::shared_ptr< Image< SeFloat >> variance_image)
Definition: CheckImages.h:128
void initialize(const UserValues &args) override
static std::shared_ptr< ConstantImage< T > > create(int width, int height, T constant_value)
Definition: ConstantImage.h:42
void addThresholdedCheckImage(std::shared_ptr< Image< SeFloat >> thresholded_image)
Definition: CheckImages.h:136
void addSnrCheckImage(std::shared_ptr< Image< SeFloat >> snr_image)
Definition: CheckImages.h:140
static std::shared_ptr< ProcessedImage< T, P > > create(std::shared_ptr< const Image< T >> image_a, std::shared_ptr< const Image< T >> image_b)