SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEFramework
SEFramework
Image
InterpolatedImageSource.h
Go to the documentation of this file.
1
17
/*
18
* InterpolatedImageSource.h
19
*
20
* Created on: Jun 21, 2019
21
* Author: Alejandro Alvarez Ayllon
22
*/
23
24
#ifndef SEFRAMEWORK_SEFRAMEWORK_IMAGE_INTERPOLATEDIMAGESOURCE_H_
25
#define SEFRAMEWORK_SEFRAMEWORK_IMAGE_INTERPOLATEDIMAGESOURCE_H_
26
27
#include "
SEFramework/Image/ProcessingImageSource.h
"
28
29
namespace
SourceXtractor
{
30
34
template
<
typename
T>
35
class
InterpolatedImageSource
:
public
ProcessingImageSource
<T> {
36
public
:
37
InterpolatedImageSource
(
std::shared_ptr
<
Image<T>
>
image
,
std::shared_ptr<WeightImage>
variance_map
,
38
WeightImage::PixelType
variance_threshold
,
int
interpolation_gap
)
39
:
ProcessingImageSource
<T>(
image
),
40
m_variance_map
(
variance_map
),
m_variance_threshold
(
variance_threshold
),
41
m_interpolation_gap
(
interpolation_gap
) {
42
}
43
44
std::string
getRepr
()
const override
{
45
return
"InterpolatedImageSource("
+
getImageRepr
() +
","
+
m_variance_map
->getRepr() +
")"
;
46
}
47
48
ImageTile::ImageType
getType
()
const override
{
49
return
ImageTile::getTypeValue
(T());
50
}
51
52
protected
:
53
using
ProcessingImageSource
<T>
::getImageRepr
;
54
55
void
generateTile
(
const
std::shared_ptr
<
Image<T>
>&
image
,
ImageTileWithType<T>
&
tile
,
56
int
x
,
int
y
,
int
width,
int
height)
const override
{
57
// Get the chunks we are interested in, and its surrounding area so we can convolve
58
auto
chunk_start_x
=
x
-
m_interpolation_gap
;
59
auto
chunk_end_x
=
x
+ width;
60
auto
chunk_start_y
=
y
-
m_interpolation_gap
;
61
auto
chunk_end_y
=
y
+ height;
62
63
// Remember to clip to avoid accessing the image out of bounds!
64
auto
chunk_pixel_x
=
std::max
(
chunk_start_x
, 0);
65
auto
chunk_pixel_y
=
std::max
(
chunk_start_y
, 0);
66
auto
chunk_w
=
std::min
(
chunk_end_x
-
chunk_pixel_x
,
image
->getWidth() -
chunk_pixel_x
);
67
auto
chunk_h
=
std::min
(
chunk_end_y
-
chunk_pixel_y
,
image
->getHeight() -
chunk_pixel_y
);
68
69
// Get the chunks for the image and the variance
70
// We rely on the underlying chain to generate them efficiently (i.e. BufferedImage across tiles)
71
auto
img_chunk
=
image
->getChunk(
chunk_pixel_x
,
chunk_pixel_y
,
chunk_w
,
chunk_h
);
72
auto
variance_chunk
=
m_variance_map
->getChunk(
chunk_pixel_x
,
chunk_pixel_y
,
chunk_w
,
chunk_h
);
73
74
// Fill the tile interpolating from the chunks
75
int
off_x
=
x
-
chunk_pixel_x
;
76
int
off_y
=
y
-
chunk_pixel_y
;
77
auto
&
tile_data
= *
tile
.getImage();
78
for
(
int
iy
= 0;
iy
< height; ++
iy
) {
79
for
(
int
ix
= 0;
ix
< width; ++
ix
) {
80
tile_data
.at(
ix
,
iy
) =
getInterpolatedValue
(*
img_chunk
, *
variance_chunk
,
ix
+
off_x
,
iy
+
off_y
);
81
}
82
}
83
}
84
85
private
:
86
std::shared_ptr<WeightImage>
m_variance_map
;
87
WeightImage::PixelType
m_variance_threshold
;
88
int
m_interpolation_gap
;
89
90
inline
T
getInterpolatedValue
(
const
ImageChunk<T>
&
img
,
const
ImageChunk<T>
&
var
,
int
x
,
int
y
)
const
{
91
if
(
var
.getValue(
x
,
y
) <
m_variance_threshold
)
92
return
img
.getValue(
x
,
y
);
93
94
for
(
int
i
= 1;
i
<=
m_interpolation_gap
;
i
++) {
95
if
(
x
-
i
>= 0 &&
var
.getValue(
x
-
i
,
y
) <
m_variance_threshold
) {
96
return
img
.getValue(
x
-
i
,
y
);
97
}
98
if
(
y
-
i
>= 0 &&
var
.getValue(
x
,
y
-
i
) <
m_variance_threshold
) {
99
return
img
.getValue(
x
,
y
-
i
);
100
}
101
}
102
return
img
.getValue(
x
,
y
);
103
}
104
};
105
106
}
// end namespace SourceXtractor
107
108
#endif
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
ProcessingImageSource.h
std::string
SourceXtractor::ImageTile::ImageType
ImageType
Definition
ImageTile.h:37
SourceXtractor::ImageTile::getTypeValue
static ImageType getTypeValue(float)
Definition
ImageTile.h:97
SourceXtractor::Image::PixelType
T PixelType
Definition
Image.h:48
SourceXtractor::InterpolatedImageSource
Definition
InterpolatedImageSource.h:35
SourceXtractor::InterpolatedImageSource::getInterpolatedValue
T getInterpolatedValue(const ImageChunk< T > &img, const ImageChunk< T > &var, int x, int y) const
Definition
InterpolatedImageSource.h:90
SourceXtractor::InterpolatedImageSource::m_interpolation_gap
int m_interpolation_gap
Definition
InterpolatedImageSource.h:88
SourceXtractor::InterpolatedImageSource::getRepr
std::string getRepr() const override
Human readable representation of this source.
Definition
InterpolatedImageSource.h:44
SourceXtractor::InterpolatedImageSource::m_variance_threshold
WeightImage::PixelType m_variance_threshold
Definition
InterpolatedImageSource.h:87
SourceXtractor::InterpolatedImageSource::InterpolatedImageSource
InterpolatedImageSource(std::shared_ptr< Image< T > > image, std::shared_ptr< WeightImage > variance_map, WeightImage::PixelType variance_threshold, int interpolation_gap)
Definition
InterpolatedImageSource.h:37
SourceXtractor::InterpolatedImageSource::m_variance_map
std::shared_ptr< WeightImage > m_variance_map
Definition
InterpolatedImageSource.h:86
SourceXtractor::InterpolatedImageSource::generateTile
void generateTile(const std::shared_ptr< Image< T > > &image, ImageTileWithType< T > &tile, int x, int y, int width, int height) const override
Definition
InterpolatedImageSource.h:55
SourceXtractor::InterpolatedImageSource::getType
ImageTile::ImageType getType() const override
Definition
InterpolatedImageSource.h:48
SourceXtractor::ProcessingImageSource
Definition
ProcessingImageSource.h:33
SourceXtractor::ProcessingImageSource::getImageRepr
std::string getImageRepr() const
Definition
ProcessingImageSource.h:70
std::function
std::max
T max(T... args)
std::min
T min(T... args)
SourceXtractor
Definition
Aperture.h:30
std::shared_ptr
Generated by
1.10.0