MATLAB: Reducing intensity in an image using a function

filteringimage processingImage Processing Toolbox

So I'm trying to use mean filtering to process an image. The idea of mean filtering is simply to replace each pixel value in an image with the mean (average) value of its neighbors, including itself.
Related Question