MATLAB: How does fspecial average filter deal with overlap causes by edges of an image

averageedgefilterfspecialimageImage Processing Toolbox

I am applying an average filter using the fspecial command. I am wondering how the average filter works on images whose dimensions are not multiples of the user-specified hsize. For example if a 3×3 filter is chosen and applied to a 10×10 pixel image, how does this filter deal with the last row and column?

Best Answer

The filter is always centered on the pixel to be processed. At the boundary, missing values are by default replaced by zero.
imfilter(ones(10), ones(3))
Other boundary conditions can be found at the help of imfilter, e.g., 'replicate', which takes the missing values from the nearest border pixel:
imfilter(ones(10), ones(3), 'replicate')