This example shows how to filter an image with
a 5-by-5 filter containing equal weights (often called an averaging
MATLAB® has several two-dimensional and multidimensional
filtering functions. The function
conv2 performs two-dimensional
convn performs multidimensional
convolution. Each of these filtering functions always converts the
double, and the output is always
These other filtering functions always assume the input is zero padded,
and they do not support other padding options.
In contrast, the
imfilter function does not
convert input images to
also offers a flexible set of boundary padding options.
I = imread('coins.png');
h = ones(5,5) / 25;
Apply filter to image using
I2 = imfilter(I,h);
Display original image and filtered image for comparison.
imshow(I), title('Original Image'); figure, imshow(I2), title('Filtered Image')