SourceXtractorPlusPlus  0.13
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 
28 #include "VectorImage.h"
29 
30 namespace SourceXtractor {
31 
44 template<typename T, typename M, template <typename> class Operator = std::bit_and>
45 class MaskedImage : public ImageBase<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  T getValue(int x, int y) const final {
86  if (m_operator(m_mask->getValue(x, y), m_mask_flag))
87  return m_replacement;
88  return m_image->getValue(x, y);
89  }
90 
91  int getWidth() const final {
92  return m_image->getWidth();
93  }
94 
95  int getHeight() const final {
96  return m_image->getHeight();
97  }
98 
99  std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const final {
100  auto chunk = UniversalImageChunk<T>::create(std::move(*m_image->getChunk(x, y, width, height)));
101  auto mask_chunk = m_mask->getChunk(x, y, width, height);
102  for (int iy = 0; iy < height; ++iy) {
103  for (int ix = 0; ix < width; ++ix) {
104  if (m_operator(mask_chunk->getValue(ix, iy), m_mask_flag))
105  chunk->setValue(ix, iy, m_replacement);
106  }
107  }
108  return chunk;
109  }
110 };
111 
112 } // end of namespace SourceXtractor
113 
114 #endif // SEFRAMEWORK_SEFRAMEWORK_IMAGE_MASKEDIMAGE_H_
std::shared_ptr< Image< M > > m_mask
Definition: MaskedImage.h:53
T getValue(int x, int y) const final
Returns the value of the pixel with the coordinates (x,y)
Definition: MaskedImage.h:85
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:95
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:132
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:99
int getWidth() const final
Returns the width of the image in pixels.
Definition: MaskedImage.h:91