20 #include <boost/filesystem.hpp>
36 using namespace Euclid::Configuration;
37 namespace po = boost::program_options;
39 namespace SourceXtractor {
41 DetectionFrameConfig::DetectionFrameConfig(
long manager_id) :
Configuration(manager_id) {
42 declareDependency<WeightImageConfig>();
43 declareDependency<DetectionImageConfig>();
44 declareDependency<BackgroundConfig>();
45 declareDependency<BackgroundAnalyzerFactory>();
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);
58 auto weight_image = getDependency<WeightImageConfig>().getWeightImage(i);
59 auto weight_threshold = getDependency<WeightImageConfig>().getWeightThreshold(i);
60 bool is_weight_absolute = getDependency<WeightImageConfig>().isWeightAbsolute();
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));
67 auto background_analyzer = getDependency<BackgroundAnalyzerFactory>().createBackgroundAnalyzer();
68 auto background_model = background_analyzer->analyzeBackground(detection_frame->getOriginalImage(), weight_image,
71 detection_frame->setBackgroundLevel(background_model.getLevelMap(), background_model.getMedianRms());
73 if (weight_image !=
nullptr) {
74 if (is_weight_absolute) {
75 detection_frame->setVarianceMap(weight_image);
78 auto bck_scaling_factor = background_model.getScalingFactor();
80 detection_frame->setVarianceMap(scaled_image);
81 detection_frame->setVarianceThreshold(detection_frame->getVarianceThreshold()*bck_scaling_factor);
85 detection_frame->setVarianceMap(background_model.getVarianceMap());
88 const auto& background_config = getDependency<BackgroundConfig>();
90 if (background_config.isBackgroundLevelAbsolute()) {
92 detection_image->getWidth(), detection_image->getHeight(), background_config.getBackgroundLevel());
94 detection_frame->setBackgroundLevel(background, background_model.getMedianRms());
101 if (background_config.isDetectionThresholdAbsolute()) {
102 detection_frame->setDetectionThreshold(background_config.getDetectionThreshold());
105 auto img_source = getDependency<DetectionImageConfig>().getImageSource(i);
106 detection_frame->setMetadata(img_source->getMetadata());
108 detection_frame->setHduIndex(i);
115 m_frames.emplace_back(detection_frame);