# Local processing through masks

To apply a local processing through a mask:

g = imfilter(f, w, filter_mode, border_options, size_options)

where 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.

## Filter creation

You can crate "standard" filters using MATLAB's Toolbox:

w = fspecial('type', parameters)

where type specifies the type of filter, and parameters specifies the details of said filter.

Options for type:

• 'average': It's defined like this:
fspecial('average', [r c])
where [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:
fspecial('disk', [r c])
same as before for [r c] applies here.
• 'gaussian': Low-pass Gaussian filter:
fspecial('gaussian', [r c], sig)
same as before for [r c] applies here, and sig represents the (positive) standard deviation.
• 'laplacian':
fspecial('laplacian', alpha)
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)
• 'motion':
fspecial('motion', len, theta)
when this filter is applied to an image, it creates a feeling of movement (of the camera with respect to the image) of len pixels. The direction of the translation is given by theta.
• 'prewitt':
fspecial('prewitt')
By default, it creates vertical gradients. For horizontal gradients, the matrix must be inverted (wh = wv).
• 'unsharp':
fspecial('unsharp', alpha)
Creates a 3x3 unsharp filter, where alpha controls the shape, and it must be greater than 0 and lower or equal to 1. The default value is 0.2.

Laplacian filter

## Non-linear filter (median filter)

g = medfilt2(f, [m n], border_options)

where 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 'symmetric'.

You can practice these concepts using snippet03.