SourceXtractorPlusPlus  0.11
Please provide a description of the project.
ScaledImageSource.h
Go to the documentation of this file.
1 
18 #ifndef _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
19 #define _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
20 
23 
24 namespace SourceXtractor {
25 
33 template<typename T>
34 class ScaledImageSource : public ImageSource<T> {
35 public:
37  enum class InterpolationType {
39  };
40 
52  ScaledImageSource(const std::shared_ptr<Image<T>>& image, int width, int height, InterpolationType interp_type = InterpolationType::BICUBIC)
53  : m_image(image), m_width(width), m_height(height) {
54  m_wscale = std::ceil(static_cast<float>(width) / image->getWidth());
55  m_hscale = std::ceil(static_cast<float>(height) / image->getHeight());
56 
57  switch (interp_type) {
60  break;
63  break;
64  }
65 
66  // Generate y coordinates on the original image
67  std::vector<double> y_coords(image->getHeight());
68  for (size_t i = 0; i < y_coords.size(); ++i) {
69  y_coords[i] = std::floor((i + 0.5) * m_hscale);
70  }
71 
72  // Generate x coordinates on the original image
73  m_x_coords.resize(image->getWidth());
74  for (size_t i = 0; i < m_x_coords.size(); ++i) {
75  m_x_coords[i] = std::floor((i + 0.5) * m_wscale);
76  }
77 
78  // Store interpolation along columns
79  m_interpolated_cols.reserve(image->getWidth());
80  for (int x = 0; x < image->getWidth(); ++x) {
81  std::vector<double> values(image->getHeight());
82  for (int y = 0; y < image->getHeight(); ++y) {
83  values[y] = image->getValue(x, y);
84  }
86  Euclid::MathUtils::interpolate(y_coords, values, m_interpolation_type, true));
87  }
88  }
89 
93  virtual ~ScaledImageSource() = default;
94 
98  std::string getRepr() const final {
99  return std::string();
100  }
101 
115  std::shared_ptr<ImageTile<T>> getImageTile(int x, int y, int width, int height) const final {
116  auto tile = std::make_shared<ImageTile<T>>(x, y, width, height);
117 
118  for (int off_y = 0; off_y < height; ++off_y) {
120  for (size_t ix = 0; ix < m_x_coords.size(); ++ix) {
121  auto& fy = *m_interpolated_cols[ix];
122  v[ix] = fy(y + off_y);
123  }
125  for (int off_x = 0; off_x < width; ++off_x) {
126  tile->setValue(x + off_x, y + off_y, (*fx)(x + off_x));
127  }
128  }
129  return tile;
130  }
131 
135  void saveTile(ImageTile<T>&) final {
136  assert(false);
137  }
138 
142  int getWidth() const final {
143  return m_width;
144  }
145 
149  int getHeight() const final {
150  return m_height;
151  }
152 
153 private:
160 };
161 
162 } // end of namespace SourceXtractor
163 
164 #endif // _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
std::vector::resize
T resize(T... args)
std::floor
T floor(T... args)
Euclid::MathUtils::InterpolationType::CUBIC_SPLINE
@ CUBIC_SPLINE
SourceXtractor::ScaledImageSource::m_width
int m_width
Definition: ScaledImageSource.h:155
SourceXtractor::ScaledImageSource::m_interpolated_cols
std::vector< std::unique_ptr< Euclid::MathUtils::Function > > m_interpolated_cols
Definition: ScaledImageSource.h:157
std::string
STL class.
std::shared_ptr
STL class.
SourceXtractor::ScaledImageSource::getHeight
int getHeight() const final
Definition: ScaledImageSource.h:149
SourceXtractor::ScaledImageSource::InterpolationType::BICUBIC
@ BICUBIC
std::vector::reserve
T reserve(T... args)
std::vector< double >
std::vector::size
T size(T... args)
SourceXtractor::ScaledImageSource::InterpolationType
InterpolationType
Interpolation type: bilinear or bicubic.
Definition: ScaledImageSource.h:37
SourceXtractor::ScaledImageSource::~ScaledImageSource
virtual ~ScaledImageSource()=default
SourceXtractor::ScaledImageSource
Definition: ScaledImageSource.h:34
SourceXtractor::ScaledImageSource::getImageTile
std::shared_ptr< ImageTile< T > > getImageTile(int x, int y, int width, int height) const final
Definition: ScaledImageSource.h:115
SourceXtractor::ScaledImageSource::getWidth
int getWidth() const final
Definition: ScaledImageSource.h:142
SourceXtractor::Image
Interface representing an image.
Definition: Image.h:43
SourceXtractor::ScaledImageSource::m_x_coords
std::vector< double > m_x_coords
Definition: ScaledImageSource.h:158
SourceXtractor::ScaledImageSource::saveTile
void saveTile(ImageTile< T > &) final
Definition: ScaledImageSource.h:135
SourceXtractor::ScaledImageSource::m_wscale
double m_wscale
Definition: ScaledImageSource.h:159
SourceXtractor::ImageTile
Definition: ImageTile.h:57
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::ScaledImageSource::getRepr
std::string getRepr() const final
Definition: ScaledImageSource.h:98
SourceXtractor::ScaledImageSource::InterpolationType::BILINEAR
@ BILINEAR
SourceXtractor::ScaledImageSource::m_hscale
double m_hscale
Definition: ScaledImageSource.h:159
SourceXtractor::ScaledImageSource::m_interpolation_type
Euclid::MathUtils::InterpolationType m_interpolation_type
Definition: ScaledImageSource.h:156
std::ceil
T ceil(T... args)
SourceXtractor::ImageSource
Definition: ImageSource.h:41
Euclid::MathUtils::InterpolationType
InterpolationType
std::vector::emplace_back
T emplace_back(T... args)
interpolation.h
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:93
SourceXtractor::ScaledImageSource::m_height
int m_height
Definition: ScaledImageSource.h:155
ImageSource.h
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:93
SourceXtractor::ScaledImageSource::ScaledImageSource
ScaledImageSource(const std::shared_ptr< Image< T >> &image, int width, int height, InterpolationType interp_type=InterpolationType::BICUBIC)
Definition: ScaledImageSource.h:52
SourceXtractor::ScaledImageSource::m_image
std::shared_ptr< Image< T > > m_image
Definition: ScaledImageSource.h:154
Euclid::MathUtils::InterpolationType::LINEAR
@ LINEAR
Euclid::MathUtils::interpolate
ELEMENTS_API std::unique_ptr< Function > interpolate(const std::vector< double > &x, const std::vector< double > &y, InterpolationType type, bool extrapolate=false)