SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEFramework
SEFramework
Image
PaddedImage.h
Go to the documentation of this file.
1
17
/*
18
* @file SEFramework/Image/PaddedImage.h
19
* @date 10/09/18
20
* @author aalvarez
21
*/
22
23
#ifndef _SEFRAMEWORK_IMAGE_PADDEDIMAGE_H
24
#define _SEFRAMEWORK_IMAGE_PADDEDIMAGE_H
25
26
#include "
SEFramework/Image/Image.h
"
27
#include "
SEFramework/Image/ImageChunk.h
"
28
#include "
SEFramework/Image/ImageAccessor.h
"
29
30
namespace
SourceXtractor
{
31
32
inline
int
ReplicateCoordinates
(
int
N
,
int
v
) {
33
if
(
v
< 0)
return
0;
34
if
(
v
>
N
- 1)
return
N
- 1;
35
return
v
;
36
}
37
38
inline
int
ReflectCoordinates
(
int
N
,
int
v
) {
39
if
(
v
>= 0 &&
v
<
N
) {
40
return
v
;
41
}
42
43
if
(
v
< 0) ++
v
;
44
v
=
std::abs
(
v
);
45
46
int
offset =
v
%
N
;
47
int
ntimes
=
v
/
N
;
48
49
if
(
ntimes
% 2 == 0) {
50
return
offset;
51
}
52
return
N
- offset - 1;
53
}
54
55
inline
int
Reflect101Coordinates
(
int
N
,
int
v
) {
56
if
(
v
>= 0 &&
v
<
N
) {
57
return
v
;
58
}
59
60
int
max
=
N
- 1;
61
v
=
std::abs
(
v
);
62
int
offset =
v
%
max
;
63
int
ntimes
=
v
/
max
;
64
65
if
(
ntimes
% 2 == 0) {
66
return
offset;
67
}
68
return
max
- offset;
69
}
70
71
inline
int
WrapCoordinates
(
int
N
,
int
v
) {
72
return
(
v
%
N
+
N
) %
N
;
73
}
74
75
template
<
typename
T,
int
CoordinateInterpolation(
int
,
int
) =
nullptr
>
76
class
PaddedImage
:
public
Image
<T> {
77
protected
:
78
PaddedImage
(
std::shared_ptr
<
const
Image<T>
>
img
,
int
width,
int
height)
79
:
m_img
{
img
},
m_width
{width},
m_height
{height} {
80
auto
wdiff
=
m_width
-
img
->getWidth();
81
auto
hdiff
=
m_height
-
img
->getHeight();
82
83
m_lpad
=
wdiff
/ 2;
84
m_tpad
=
hdiff
/ 2;
85
}
86
87
public
:
88
template
<
typename
...
Args
>
89
static
std::shared_ptr<PaddedImage<T, CoordinateInterpolation>
>
create
(
Args
&&...
args
) {
90
return
std::shared_ptr<PaddedImage<T, CoordinateInterpolation>
>(
new
PaddedImage
{
std::forward<Args>
(
args
)...});
91
}
92
93
std::string
getRepr
()
const override
{
94
return
"PaddedImage("
+
m_img
->getRepr() +
")"
;
95
}
96
97
int
getWidth
()
const override
{
98
return
m_width
;
99
}
100
101
int
getHeight
()
const override
{
102
return
m_height
;
103
}
104
105
std::shared_ptr<ImageChunk<T>
>
getChunk
(
int
x
,
int
y
,
int
width,
int
height)
const override
{
106
ImageAccessor<T>
accessor
(
m_img
,
ImageAccessor<T>::TOP_LEFT
, width, height);
107
auto
chunk
=
UniversalImageChunk<T>::create
(width, height);
108
auto
img_w
=
accessor
.getWidth();
109
auto
img_h
=
accessor
.getHeight();
110
for
(
int
iy
= 0;
iy
< height; ++
iy
) {
111
for
(
int
ix
= 0;
ix
< width; ++
ix
) {
112
auto
img_x
=
CoordinateInterpolation
(
img_w
,
ix
+
x
-
m_lpad
);
113
auto
img_y
=
CoordinateInterpolation
(
img_h
,
iy
+
y
-
m_tpad
);
114
chunk
->at(
ix
,
iy
) =
accessor
.getValue(
img_x
,
img_y
);
115
}
116
}
117
return
chunk
;
118
}
119
120
private
:
121
std::shared_ptr<const Image<T>
>
m_img
;
122
int
m_width
,
m_height
;
123
int
m_lpad
,
m_tpad
;
124
};
125
126
127
template
<
typename
T>
128
class
PaddedImage
<T,
nullptr
> :
public
Image
<T> {
129
protected
:
130
PaddedImage
(
std::shared_ptr
<
const
Image<T>
>
img
,
int
width,
int
height, T
default_value
)
131
:
m_img
{
img
},
m_width
{width},
m_height
{height}, m_default{
default_value
} {
132
auto
wdiff
=
m_width
-
img
->getWidth();
133
auto
hdiff
=
m_height
-
img
->getHeight();
134
135
m_lpad
=
wdiff
/ 2;
136
m_tpad
=
hdiff
/ 2;
137
}
138
139
PaddedImage
(
std::shared_ptr
<
const
Image<T>
>
img
,
int
width,
int
height):
PaddedImage
(
img
, width, height, {}) {
140
}
141
142
public
:
143
template
<
typename
... Args>
144
static
std::shared_ptr<PaddedImage<T, nullptr>
>
create
(
Args
&&...
args
) {
145
return
std::shared_ptr<PaddedImage<T, nullptr>
>(
new
PaddedImage
{
std::forward<Args>
(
args
)...});
146
}
147
148
std::string
getRepr
()
const override
{
149
return
"PaddedImage("
+
m_img
->getRepr() +
")"
;
150
}
151
152
int
getWidth
()
const override
{
153
return
m_width
;
154
}
155
156
int
getHeight
()
const override
{
157
return
m_height
;
158
}
159
160
std::shared_ptr<ImageChunk<T>
>
getChunk
(
int
x
,
int
y
,
int
width,
int
height)
const override
{
161
ImageAccessor<T>
accessor
(
m_img
,
ImageAccessor<T>::TOP_LEFT
, width, height);
162
163
auto
chunk
=
UniversalImageChunk<T>::create
(width, height);
164
auto
img_w
=
accessor
.getWidth();
165
auto
img_h
=
accessor
.getHeight();
166
for
(
int
iy
= 0;
iy
< height; ++
iy
) {
167
for
(
int
ix
= 0;
ix
< width; ++
ix
) {
168
auto
img_x
=
x
+
ix
;
169
auto
img_y
=
y
+
iy
;
170
if
(
img_x
<
m_lpad
||
img_y < m_tpad || img_x >
=
img_w
+
m_lpad
||
171
img_y
>=
img_h
+
m_tpad
) {
172
chunk
->at(
ix
,
iy
) = m_default;
173
}
174
else
{
175
chunk
->at(
ix
,
iy
) =
accessor
.getValue(
img_x
-
m_lpad
,
img_y
-
m_tpad
);
176
}
177
}
178
}
179
return
chunk
;
180
}
181
182
private
:
183
std::shared_ptr<const Image<T>
>
m_img
;
184
int
m_width
,
m_height
;
185
int
m_lpad
,
m_tpad
;
186
T
m_default
;
187
};
188
189
}
// end SourceXtractor
190
191
#endif
// _SEFRAMEWORK_IMAGE_PADDEDIMAGE_H
ImageAccessor.h
ImageChunk.h
Image.h
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition
MoffatModelFittingTask.cpp:94
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition
MoffatModelFittingTask.cpp:94
std::string
SourceXtractor::ImageAccessor
Definition
ImageAccessor.h:41
SourceXtractor::Image
Interface representing an image.
Definition
Image.h:44
SourceXtractor::PaddedImage< T, nullptr >::getRepr
std::string getRepr() const override
Get a string identifying this image in a human readable manner.
Definition
PaddedImage.h:148
SourceXtractor::PaddedImage< T, nullptr >::PaddedImage
PaddedImage(std::shared_ptr< const Image< T > > img, int width, int height)
Definition
PaddedImage.h:139
SourceXtractor::PaddedImage< T, nullptr >::m_img
std::shared_ptr< const Image< T > > m_img
Definition
PaddedImage.h:183
SourceXtractor::PaddedImage< T, nullptr >::PaddedImage
PaddedImage(std::shared_ptr< const Image< T > > img, int width, int height, T default_value)
Definition
PaddedImage.h:130
SourceXtractor::PaddedImage< T, nullptr >::m_height
int m_height
Definition
PaddedImage.h:184
SourceXtractor::PaddedImage< T, nullptr >::m_default
T m_default
Definition
PaddedImage.h:186
SourceXtractor::PaddedImage< T, nullptr >::m_lpad
int m_lpad
Definition
PaddedImage.h:185
SourceXtractor::PaddedImage< T, nullptr >::getWidth
int getWidth() const override
Returns the width of the image in pixels.
Definition
PaddedImage.h:152
SourceXtractor::PaddedImage< T, nullptr >::create
static std::shared_ptr< PaddedImage< T, nullptr > > create(Args &&... args)
Definition
PaddedImage.h:144
SourceXtractor::PaddedImage< T, nullptr >::getHeight
int getHeight() const override
Returns the height of the image in pixels.
Definition
PaddedImage.h:156
SourceXtractor::PaddedImage< T, nullptr >::getChunk
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition
PaddedImage.h:160
SourceXtractor::PaddedImage
Definition
PaddedImage.h:76
SourceXtractor::PaddedImage::PaddedImage
PaddedImage(std::shared_ptr< const Image< T > > img, int width, int height)
Definition
PaddedImage.h:78
SourceXtractor::PaddedImage::getHeight
int getHeight() const override
Returns the height of the image in pixels.
Definition
PaddedImage.h:101
SourceXtractor::PaddedImage::getChunk
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition
PaddedImage.h:105
SourceXtractor::PaddedImage::m_width
int m_width
Definition
PaddedImage.h:122
SourceXtractor::PaddedImage::m_img
std::shared_ptr< const Image< T > > m_img
Definition
PaddedImage.h:121
SourceXtractor::PaddedImage::m_height
int m_height
Definition
PaddedImage.h:122
SourceXtractor::PaddedImage::m_tpad
int m_tpad
Definition
PaddedImage.h:123
SourceXtractor::PaddedImage::m_lpad
int m_lpad
Definition
PaddedImage.h:123
SourceXtractor::PaddedImage::getRepr
std::string getRepr() const override
Get a string identifying this image in a human readable manner.
Definition
PaddedImage.h:93
SourceXtractor::PaddedImage::create
static std::shared_ptr< PaddedImage< T, CoordinateInterpolation > > create(Args &&... args)
Definition
PaddedImage.h:89
SourceXtractor::PaddedImage::getWidth
int getWidth() const override
Returns the width of the image in pixels.
Definition
PaddedImage.h:97
SourceXtractor::UniversalImageChunk::create
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&... args)
Definition
ImageChunk.h:144
std::function
std::max
T max(T... args)
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::ReflectCoordinates
int ReflectCoordinates(int N, int v)
Definition
PaddedImage.h:38
SourceXtractor::ReplicateCoordinates
int ReplicateCoordinates(int N, int v)
Definition
PaddedImage.h:32
SourceXtractor::WrapCoordinates
int WrapCoordinates(int N, int v)
Definition
PaddedImage.h:71
SourceXtractor::Reflect101Coordinates
int Reflect101Coordinates(int N, int v)
Definition
PaddedImage.h:55
std::shared_ptr
Generated by
1.10.0