SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaskedImage.h
Go to the documentation of this file.
1 
17 /*
18 * MaskedImage.h
19 *
20 * Created on: Feb 13, 2020
21 * Author: Alejandro Alvarez Ayllon
22 */
23 
24 #ifndef SEFRAMEWORK_SEFRAMEWORK_IMAGE_MASKEDIMAGE_H_
25 #define SEFRAMEWORK_SEFRAMEWORK_IMAGE_MASKEDIMAGE_H_
26 
29 
30 namespace SourceXtractor {
31 
44 template<typename T, typename M, template <typename> class Operator = std::bit_and>
45 class MaskedImage : public Image<T> {
46 private:
48  T replacement, M mask_flag) : m_image{image}, m_mask{mask}, m_replacement{replacement},
49  m_mask_flag{mask_flag} {
50  }
51 
56  Operator<M> m_operator;
57 
58 public:
59  virtual ~MaskedImage() = default;
60 
76  T replacement, M mask_flag = 0x01) {
77  assert(image->getWidth() == mask->getWidth() && image->getHeight() == mask->getHeight());
78  return std::shared_ptr<MaskedImage<T, M, Operator>>(new MaskedImage<T, M, Operator>(image, mask, replacement, mask_flag));
79  }
80 
81  std::string getRepr() const final {
82  return std::string("Masked(" + m_image->getRepr() + ")");
83  }
84 
85  int getWidth() const final {
86  return m_image->getWidth();
87  }
88 
89  int getHeight() const final {
90  return m_image->getHeight();
91  }
92 
93  std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const final {
94  auto chunk = UniversalImageChunk<T>::create(std::move(*m_image->getChunk(x, y, width, height)));
95  auto mask_chunk = m_mask->getChunk(x, y, width, height);
96  for (int iy = 0; iy < height; ++iy) {
97  for (int ix = 0; ix < width; ++ix) {
98  if (m_operator(mask_chunk->getValue(ix, iy), m_mask_flag))
99  chunk->setValue(ix, iy, m_replacement);
100  }
101  }
102  return chunk;
103  }
104 
105 };
106 
107 } // end of namespace SourceXtractor
108 
109 #endif // SEFRAMEWORK_SEFRAMEWORK_IMAGE_MASKEDIMAGE_H_
std::shared_ptr< Image< M > > m_mask
Definition: MaskedImage.h:53
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< Image< T > > m_image
Definition: MaskedImage.h:52
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
int getHeight() const final
Returns the height of the image in pixels.
Definition: MaskedImage.h:89
STL class.
MaskedImage(const std::shared_ptr< Image< T >> &image, const std::shared_ptr< Image< M >> &mask, T replacement, M mask_flag)
Definition: MaskedImage.h:47
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&...args)
Definition: ImageChunk.h:142
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
Definition: MaskedImage.h:81
static std::shared_ptr< MaskedImage< T, M, Operator > > create(const std::shared_ptr< Image< T >> &image, const std::shared_ptr< Image< M >> &mask, T replacement, M mask_flag=0x01)
Definition: MaskedImage.h:75
T move(T...args)
virtual ~MaskedImage()=default
Interface representing an image.
Definition: Image.h:43
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const final
Definition: MaskedImage.h:93
int getWidth() const final
Returns the width of the image in pixels.
Definition: MaskedImage.h:85