It computes 2-d averging filtering operation on a gray scale image.
y = avgfilt2(x)
y = avgfilt2(x,sz)
y = avgfilt2(x,sz,opt)
A matrix representing a gray scale image.
A two element vector representing the kernel size of the averaging filter to be applied.
A character constant representing the padding option used for average filtering of boundary pixels.
A matrix representing the average filtered gray scale image of the given input image.
It performs 2-d average filtering on a given gray scale image. It takes one, two or three parameters. If only a gray scale image is given as input, then the second parameter kernel size is taken as [3 3] and the third parameter padding option is taken as zero padding. If the third parameter opt is not explicity given, it is taken as 'z' for zero padding. The possible values of the third parameter opt are 'z' for zero padding(default), 'p' for periodic padding 'o' for padding with ones 'm' for padding with median value '-' for padding with minimum value '+' for padding with maximum values. It may be noted that average filtering with periodic padding gives smoother boundary in the resulting filtered image.
x=imread('lena.png'); x=rgb2gray(x); // Average filtering with kernel size (3x3) y=avgfilt2(x); imshow(uint8(y)) // Average filtering with kernel size (5x5) y1=avgfilt2(x,[5 5]); imshow(uint8(y1)) //Average filtering with kernel size (5x5) //and perioding padding y2=avgfilt2(x,[5 5],'p'); imshow(uint8(y2)) | ![]() | ![]() |