Note that
conv2(double(im(:,:,q)),mask,'same')./sz^2
is the same as
conv2(double(im(:,:,q)),mask./sz^2,'same')
This is because the convolution and the multiplication commute.
Thus, the convolution operation computes a local mean. Without the division, it would be a local sum.
0
solved Why is the output of `conv2()` is divided by `sz^2`?