SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
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
28namespace SourceXtractor {
29
30
38
40 return "BgConvolutionImageSource(" + getImageRepr() + ")";
41}
42
45 int start_x, int start_y, int clip_w, int clip_h, SeFloat threshold) {
48
49 for (int cy = 0; cy < kernel.getHeight(); ++cy) {
50 for (int cx = 0; cx < kernel.getWidth(); ++cx) {
51 int clip_x2 = start_x + cx;
52 int clip_y2 = start_y + cy;
53
55 if (variance_chunk.getValue(clip_x2, clip_y2) < threshold) {
56 total += image_chunk.getValue(clip_x2, clip_y2) * kernel.getValue(cx, cy);
57 conv_weight += kernel.getValue(cx, cy);
58 }
59 }
60 }
61 }
62
63 return std::make_pair(total, conv_weight);
64}
65
68 int start_y, int width, int height) const {
69 const int hx = m_kernel->getWidth() / 2;
70 const int hy = m_kernel->getHeight() / 2;
71 const int clip_x = std::max(start_x - hx, 0);
72 const int clip_y = std::max(start_y - hy, 0);
73 const int clip_w = std::min(width + hx * 2, image->getWidth() - clip_x);
74 const int clip_h = std::min(height + hy * 2, image->getHeight() - clip_y);
75
76 // "Materialize" the image and variance
77 auto image_chunk = image->getChunk(clip_x, clip_y, clip_w, clip_h);
79
80 // Convolve both and copy out to the tile
81 const int off_x = start_x - clip_x;
82 const int off_y = start_y - clip_y;
83 auto& tile_image = *tile.getImage();
84 for (int iy = 0; iy < height; ++iy) {
85 for (int ix = 0; ix < width; ++ix) {
86 if (variance_chunk->getValue(ix + off_x, iy + off_y) < m_threshold) {
89
91 ix - hx + off_x, iy - hy + off_y, clip_w, clip_h,
93
94 // Note that because of the conditional, at least the center pixel is below the threshold,
95 // so checking for conv_weight > 0 is redundant
96 tile_image.setValue(ix, iy, total / conv_weight);
97 }
98 else {
99 tile_image.setValue(ix, iy, 0.);
100 }
101 }
102 }
103}
104
105
106} // end namespace SourceXtractor
107
std::string getRepr() const override
Human readable representation of this source.
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
std::shared_ptr< DetectionImage > m_variance
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< SeFloat > > m_kernel
Mirrors an image in both X and Y axes.
Definition MirrorImage.h:37
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
T make_pair(T... args)
T max(T... args)
T min(T... args)
SeFloat32 SeFloat
Definition Types.h:32
static std::tuple< float, float > applyKernel(const VectorImage< SeFloat > &kernel, ImageChunk< SeFloat > &image_chunk, ImageChunk< SeFloat > &variance_chunk, int start_x, int start_y, int clip_w, int clip_h, SeFloat threshold)
T tie(T... args)