I have a MxN image matrix in, and need to get out matrix out size MxN as follows:
Each point out[i,j] is the average of all in[i,j] inside a window size WxW (if boundary allows). For example if W=10
out[10,10] is average of in[5:15,5:15]
out[1,1] is average of in[1:5,1:5]
This can be implemented as a correlation with ones(1:W,1:W)/W^2, but at the boundary the result is not correct. How should I apply the convolution? I tried pad zeros, reflect but it's not correct yet
out[1,1]will add $36$ image values and $121-36=85$ zeroes from the padding, and then divide by $121 (or $100$ if you prefer) so that the average is not quite what you want. There will also be edge effects in addition to corner effects. So, you could program in the correct divisors for the edges and corners (actually whole borders) and go that way. – Dilip Sarwate Feb 21 at 22:04