Here, `r_st` and `r_end` are indices into the _padded_ image, so are `m` and `n` as well. So, you cannot call `PyArray_GETPTR4` on the _original_ image with those indices. Either you would have to make `r_st` (and so on) indices into the original image, or to use `m - %(pd0)s` and `n - %(pd1)s`. 