SourceXtractorPlusPlus  0.11
Please provide a description of the project.
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 
30 namespace SourceXtractor {
31 
32 template <typename T = SeFloat, class TPadding = PaddedImage<T, Reflect101Coordinates>>
34 public:
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 
66  return m_kernel->getWidth();
67  }
68 
70  return m_kernel->getHeight();
71  }
72 
74  return m_kernel;
75  }
76 
77 private:
79 };
80 
81 } // end SourceXtractor
82 
83 #endif // _SEFRAMEWORK_CONVOLUTION_DIRECTCONVOLUTION_H
std::shared_ptr
STL class.
SourceXtractor::DirectConvolution::DirectConvolution
DirectConvolution(std::shared_ptr< const Image< T >> img)
Definition: DirectConvolution.h:35
SourceXtractor::MirrorImage::create
static std::shared_ptr< MirrorImage< T > > create(Args &&... args)
Definition: MirrorImage.h:42
SourceXtractor::Image
Interface representing an image.
Definition: Image.h:43
VectorImage.h
SourceXtractor::DirectConvolution::getKernel
std::shared_ptr< const Image< T > > getKernel() const
Definition: DirectConvolution.h:73
SourceXtractor::DirectConvolution::convolve
void convolve(std::shared_ptr< WriteableImage< T >> image, Args... padding_args) const
Definition: DirectConvolution.h:42
SourceXtractor
Definition: Aperture.h:30
MirrorImage.h
SourceXtractor::WriteableImage
Definition: WriteableImage.h:32
SourceXtractor::DirectConvolution
Definition: DirectConvolution.h:33
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:89
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
PaddedImage.h
std::size_t
SourceXtractor::DirectConvolution::m_kernel
std::shared_ptr< const Image< T > > m_kernel
Definition: DirectConvolution.h:78