SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
ScaledImageSource.h
Go to the documentation of this file.
1
18#ifndef _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
19#define _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
20
23#include "MathUtils/interpolation/interpolation.h"
24
25namespace SourceXtractor {
26
34template<typename T>
36public:
38 enum class InterpolationType {
40 };
41
54 : m_image(image), m_width(width), m_height(height) {
55 m_wscale = std::ceil(static_cast<float>(width) / image->getWidth());
56 m_hscale = std::ceil(static_cast<float>(height) / image->getHeight());
57
59
60 switch (interp_type) {
62 m_interpolation_type = Euclid::MathUtils::InterpolationType::CUBIC_SPLINE;
63 break;
65 m_interpolation_type = Euclid::MathUtils::InterpolationType::LINEAR;
66 break;
67 }
68
69 // Generate y coordinates on the original image
71 for (size_t i = 0; i < y_coords.size(); ++i) {
72 y_coords[i] = std::floor((i + 0.5) * m_hscale);
73 }
74
75 // Generate x coordinates on the original image
76 m_x_coords.resize(image->getWidth());
77 for (size_t i = 0; i < m_x_coords.size(); ++i) {
78 m_x_coords[i] = std::floor((i + 0.5) * m_wscale);
79 }
80
81 // Store interpolation along columns
82 m_interpolated_cols.reserve(image->getWidth());
83 for (int x = 0; x < image->getWidth(); ++x) {
84 std::vector<double> values(image->getHeight());
85 for (int y = 0; y < image->getHeight(); ++y) {
86 values[y] = accessor.getValue(x, y);
87 }
88 m_interpolated_cols.emplace_back(
90 }
91 }
92
96 virtual ~ScaledImageSource() = default;
97
102 return std::string("ScaledImageSource");
103 }
104
118 std::shared_ptr<ImageTile> getImageTile(int x, int y, int width, int height) const final {
119 auto tile = ImageTile::create(ImageTile::getTypeValue(T()), x, y, width, height);
120
121 for (int off_y = 0; off_y < height; ++off_y) {
123 for (size_t ix = 0; ix < m_x_coords.size(); ++ix) {
124 auto& fy = *m_interpolated_cols[ix];
125 v[ix] = fy(y + off_y);
126 }
128 for (int off_x = 0; off_x < width; ++off_x) {
129 tile->setValue(x + off_x, y + off_y, T((*fx)(x + off_x)));
130 }
131 }
132 return tile;
133 }
134
138 void saveTile(ImageTile&) final {
139 assert(false);
140 }
141
146 return m_width;
147 }
148
153 return m_height;
154 }
155
156 ImageTile::ImageType getType() const override {
157 return ImageTile::getTypeValue(T());
158 }
159
160private:
167};
168
169} // end of namespace SourceXtractor
170
171#endif // _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T ceil(T... args)
static ImageType getTypeValue(float)
Definition ImageTile.h:97
static std::shared_ptr< ImageTile > create(ImageType image_type, int x, int y, int width, int height, std::shared_ptr< ImageSource > source=nullptr)
Definition ImageTile.cpp:24
virtual ~ScaledImageSource()=default
ImageTile::ImageType getType() const override
ScaledImageSource(const std::shared_ptr< Image< T > > &image, int width, int height, InterpolationType interp_type=InterpolationType::BICUBIC)
std::string getRepr() const final
std::vector< std::unique_ptr< Euclid::MathUtils::Function > > m_interpolated_cols
std::shared_ptr< Image< T > > m_image
std::shared_ptr< ImageTile > getImageTile(int x, int y, int width, int height) const final
InterpolationType
Interpolation type: bilinear or bicubic.
Euclid::MathUtils::InterpolationType m_interpolation_type
T floor(T... args)
ELEMENTS_API std::unique_ptr< Function > interpolate(const std::vector< double > &x, const std::vector< double > &y, InterpolationType type, bool extrapolate=false)
T resize(T... args)
T size(T... args)