SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiThresholdPartitionConfig.cpp
Go to the documentation of this file.
1 
17 /*
18  * MultiThresholdPartitionConfig.cpp
19  *
20  * Created on: Jan 18, 2017
21  * Author: mschefer
22  */
23 
27 
29 
30 using namespace Euclid::Configuration;
31 namespace po = boost::program_options;
32 
33 namespace SourceXtractor {
34 
35 static const std::string MTHRESH_USE {"partition-multithreshold"};
36 static const std::string MTHRESH_THRESHOLDS_NB {"partition-threshold-count"};
37 static const std::string MTHRESH_MIN_AREA {"partition-minimum-area"};
38 static const std::string MTHRESH_MIN_CONTRAST {"partition-minimum-contrast"};
39 
40 MultiThresholdPartitionConfig::MultiThresholdPartitionConfig(long manager_id) : Configuration(manager_id) {
41  declareDependency<PartitionStepConfig>();
42 
44 }
45 
47  return { {"Multi-thresholding", {
48  {MTHRESH_USE.c_str(), po::bool_switch(), "activates multithreshold partitioning"},
49  {MTHRESH_THRESHOLDS_NB.c_str(), po::value<int>()->default_value(32), "# of thresholds"},
50  {MTHRESH_MIN_AREA.c_str(), po::value<int>()->default_value(3), "min area in pixels to consider partitioning"},
51  {MTHRESH_MIN_CONTRAST.c_str(), po::value<double>()->default_value(0.005), "min contrast of for partitioning"}
52  }}};
53 }
54 
55 void MultiThresholdPartitionConfig::initialize(const UserValues& args) {
56  if (args.at(MTHRESH_USE).as<bool>()) {
57  auto threshold_nb = args.at(MTHRESH_THRESHOLDS_NB).as<int>();
58  auto min_area = args.at(MTHRESH_MIN_AREA).as<int>();
59  auto min_contrast = args.at(MTHRESH_MIN_CONTRAST).as<double>();
60 
61  if (min_area <= 0) {
62  throw Elements::Exception() << "Invalid " << MTHRESH_MIN_AREA << " value: " << min_area;
63  }
64  if (threshold_nb <= 0) {
65  throw Elements::Exception() << "Invalid " << MTHRESH_THRESHOLDS_NB << " value: " << threshold_nb;
66  }
67 
68  getDependency<PartitionStepConfig>().addPartitionStepCreator(
69  [=](std::shared_ptr<SourceFactory> source_factory) {
70  return std::make_shared<MultiThresholdPartitionStep>(source_factory, min_contrast, threshold_nb, min_area);
71  }
72  );
73  }
74 }
75 
76 } // SourceXtractor namespace
std::map< std::string, OptionDescriptionList > getProgramOptions() override
static ConfigManager & getInstance(long id)
static const std::string MTHRESH_MIN_CONTRAST
STL class.
STL class.
static const std::string MTHRESH_MIN_AREA
static const std::string MTHRESH_USE
static const std::string MTHRESH_THRESHOLDS_NB
T c_str(T...args)