SourceXtractorPlusPlus  0.10
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BgConvolutionImageSource.cpp
Go to the documentation of this file.
1 
17 /*
18  * BgConvolutionImageSource.cpp
19  *
20  * Created on: Jun 12, 2019
21  * Author: Alejandro Alvarez
22  * Refactored out from: BackgroundConvolution.h
23  */
24 
27 
28 namespace SourceXtractor {
29 
30 
32  std::shared_ptr<DetectionImage> variance, SeFloat threshold,
34  : ProcessingImageSource<DetectionImage::PixelType>(image),
35  m_variance(variance), m_threshold(threshold) {
37 }
38 
40  return "BgConvolutionImageSource(" + getImageRepr() + ")";
41 }
42 
45  int start_x, int start_y, int width, int height) const {
46  const int hx = m_kernel->getWidth() / 2;
47  const int hy = m_kernel->getHeight() / 2;
48  const int clip_x = std::max(start_x - hx, 0);
49  const int clip_y = std::max(start_y - hy, 0);
50  const int clip_w = std::min(width + hx * 2, image->getWidth() - clip_x);
51  const int clip_h = std::min(height + hy * 2, image->getHeight() - clip_y);
52 
53  // "Materialize" the image and variance
54  auto image_chunk = image->getChunk(clip_x, clip_y, clip_w, clip_h);
55  auto variance_chunk = m_variance->getChunk(clip_x, clip_y, clip_w, clip_h);
56 
57  // Convolve both and copy out to the tile
58  const int off_x = start_x - clip_x;
59  const int off_y = start_y - clip_y;
60 
61  for (int iy = 0; iy < height; ++iy) {
62  for (int ix = 0; ix < width; ++ix) {
63  DetectionImage::PixelType total = 0.;
64  DetectionImage::PixelType conv_weight = 0.;
65 
66  if (variance_chunk->getValue(ix + off_x, iy + off_y) < m_threshold) {
67  for (int cy = 0; cy < m_kernel->getHeight(); ++cy) {
68  for (int cx = 0; cx < m_kernel->getWidth(); ++cx) {
69  int x2 = ix + cx - hx;
70  int y2 = iy + cy - hy;
71  int clip_x2 = x2 + off_x;
72  int clip_y2 = y2 + off_y;
73 
74  if (clip_x2 >= 0 && clip_x2 < clip_w && clip_y2 >= 0 && clip_y2 < clip_h) {
75  if (variance_chunk->getValue(clip_x2, clip_y2) < m_threshold) {
76  total += image_chunk->getValue(clip_x2, clip_y2) * m_kernel->getValue(cx, cy);
77  conv_weight += m_kernel->getValue(cx,cy);
78  }
79  }
80  }
81  }
82  // Note that because of the conditional, at least the center pixel is below the threshold,
83  // so checking for conv_weight > 0 is redundant
84  tile.getImage()->setValue(ix, iy, total / conv_weight);
85  }
86  else {
87  tile.getImage()->setValue(ix, iy, 0.);
88  }
89  }
90  }
91 }
92 
93 
94 } // end namespace SourceXtractor
95 
Mirrors an image in both X and Y axes.
Definition: MirrorImage.h:35
BgConvolutionImageSource(std::shared_ptr< Image< DetectionImage::PixelType >> image, std::shared_ptr< DetectionImage > variance, SeFloat threshold, std::shared_ptr< VectorImage< SeFloat >> kernel)
std::shared_ptr< VectorImage< T > > getImage()
Definition: ImageTile.h:87
SeFloat32 SeFloat
Definition: Types.h:32
static std::shared_ptr< VectorImage< T > > create(Args &&...args)
Definition: VectorImage.h:89
STL class.
T min(T...args)
std::string getRepr() const override
Human readable representation of this source.
std::shared_ptr< VectorImage< SeFloat > > m_kernel
Image implementation which keeps the pixel values in memory.
Definition: VectorImage.h:53
T max(T...args)
void generateTile(std::shared_ptr< Image< DetectionImage::PixelType >> image, ImageTile< DetectionImage::PixelType > &tile, int start_x, int start_y, int width, int height) const override
Interface representing an image.
Definition: Image.h:43
std::shared_ptr< DetectionImage > m_variance