SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Segmentation
BgDFTConvolutionImageSource.cpp
Go to the documentation of this file.
1
17
/*
18
* BgDFTConvolutionImageSource.h
19
*
20
* Created on: Jun 12, 2019
21
* Author: Alejandro Alvarez
22
* Refactored out from: BackgroundConvolution.h
23
*/
24
25
#include "
SEImplementation/Segmentation/BgDFTConvolutionImageSource.h
"
26
#include "
SEFramework/Image/ImageAccessor.h
"
27
#include "
SEFramework/Image/FunctionalImage.h
"
28
#include "
SEFramework/Image/SubImage.h
"
29
#include "
SEFramework/Image/MaskedImage.h
"
30
31
namespace
SourceXtractor
{
32
33
34
BgDFTConvolutionImageSource::BgDFTConvolutionImageSource
(
std::shared_ptr
<
Image<DetectionImage::PixelType>
>
image
,
35
std::shared_ptr<DetectionImage>
variance
,
SeFloat
threshold
,
36
std::shared_ptr
<
VectorImage<SeFloat>
>
kernel
)
37
:
ProcessingImageSource
<
DetectionImage
::PixelType>(
image
),
38
m_variance(
variance
), m_threshold(
threshold
), m_convolution(
kernel
) {
39
}
40
41
std::string
BgDFTConvolutionImageSource::getRepr
()
const
{
42
return
"BgDFTConvolutionImageSource("
+
getImageRepr
() +
")"
;
43
}
44
45
void
BgDFTConvolutionImageSource::generateTile
(
const
std::shared_ptr
<
Image<DetectionImage::PixelType>
>&
image
,
46
ImageTileWithType<DetectionImage::PixelType>
&
tile
,
int
start_x
,
47
int
start_y
,
int
width,
int
height)
const
{
48
int
hx
=
m_convolution
.
getWidth
() / 2;
49
int
hy
=
m_convolution
.
getHeight
() / 2;
50
int
clip_x
=
std::max
(
start_x
-
hx
, 0);
51
int
clip_y
=
std::max
(
start_y
-
hy
, 0);
52
int
clip_w
=
std::min
(width +
hx
* 2,
image
->getWidth() -
clip_x
);
53
int
clip_h
=
std::min
(height +
hy
* 2,
image
->getHeight() -
clip_y
);
54
55
using
VarianceAccessor
=
ImageAccessor<WeightImage::PixelType>
;
56
57
// Clip the image and variance map to the given size, accounting for the margins for the convolution
58
auto
clipped_img
=
SubImage<DetectionImage::PixelType>::create
(
59
image
,
clip_x
,
clip_y
,
clip_w
,
clip_h
60
);
61
auto
clipped_variance
=
SubImage<WeightImage::PixelType>::create
(
62
m_variance
,
clip_x
,
clip_y
,
clip_w
,
clip_h
63
);
64
65
// Get the mask
66
// For instance, with a threshold of 0.5
67
// Variance Mask Negative
68
// 1 1 1 0 0 0 1 1 1
69
// 1 0 1 0 1 0 1 0 1
70
// 1 1 1 0 0 0 1 1 1
71
auto
mask =
FunctionalImage<WeightImage::PixelType>::create
(
72
clipped_variance
, [
this
](
int
,
int
,
WeightImage::PixelType
v
) {
73
return
v
<
m_threshold
;
74
}
75
);
76
VarianceAccessor
maskAccessor
(mask);
77
78
// Get the image masking out values where the variance is greater than the threshold
79
auto
masked_img
=
MaskedImage<DetectionImage::PixelType, DetectionImage::PixelType, std::equal_to>::create
(
80
clipped_img
, mask, 0., 0.);
81
82
// Convolve the masked image, padding with 0
83
auto
conv_masked
=
VectorImage<DetectionImage::PixelType>::create
(
masked_img
);
84
m_convolution
.
convolve
(
conv_masked
);
85
86
// Convolve the mask
87
// This gives us in each cell the sum of the kernel values that have been used,
88
// so we can divide the previous convolution.
89
auto
conv_mask
=
VectorImage<DetectionImage::PixelType>::create
(mask);
90
m_convolution
.
convolve
(
conv_mask
);
91
92
// Copy out the value of the convolved image, divided by the negative mask, applying
93
// again the mask to the convolved result
94
int
off_x
=
start_x
-
clip_x
;
95
int
off_y
=
start_y
-
clip_y
;
96
for
(
int
y
= 0;
y
< height; ++
y
) {
97
for
(
int
x
= 0;
x
< width; ++
x
) {
98
if
(
maskAccessor
.getValue(
x
+
off_x
,
y
+
off_y
)) {
99
tile
.setValue(
100
x
+
start_x
,
y
+
start_y
,
101
conv_masked
->getValue(
x
+
off_x
,
y
+
off_y
) /
conv_mask
->getValue(
x
+
off_x
,
y
+
off_y
)
102
);
103
}
else
{
104
tile
.setValue(
x
+
start_x
,
y
+
start_y
, 0);
105
}
106
}
107
}
108
}
109
110
}
// end namespace SourceXtractor
111
BgDFTConvolutionImageSource.h
FunctionalImage.h
ImageAccessor.h
MaskedImage.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
SubImage.h
std::string
SourceXtractor::BgDFTConvolutionImageSource::getRepr
std::string getRepr() const override
Human readable representation of this source.
Definition
BgDFTConvolutionImageSource.cpp:41
SourceXtractor::BgDFTConvolutionImageSource::m_threshold
DetectionImage::PixelType m_threshold
Definition
BgDFTConvolutionImageSource.h:60
SourceXtractor::BgDFTConvolutionImageSource::m_variance
std::shared_ptr< DetectionImage > m_variance
Definition
BgDFTConvolutionImageSource.h:59
SourceXtractor::BgDFTConvolutionImageSource::generateTile
void generateTile(const std::shared_ptr< Image< DetectionImage::PixelType > > &image, ImageTileWithType< DetectionImage::PixelType > &tile, int start_x, int start_y, int width, int height) const override
Definition
BgDFTConvolutionImageSource.cpp:45
SourceXtractor::BgDFTConvolutionImageSource::m_convolution
ConvolutionType m_convolution
Definition
BgDFTConvolutionImageSource.h:61
SourceXtractor::BgDFTConvolutionImageSource::BgDFTConvolutionImageSource
BgDFTConvolutionImageSource(std::shared_ptr< Image< DetectionImage::PixelType > > image, std::shared_ptr< DetectionImage > variance, SeFloat threshold, std::shared_ptr< VectorImage< SeFloat > > kernel)
Definition
BgDFTConvolutionImageSource.cpp:34
SourceXtractor::DFTConvolution::getHeight
std::size_t getHeight() const
Definition
DFT.h:94
SourceXtractor::DFTConvolution::getWidth
std::size_t getWidth() const
Definition
DFT.h:86
SourceXtractor::DFTConvolution::convolve
void convolve(std::shared_ptr< WriteableImage< T > > image_ptr, std::unique_ptr< ConvolutionContext > &context, Args... padding_args) const
Definition
DFT.h:152
SourceXtractor::FunctionalImage::create
static std::shared_ptr< FunctionalImage< T, I > > create(Args &&... args)
Definition
FunctionalImage.h:56
SourceXtractor::Image< SeFloat >
SourceXtractor::MaskedImage::create
static std::shared_ptr< MaskedImage< T, M, Operator > > create(const std::shared_ptr< Image< T > > &image, const std::shared_ptr< Image< M > > &mask, T replacement, M mask_flag=0x01)
Definition
MaskedImage.h:78
SourceXtractor::ProcessingImageSource
Definition
ProcessingImageSource.h:33
SourceXtractor::ProcessingImageSource< DetectionImage::PixelType >::getImageRepr
std::string getImageRepr() const
Definition
ProcessingImageSource.h:70
SourceXtractor::SubImage::create
static std::shared_ptr< SubImage< T > > create(Args &&... args)
Definition
SubImage.h:55
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition
VectorImage.h:100
std::function
std::max
T max(T... args)
std::min
T min(T... args)
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition
Types.h:32
std::shared_ptr
Generated by
1.10.0