Halide: image shifts to top-left after convolution using a large patch

Solution for Halide: image shifts to top-left after convolution using a large patch
is Given Below:

I encounter a strange issue during convolution using Halide. Below is the code

Func Deblur::filter2D(Func ima, Func ker, RDom r) {

    Func blur{"blur1"};
    blur(x, y, c) += ker(r.x, r.y) * ima(x + r.x - 1, y + r.y - 1, c);
    
    return blur;
}

When the RDom r(kernel) (kernel patch size) is getting larger and larger, the result will appear to move more and more to top-left. I am using repeat-edge boundary condition. What might be the cause of this issue? This is confusing.

Solved it. The updated code is:

Func Deblur::filter2D(Func ima, Func ker, RDom r, Expr w, Expr h) {
    Func blur{"blur1"};
    blur(x, y, c) += ker(r.x, r.y) * ima(x + r.x - w / 2, y + r.y - h / 2, c);

    return blur;
}

where w and h is the width and height of the kernel. The original RDom does not have offset and starts from index 0. It is like summing from x to x+w, which is wrong. Now it is from x-w/2 to x+w/2.