SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEFramework
SEFramework
Convolution
DirectConvolution.h
Go to the documentation of this file.
1
17
/*
18
* @file SEFramework/Convolution/DirectConvolution.h
19
* @date 17/09/18
20
* @author aalvarez
21
*/
22
23
#ifndef _SEFRAMEWORK_CONVOLUTION_DIRECTCONVOLUTION_H
24
#define _SEFRAMEWORK_CONVOLUTION_DIRECTCONVOLUTION_H
25
26
#include "
SEFramework/Image/MirrorImage.h
"
27
#include "
SEFramework/Image/PaddedImage.h
"
28
#include "
SEFramework/Image/VectorImage.h
"
29
30
namespace
SourceXtractor
{
31
32
template
<
typename
T = SeFloat,
class
TPadding = PaddedImage<T, Reflect101Coordinates>>
33
class
DirectConvolution
{
34
public
:
35
explicit
DirectConvolution
(
std::shared_ptr
<
const
Image<T>
>
img
)
36
:
m_kernel
{
VectorImage
<T>::create(*
MirrorImage
<T>::create(
img
))} {
37
}
38
39
virtual
~DirectConvolution
() =
default
;
40
41
template
<
typename
...Args>
42
void
convolve
(
std::shared_ptr
<
WriteableImage<T>
>
image
,
Args
...
padding_args
)
const
{
43
auto
padded_width
=
image
->getWidth() +
m_kernel
->getWidth() - 1;
44
auto
padded_height
=
image
->getHeight() +
m_kernel
->getHeight() - 1;
45
auto
lpad
=
m_kernel
->getWidth() / 2;
46
auto
tpad
=
m_kernel
->getHeight() / 2;
47
48
auto
padded
=
VectorImage<T>::create
(
49
TPadding::create(
image
,
padded_width
,
padded_height
,
std::forward<Args>
(
padding_args
)...)
50
);
51
52
for
(
int
iy
=
tpad
;
iy
<
padded
->getHeight() -
tpad
; ++
iy
) {
53
for
(
int
ix
=
lpad
;
ix
<
padded
->getWidth() -
lpad
; ++
ix
) {
54
T
acc
= 0;
55
for
(
int
ky
= 0;
ky
<
m_kernel
->getHeight(); ++
ky
) {
56
for
(
int
kx
= 0;
kx
<
m_kernel
->getWidth(); ++
kx
) {
57
acc
+=
m_kernel
->getValue(
kx
,
ky
) *
padded
->getValue(
ix
-
lpad
+
kx
,
iy
-
tpad
+
ky
);
58
}
59
}
60
image
->setValue(
ix
-
lpad
,
iy
-
tpad
,
acc
);
61
}
62
}
63
}
64
65
std::size_t
getWidth
()
const
{
66
return
m_kernel
->getWidth();
67
}
68
69
std::size_t
getHeight
()
const
{
70
return
m_kernel
->getHeight();
71
}
72
73
std::shared_ptr<const Image<T>
>
getKernel
()
const
{
74
return
m_kernel
;
75
}
76
77
private
:
78
std::shared_ptr<const VectorImage<T>
>
m_kernel
;
79
};
80
81
}
// end SourceXtractor
82
83
#endif
// _SEFRAMEWORK_CONVOLUTION_DIRECTCONVOLUTION_H
MirrorImage.h
PaddedImage.h
VectorImage.h
SourceXtractor::DirectConvolution
Definition
DirectConvolution.h:33
SourceXtractor::DirectConvolution::getKernel
std::shared_ptr< const Image< T > > getKernel() const
Definition
DirectConvolution.h:73
SourceXtractor::DirectConvolution::DirectConvolution
DirectConvolution(std::shared_ptr< const Image< T > > img)
Definition
DirectConvolution.h:35
SourceXtractor::DirectConvolution::m_kernel
std::shared_ptr< const VectorImage< T > > m_kernel
Definition
DirectConvolution.h:78
SourceXtractor::DirectConvolution::convolve
void convolve(std::shared_ptr< WriteableImage< T > > image, Args... padding_args) const
Definition
DirectConvolution.h:42
SourceXtractor::DirectConvolution::getHeight
std::size_t getHeight() const
Definition
DirectConvolution.h:69
SourceXtractor::DirectConvolution::getWidth
std::size_t getWidth() const
Definition
DirectConvolution.h:65
SourceXtractor::DirectConvolution::~DirectConvolution
virtual ~DirectConvolution()=default
SourceXtractor::MirrorImage
Mirrors an image in both X and Y axes.
Definition
MirrorImage.h:37
SourceXtractor::VectorImage
Image implementation which keeps the pixel values in memory.
Definition
VectorImage.h:52
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition
VectorImage.h:100
std::function
SourceXtractor
Definition
Aperture.h:30
std::shared_ptr
std::size_t
Generated by
1.10.0