SourceXtractorPlusPlus  0.15
Please provide a description of the project.
SubImage.h
Go to the documentation of this file.
1 
18 #ifndef _SEFRAMEWORK_IMAGE_SUBIMAGE_H_
19 #define _SEFRAMEWORK_IMAGE_SUBIMAGE_H_
20 
21 #include <memory>
22 
25 
26 namespace SourceXtractor {
27 
33 template<typename T>
34 class SubImage : public Image<T> {
35 protected:
36  SubImage(std::shared_ptr<const Image<T>> image, const PixelCoordinate &offset, int width, int height)
37  : m_image(image), m_offset(offset), m_width(width), m_height(height) {
38  assert(offset.m_x >= 0 && offset.m_y >= 0 && width > 0 && height > 0 &&
39  offset.m_x + width <= image->getWidth() && offset.m_y + height <= image->getHeight());
40  }
41 
42  SubImage(std::shared_ptr<const Image<T>> image, int x, int y, int width, int height)
43  : m_image(image), m_offset(x, y), m_width(width), m_height(height) {
44  assert(x >= 0 && y >= 0 && width > 0 && height > 0 &&
45  x + width <= image->getWidth() && y + height <= image->getHeight());
46  }
47 
48 public:
52  virtual ~SubImage() = default;
53 
54  template<typename... Args>
55  static std::shared_ptr<SubImage<T>> create(Args &&... args) {
56  return std::shared_ptr<SubImage<T>>(new SubImage{std::forward<Args>(args)...});
57  }
58 
59  std::string getRepr() const override {
60  return "SubImage(" + m_image->getRepr() + ", " + std::to_string(m_offset.m_x) + ", " + std::to_string(m_offset.m_y) + ", " + std::to_string(m_width) + ", " + std::to_string(m_height) + ")";
61  }
62 
63  int getWidth() const override {
64  return m_width;
65  }
66 
67  int getHeight() const override {
68  return m_height;
69  }
70 
71  std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const override {
72  ImageAccessor<T> accessor(m_image);
73  auto chunk = UniversalImageChunk<T>::create(width, height);
74  for (int iy = 0; iy < height; ++iy) {
75  for (int ix = 0; ix < width; ++ix) {
76  chunk->at(ix, iy) = accessor.getValue(ix + x + m_offset.m_x, iy + y + m_offset.m_y);
77  }
78  }
79  return chunk;
80  }
81 
82 private:
86 };
87 
88 } /* namespace SourceXtractor */
89 
90 #endif /* _SEFRAMEWORK_IMAGE_SUBIMAGE_H_ */
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition: PixelCoordinate.h:37
SourceXtractor::ImageAccessor
Definition: ImageAccessor.h:41
std::string
STL class.
std::shared_ptr
STL class.
SourceXtractor::SubImage::m_offset
PixelCoordinate m_offset
Definition: SubImage.h:84
SourceXtractor::SubImage::~SubImage
virtual ~SubImage()=default
Destructor.
SourceXtractor::Image
Interface representing an image.
Definition: Image.h:43
SourceXtractor::SubImage::create
static std::shared_ptr< SubImage< T > > create(Args &&... args)
Definition: SubImage.h:55
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::SubImage::SubImage
SubImage(std::shared_ptr< const Image< T >> image, int x, int y, int width, int height)
Definition: SubImage.h:42
SourceXtractor::PixelCoordinate::m_x
int m_x
Definition: PixelCoordinate.h:38
SourceXtractor::SubImage::getHeight
int getHeight() const override
Returns the height of the image in pixels.
Definition: SubImage.h:67
SourceXtractor::PixelCoordinate::m_y
int m_y
Definition: PixelCoordinate.h:38
SourceXtractor::SubImage::SubImage
SubImage(std::shared_ptr< const Image< T >> image, const PixelCoordinate &offset, int width, int height)
Definition: SubImage.h:36
std::to_string
T to_string(T... args)
SourceXtractor::SubImage::getRepr
std::string getRepr() const override
Get a string identifying this image in a human readable manner.
Definition: SubImage.h:59
Image.h
SourceXtractor::ImageAccessor::getValue
T getValue(int x, int y)
Definition: ImageAccessor.h:100
SourceXtractor::SubImage
Part of another image.
Definition: SubImage.h:34
SourceXtractor::SubImage::m_height
int m_height
Definition: SubImage.h:85
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:94
SourceXtractor::UniversalImageChunk::create
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&... args)
Definition: ImageChunk.h:142
SourceXtractor::SubImage::m_width
int m_width
Definition: SubImage.h:85
SourceXtractor::SubImage::getChunk
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition: SubImage.h:71
SourceXtractor::SubImage::m_image
std::shared_ptr< const Image< T > > m_image
Definition: SubImage.h:83
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:94
ImageAccessor.h
SourceXtractor::SubImage::getWidth
int getWidth() const override
Returns the width of the image in pixels.
Definition: SubImage.h:63