SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
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
30namespace SourceXtractor {
31
44template<typename T, typename M, template <typename> class Operator = std::bit_and>
45class MaskedImage : public Image<T> {
46private:
51
57
60
61public:
62 virtual ~MaskedImage() = default;
63
79 T replacement, M mask_flag = 0x01) {
80 assert(image->getWidth() == mask->getWidth() && image->getHeight() == mask->getHeight());
82 }
83
85 if (m_n_total == (m_image->getWidth()*m_image->getHeight())){
86 char char_fract[8];
87 // determine the percentage of masked pixels
88 std::snprintf(char_fract, 7, "%.1f%", 100.0*this->getNMasked()/(m_image->getWidth()*m_image->getHeight()));
89 return std::string("Masked(" + m_image->getRepr() + ") with "+std::string(char_fract)+" weight image masked pixels;");
90 }
91 else
92 return std::string("Masked(" + m_image->getRepr() + ")");
93 }
94
96 return m_image->getWidth();
97 }
98
100 return m_image->getHeight();
101 }
102
104 return m_n_masked;
105 }
106
108 return m_n_total;
109 }
110
111 std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const final {
112 auto chunk = UniversalImageChunk<T>::create(std::move(*m_image->getChunk(x, y, width, height)));
113 auto mask_chunk = m_mask->getChunk(x, y, width, height);
114 for (int iy = 0; iy < height; ++iy) {
115 for (int ix = 0; ix < width; ++ix) {
116 m_n_total += 1;
117 if (m_operator(mask_chunk->getValue(ix, iy), m_mask_flag)){
118 chunk->setValue(ix, iy, m_replacement);
119 m_n_masked+=1;
120 }
121 }
122 }
123 return chunk;
124 }
125
126};
127
128} // end of namespace SourceXtractor
129
130#endif // SEFRAMEWORK_SEFRAMEWORK_IMAGE_MASKEDIMAGE_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:44
int getHeight() const final
Returns the height of the image in pixels.
Definition MaskedImage.h:99
std::size_t getNTotal() const
int getWidth() const final
Returns the width of the image in pixels.
Definition MaskedImage.h:95
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
Definition MaskedImage.h:84
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< 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:78
std::size_t getNMasked() const
virtual ~MaskedImage()=default
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const final
std::shared_ptr< Image< M > > m_mask
Definition MaskedImage.h:53
std::shared_ptr< Image< T > > m_image
Definition MaskedImage.h:52
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&... args)
Definition ImageChunk.h:144
T snprintf(T... args)
T move(T... args)