SourceXtractorPlusPlus  0.15
Please provide a description of the project.
ThresholdedImage.h
Go to the documentation of this file.
1 
17 /*
18  * ThresholdedImage.h
19  *
20  * Created on: Jan 10, 2018
21  * Author: mschefer
22  */
23 
24 #ifndef _SEFRAMEWORK_IMAGE_THRESHOLDEDIMAGE_H_
25 #define _SEFRAMEWORK_IMAGE_THRESHOLDEDIMAGE_H_
26 
27 #include <memory>
28 
32 
33 namespace SourceXtractor {
34 
40 template <typename T>
41 class ThresholdedImage : public Image<T> {
42 
43 protected:
44 
45  ThresholdedImage(std::shared_ptr<const Image<T>> image, std::shared_ptr<const Image<T>> variance_map, T threshold_multiplier)
46  : m_image(image), m_variance_map(variance_map), m_threshold_multiplier(threshold_multiplier) {
47  assert(m_image->getWidth() == m_variance_map->getWidth());
48  assert(m_image->getHeight() == m_variance_map->getHeight());
49  };
50 
51 public:
52 
56  virtual ~ThresholdedImage() = default;
57 
59  std::shared_ptr<const Image<T>> image, std::shared_ptr<const Image<T>> variance_map, T threshold_multiplier) {
60  return std::shared_ptr<ThresholdedImage<T>>(new ThresholdedImage<T>(image, variance_map, threshold_multiplier));
61  }
62 
63  std::string getRepr() const override {
64  return "ThresholdedImage(" + m_image->getRepr() + ")";
65  }
66 
67  int getWidth() const override {
68  return m_image->getWidth();
69  }
70 
71  int getHeight() const override {
72  return m_image->getHeight();
73  }
74 
75  std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const override{
76  auto img_chunk = m_image->getChunk(x, y, width, height);
77  auto var_chunk = m_variance_map->getChunk(x, y, width, height);
78  auto chunk = UniversalImageChunk<T>::create(std::move(*img_chunk));
79  for (int iy = 0; iy < height; ++iy) {
80  for (int ix = 0; ix < width; ++ix) {
81  chunk->at(ix, iy) -= sqrt(var_chunk->getValue(ix, iy)) * m_threshold_multiplier;
82  }
83  }
84  return chunk;
85  }
86 
87 private:
90 
91 }; /* End of ThresholdedImage class */
92 
93 } /* namespace SourceXtractor */
94 
95 #endif /* _SEFRAMEWORK_IMAGE_THRESHOLDEDIMAGE_H_ */
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Interface representing an image.
Definition: Image.h:43
Used to subtract a constant value from an Image.
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
std::shared_ptr< const Image< T > > m_variance_map
ThresholdedImage(std::shared_ptr< const Image< T >> image, std::shared_ptr< const Image< T >> variance_map, T threshold_multiplier)
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)
std::shared_ptr< const Image< T > > m_image
int getHeight() const override
Returns the height of the image in pixels.
int getWidth() const override
Returns the width of the image in pixels.
std::string getRepr() const override
Get a string identifying this image in a human readable manner.
virtual ~ThresholdedImage()=default
Destructor.
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&... args)
Definition: ImageChunk.h:142
T move(T... args)
T sqrt(T... args)