I put a fix for the case when the input disparity is invalid in the entire region to fit.
This code is still not robust enough in funny situations. I would argue that a better approach would be to simply blur the input disparity, but then one must be careful that one invalid pixel in the disparity not invalidate the entire convolution, so one would need to blur by doing a weighted average of the valid pixels only.
I put a fix for the case when the input disparity is invalid in the entire region to fit.
This code is still not robust enough in funny situations. I would argue that a better approach would be to simply blur the input disparity, but then one must be careful that one invalid pixel in the disparity not invalidate the entire convolution, so one would need to blur by doing a weighted average of the valid pixels only.