来源:https://blog.csdn.net/hustrains/article/details/9153553
参数type制定算子类型,parameters指定相应的参数,具体格式为:
type='average',为均值滤波,参数为n,代表模版尺寸,用向量表示,默认值为[3,3]。
type= 'gaussian',为高斯低通滤波器,参数有两个,n表示模版尺寸,默认值为[3,3],sigma表示滤波器的标准差,单位为像素,默认值为
'average' filter type, the default filter size is [3 3]. When used with the Laplacian of Gaussian ('log') filter type, the default filter size is [5 5].type= 'laplacian',为拉普拉斯算子,参数为alpha,用于控制拉普拉斯算子的形状,取值范围为[0,1],默认值为0.2。
type= 'log',为拉普拉斯高斯算子,参数有两个,n表示模版尺寸,默认值为[3,3],sigma为滤波器的标准差,单位为像素,默认值为0.5
type= 'prewitt',为prewitt算子,用于边缘增强,无参数。
type= 'sobel',为著名的sobel算子,用于边缘提取,无参数。
type= 'unsharp',为对比度增强滤波器,参数alpha用于控制滤波器的形状,范围为[0,1],默认值为0.2。
————————————————
Syntax
Description
imfilter.
hsize.
2*radius+1.
imgaussfilt3 instead.
alpha controls the shape of the Laplacian.
sigma.
0, which corresponds to a horizontal motion of nine pixels.
h'.
[ 1 1 1 0 0 0 -1 -1 -1 ]
h'.
[ 1 2 1 0 0 0 -1 -2 -1 ]
Examples
Create Various Filters and Filter an Image
Read image and display it.
I = imread('cameraman.tif');
imshow(I);
Create a motion filter and use it to blur the image. Display the blurred image.
H = fspecial('motion',20,45);
MotionBlur = imfilter(I,H,'replicate');
imshow(MotionBlur);
Create a disk filter and use it to blur the image. Display the blurred image.
H = fspecial('disk',10);
blurred = imfilter(I,H,'replicate');
imshow(blurred);
Input Arguments
Output Arguments
Algorithms
Averaging filters:
ones(n(1),n(2))/(n(1)*n(2))
Gaussian filters:
hg(n1,n2)=e−(n21+n22)2σ2
h(n1,n2)=hg(n1,n2)n1n2hg
Laplacian filters:
∇2=∂2∂x2+∂2∂y2
∇2=4(α+1)α41−α4α41−α4−11−α4α41−α4α4
Laplacian of Gaussian (LoG) filters:
hg(n1,n2)=e−(n21+n22)2σ2
h(n1,n2)=(n21+n22−2σ2)hg(n1,n2)σ4n1n2hg
Note that fspecial shifts the equation to ensure that the sum of all elements of the kernel is zero (similar to the Laplace kernel) so that the convolution result of homogeneous regions is always zero.
Motion filters:
-
Construct an ideal line segment with the length and angle specified by the arguments
lenandtheta, centered at the center coefficient ofh. -
For each coefficient location
(i,j), compute the nearest distance between that location and the ideal line segment. -
h = max(1 - nearest_distance, 0); -
Normalize
h:h = h/(sum(h(:)))
Extended Capabilities
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
-
fspecialsupports the generation of C code (requires MATLAB® Coder™). For more information, see Code Generation for Image Processing. -
When generating code, all inputs must be constants at compilation time.
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
-
When generating code, all inputs must be constants at compilation time.