https://github.com/opencv/opencv/blob/1b443219ed181124978ed8627fb2da8db42765ab/modules/imgproc/src/demosaicing.cpp#L1587 The code `D[2] = (S[-sstep-1] + S[-sstep+1] + S[sstep-1] + S[sstep+1]) >> 2;` should be modifed to `D[2] = (S[-sstep-1] + S[-sstep+1] + S[sstep-1] + S[sstep+1] + 2) >> 2;`