Local processing through masks
To apply a local processing through a mask:
g = imfilter(f, w, filter_mode, border_options, size_options)
f is the original image,
w is the mask,
g is the resulting image,
filter_mode is "corr" for correlation and "conv" for the case of convolution,
size_options which has two size options "full" and "same", and
border_options has several options:
P: The image's borders extend with pixels of value P. By default, P is zero.
'replicate': The image's borders extend with pixels that replicate the value of the pixels that are borders.
'symmetric': The image's borders are extended making a mirror effect with the image.
'circular': The image is extended interpreting the image as the period of a periodic 2D function.
You can crate "standard" filters using MATLAB's Toolbox:
w = fspecial('type', parameters)
type specifies the type of filter, and
parameters specifies the details of said filter.
'average': It's defined like this:
fspecial('average', [r c])
[r c]is the filter size. By default it's 3x3. If instead of
[r c]we use a number, we'll have a squared matrix.
'disk': Gives a bigger weight to the central pixel:
same as before for
fspecial('disk', [r c])
[r c]applies here.
'gaussian': Low-pass Gaussian filter:
same as before for
fspecial('gaussian', [r c], sig)
[r c]applies here, and
sigrepresents the (positive) standard deviation.
filter of size 3x3, whose shape is specified by
alpha, a number in between 0 to 1. The default value is 0.5.
'log': Laplacian filter of a Gaussian:
fspecial('log', [r c], sig)
when this filter is applied to an image, it creates a feeling of movement (of the camera with respect to the image) of
fspecial('motion', len, theta)
lenpixels. The direction of the translation is given by
By default, it creates vertical gradients. For horizontal gradients, the matrix must be inverted (
wh = wv).
Creates a 3x3 unsharp filter, where
alphacontrols the shape, and it must be greater than 0 and lower or equal to 1. The default value is 0.2.
Non-linear filter (median filter)
g = medfilt2(f, [m n], border_options)
g is the resulting filtered image,
f is the image to filter,
[m n] is the size of the mask ([3 3] by default), and there are two border options:
'zeros', which is the default and
You can practice these concepts using