SIVP Toolbox
Last update : June, 2006
fspecial - Create some 2D special filters
Calling Sequence
- F = fspecial(type)
- F = fspecial(type, op1)
- F = fspecial(type, op1, op2)
Parameters
-
type:
Filter type. It can be one of these string: 'sobel', 'prewitt', 'gaussion', 'laplacian', 'log', 'average', 'unsharp'. ('motion', 'disk' in future.)
-
op1:
The first parameter for the filter. Some type of filters do not need it.
-
op2:
The second parameter for the filter. Some type of filters do not need it.
-
F:
The returned filter, which is of type double.
Description
fspecial create some 2D special filters. If no parameters are given, fspecial will uses default values.
The supported filters and the syntax for each filter type are listed in the following list:
- F=fspecial('sobel')
-
returns a 3x3 horizontal edges sobel filter. If you want avertical edges sobel filter, you can use transposition of F. F is [ 1 2 1; 0 0 0; -1 -2 -1].
- F=fspecial('prewitt')
-
returns a 3x3 horizontal edges prewitt filter. If you want avertical edges prewitt filter, you can use transposition of F. F is [ 1 1 1; 0 0 0; -1 -1 -1].
- F=fspecial('gaussian', hsize, sigma)
-
returns a Gaussian lowpass filter.
The size of returned filter is determined by parameter hsize.
hsize can be a 1x2 vector which indicate the rows and columns of F.
If hsize is a scalar, F is a square matrix.
The default value for hsize is [3, 3]; the default value for sigma is 0.5.
- F=fspecial('laplacian',alpha)
-
returns a 3-by-3 Laplacian filter.
The returned filter is [alpha, 1-alpha, alpha; 1-alpha, -4, 1-alpha; alpha, 1-alpha, alpha]/(alpha+1).
The default value for alpha is 0.2.
- F=fspecial('log',hsize,sigma)
-
returns a Laplacian of Gaussian filter.
The size of returned filter is determined by parameter hsize.
hsize can be a 1x2 vector which indicate the rows and columns of F.
If hsize is a scalar, F is a square matrix.
The default value for hsize is [5, 5]; the default value for sigma is 0.5.
- F=fspecial('average',hsize)
-
returns an averaging filter.
The size of returned filter is determined by parameter hsize.
hsize can be a 1x2 vector which indicate the rows and columns of F.
If hsize is a scalar, F is a square matrix.
The default value for hsize is [3, 3].
- F=fspecial('unsharp',alpha)
-
returns a 3x3 unsharp contrast enhancement filter.
alpha must be in the range [0.0, 1.0]. The default value of alpha is 0.2.
Examples
im = imread('lena.png');
filter = fspecial('sobel');
imf = imfilter(im, filter);
imshow(imf);
Authors
-
Shiqi Yu <shiqi.yu[at]gmail.com>
Availability
The latest version of SIVP can be found at
http://sivp.sourceforge.net
See Also
imfilter, filter2,