SourceXtractorPlusPlus  0.10
Please provide a description of the project.
SimpleBackgroundAnalyzer.cpp
Go to the documentation of this file.
1 
17 /*
18  * Background.cpp
19  *
20  * Created on: Oct 11, 2016
21  * Author: mschefer
22  */
23 
26 
27 #include <memory>
28 #include <algorithm>
29 
30 #include "ElementsKernel/Logging.h"
34 
35 
36 namespace SourceXtractor {
37 
41  WeightImage::PixelType /*variance_threshold*/) const {
42 
43  // FIXME we use a VectorImage the same size as input which won't allow larger than memory images to be processed
44 
45  auto image_copy = VectorImage<DetectionImage::PixelType>::create(*image);
46  std::sort(image_copy->getData().begin(), image_copy->getData().end());
47  bck_model_logger.debug() << "Using the SimpleBackgroundLeverAnalyzer";
48 
49  auto background_level = image_copy->getData()[image_copy->getData().size()/2]; // the median
50  auto background_level_map = ConstantImage<SeFloat>::create(image->getWidth(), image->getHeight(), background_level);
51 
52  auto subtracted_image = SubtractImage<SeFloat>::create(image, background_level_map);
53 
54  auto background_variance = getVariance(subtracted_image);
55  auto background_variance_map = ConstantImage<SeFloat>::create(image->getWidth(), image->getHeight(), background_variance);
56  bck_model_logger.debug() << "bg: " << background_level << " var: " << background_variance;
57 
58  return BackgroundModel(background_level_map, background_variance_map, 1.0);
59 }
60 
61 
63  // Note: We compute the RMS by only taking into consideration pixels
64  // below the background value.
65 
66  double variance = 0;
67  int pixels = 0;
68  for (int y=0; y < image->getHeight(); y++) {
69  for (int x=0; x < image->getWidth(); x++) {
70  auto value = image->getValue(x, y);
71  if (value < 0) {
72  variance += value * value;
73  pixels++;
74  }
75  }
76  }
77 
78  if (pixels > 0) {
79  variance /= pixels;
80  }
81 
82  return variance;
83 }
84 
85 }
86 
std::shared_ptr
STL class.
SourceXtractor::Image< SeFloat >::PixelType
SeFloat PixelType
Definition: Image.h:47
ConstantImage.h
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition: Types.h:32
SourceXtractor::SimpleBackgroundAnalyzer::getVariance
static SeFloat getVariance(std::shared_ptr< DetectionImage > image)
Definition: SimpleBackgroundAnalyzer.cpp:62
SourceXtractor::BackgroundModel
Definition: BackgroundAnalyzer.h:33
SourceXtractor::Image< unsigned char >
VectorImage.h
std::sort
T sort(T... args)
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:89
SourceXtractor::ConstantImage::create
static std::shared_ptr< ConstantImage< T > > create(int width, int height, T constant_value)
Definition: ConstantImage.h:42
ProcessedImage.h
Elements::Logging::debug
void debug(const std::string &logMessage)
SimpleBackgroundAnalyzer.h
SourceXtractor::ProcessedImage::create
static std::shared_ptr< ProcessedImage< T, P > > create(std::shared_ptr< const Image< T >> image_a, std::shared_ptr< const Image< T >> image_b)
Definition: ProcessedImage.h:54
SourceXtractor::bck_model_logger
static Elements::Logging bck_model_logger
Definition: SE2BackgroundUtils.h:33
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:93
SE2BackgroundUtils.h
Logging.h
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:93
SourceXtractor::SimpleBackgroundAnalyzer::analyzeBackground
BackgroundModel analyzeBackground(std::shared_ptr< DetectionImage > image, std::shared_ptr< WeightImage > variance_map, std::shared_ptr< Image< unsigned char >> mask, WeightImage::PixelType variance_threshold) const override
Definition: SimpleBackgroundAnalyzer.cpp:38