SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
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
29
30namespace SourceXtractor {
31
32template <typename T = SeFloat, class TPadding = PaddedImage<T, Reflect101Coordinates>>
34public:
36 : m_kernel{VectorImage<T>::create(*MirrorImage<T>::create(img))} {
37 }
38
39 virtual ~DirectConvolution() = default;
40
41 template <typename ...Args>
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
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
66 return m_kernel->getWidth();
67 }
68
70 return m_kernel->getHeight();
71 }
72
76
77private:
79};
80
81} // end SourceXtractor
82
83#endif // _SEFRAMEWORK_CONVOLUTION_DIRECTCONVOLUTION_H
std::shared_ptr< const Image< T > > getKernel() const
DirectConvolution(std::shared_ptr< const Image< T > > img)
std::shared_ptr< const VectorImage< T > > m_kernel
void convolve(std::shared_ptr< WriteableImage< T > > image, Args... padding_args) const
virtual ~DirectConvolution()=default
Mirrors an image in both X and Y axes.
Definition MirrorImage.h:37
Image implementation which keeps the pixel values in memory.
Definition VectorImage.h:52
static std::shared_ptr< VectorImage< T > > create(Args &&... args)