28 namespace SourceXtractor {
35 m_variance(variance), m_threshold(threshold) {
40 return "BgConvolutionImageSource(" +
getImageRepr() +
")";
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);
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);
58 const int off_x = start_x - clip_x;
59 const int off_y = start_y - clip_y;
61 for (
int iy = 0; iy <
height; ++iy) {
62 for (
int ix = 0; ix <
width; ++ix) {
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;
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);
84 tile.
getImage()->setValue(ix, iy, total / conv_weight);
87 tile.
getImage()->setValue(ix, iy, 0.);