SourceXtractorPlusPlus
0.15
Please provide a description of the project.
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SEFramework
SEFramework
Image
ScaledImageSource.h
Go to the documentation of this file.
1
18
#ifndef _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
19
#define _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
20
21
#include "
SEFramework/Image/ImageAccessor.h
"
22
#include "
SEFramework/Image/ImageSource.h
"
23
#include "
MathUtils/interpolation/interpolation.h
"
24
25
namespace
SourceXtractor {
26
34
template
<
typename
T>
35
class
ScaledImageSource
:
public
ImageSource
{
36
public
:
38
enum class
InterpolationType
{
39
BILINEAR
,
BICUBIC
40
};
41
53
ScaledImageSource
(
const
std::shared_ptr
<
Image<T>
>& image,
int
width
,
int
height
,
InterpolationType
interp_type =
InterpolationType::BICUBIC
)
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
58
ImageAccessor<T>
accessor(image);
59
60
switch
(interp_type) {
61
case
InterpolationType::BICUBIC
:
62
m_interpolation_type
=
Euclid::MathUtils::InterpolationType::CUBIC_SPLINE
;
63
break
;
64
case
InterpolationType::BILINEAR
:
65
m_interpolation_type
=
Euclid::MathUtils::InterpolationType::LINEAR
;
66
break
;
67
}
68
69
// Generate y coordinates on the original image
70
std::vector<double>
y_coords(image->getHeight());
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
(
89
Euclid::MathUtils::interpolate
(y_coords, values,
m_interpolation_type
,
true
));
90
}
91
}
92
96
virtual
~ScaledImageSource
() =
default
;
97
101
std::string
getRepr
() const final {
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) {
122
std::vector<double>
v(
m_x_coords
);
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
}
127
auto
fx =
Euclid::MathUtils::interpolate
(
m_x_coords
, v,
m_interpolation_type
,
true
);
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
145
int
getWidth
() const final {
146
return
m_width
;
147
}
148
152
int
getHeight
() const final {
153
return
m_height
;
154
}
155
156
ImageTile::ImageType
getType
()
const override
{
157
return
ImageTile::getTypeValue
(T());
158
}
159
160
private
:
161
std::shared_ptr<Image<T>
>
m_image
;
162
int
m_width
,
m_height
;
163
Euclid::MathUtils::InterpolationType
m_interpolation_type
;
164
std::vector<std::unique_ptr<Euclid::MathUtils::Function>
>
m_interpolated_cols
;
165
std::vector<double>
m_x_coords
;
166
double
m_wscale
,
m_hscale
;
167
};
168
169
}
// end of namespace SourceXtractor
170
171
#endif // _SEFRAMEWORK_IMAGE_SCALEDIMAGESOURCE_H
SourceXtractor::ScaledImageSource::m_image
std::shared_ptr< Image< T > > m_image
Definition:
ScaledImageSource.h:161
std::shared_ptr
ImageSource.h
SourceXtractor::ScaledImageSource::~ScaledImageSource
virtual ~ScaledImageSource()=default
SourceXtractor::ScaledImageSource::getImageTile
std::shared_ptr< ImageTile > getImageTile(int x, int y, int width, int height) const final
Definition:
ScaledImageSource.h:118
std::ceil
T ceil(T...args)
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition:
MoffatModelFittingTask.cpp:94
SourceXtractor::ScaledImageSource::getHeight
int getHeight() const final
Definition:
ScaledImageSource.h:152
SourceXtractor::ScaledImageSource::InterpolationType::BILINEAR
SourceXtractor::ScaledImageSource::m_wscale
double m_wscale
Definition:
ScaledImageSource.h:166
ImageAccessor.h
SourceXtractor::ScaledImageSource::InterpolationType
InterpolationType
Interpolation type: bilinear or bicubic.
Definition:
ScaledImageSource.h:38
std::floor
T floor(T...args)
interpolation.h
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition:
MoffatModelFittingTask.cpp:94
SourceXtractor::ScaledImageSource::getRepr
std::string getRepr() const final
Definition:
ScaledImageSource.h:101
std::vector::resize
T resize(T...args)
std::string
STL class.
SourceXtractor::ImageTile::ImageType
ImageType
Definition:
ImageTile.h:37
SourceXtractor::ScaledImageSource::getWidth
int getWidth() const final
Definition:
ScaledImageSource.h:145
SourceXtractor::ScaledImageSource::m_x_coords
std::vector< double > m_x_coords
Definition:
ScaledImageSource.h:165
SourceXtractor::ScaledImageSource::m_hscale
double m_hscale
Definition:
ScaledImageSource.h:166
SourceXtractor::ScaledImageSource
Definition:
ScaledImageSource.h:35
SourceXtractor::ImageTile
Definition:
ImageTile.h:34
SourceXtractor::ScaledImageSource::InterpolationType::BICUBIC
Euclid::MathUtils::InterpolationType::LINEAR
SourceXtractor::ImageAccessor
Definition:
ImageAccessor.h:41
SourceXtractor::ScaledImageSource::m_interpolation_type
Euclid::MathUtils::InterpolationType m_interpolation_type
Definition:
ScaledImageSource.h:163
SourceXtractor::ImageSource
Definition:
ImageSource.h:52
std::vector::size
T size(T...args)
std::vector< double >
SourceXtractor::ImageTile::create
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
ModelFitting::height
height
Definition:
CompactModelBase.icpp:19
SourceXtractor::Image
Interface representing an image.
Definition:
Image.h:43
SourceXtractor::ScaledImageSource::ScaledImageSource
ScaledImageSource(const std::shared_ptr< Image< T >> &image, int width, int height, InterpolationType interp_type=InterpolationType::BICUBIC)
Definition:
ScaledImageSource.h:53
Euclid::MathUtils::InterpolationType
InterpolationType
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)
ModelFitting::width
width
Definition:
CompactModelBase.icpp:19
Euclid::MathUtils::InterpolationType::CUBIC_SPLINE
SourceXtractor::ScaledImageSource::saveTile
void saveTile(ImageTile &) final
Definition:
ScaledImageSource.h:138
SourceXtractor::ScaledImageSource::m_height
int m_height
Definition:
ScaledImageSource.h:162
SourceXtractor::ImageTile::getTypeValue
static ImageType getTypeValue(float)
Definition:
ImageTile.h:99
SourceXtractor::ScaledImageSource::m_width
int m_width
Definition:
ScaledImageSource.h:162
SourceXtractor::ScaledImageSource::m_interpolated_cols
std::vector< std::unique_ptr< Euclid::MathUtils::Function > > m_interpolated_cols
Definition:
ScaledImageSource.h:164
SourceXtractor::ScaledImageSource::getType
ImageTile::ImageType getType() const override
Definition:
ScaledImageSource.h:156
std::vector::reserve
T reserve(T...args)
std::vector::emplace_back
T emplace_back(T...args)
Generated by
1.8.5