来源:https://blog.csdn.net/hustrains/article/details/9153553

Fspecial函数用于创建预定义的滤波算子,会与imfilter搭配使用,其语法格式为:
h = fspecial(type)h = fspecial(type,parameters,sigma)

参数type制定算子类型,parameters指定相应的参数,具体格式为:
type='average',为均值滤波,参数为n,代表模版尺寸,用向量表示,默认值为[3,3]。
type= 'gaussian',为高斯低通滤波器,参数有两个,n表示模版尺寸,默认值为[3,3],sigma表示滤波器的标准差,单位为像素,默认值为
0.5。
When used with the '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。
例子:
>> G=fspecial('gaussian',5)%参数为5,表示产生5*5的gaussian矩阵,如果没有,默认为3*3的矩阵。
G =     0.0000    0.0000    0.0002    0.0000    0.0000    0.0000    0.0113    0.0837    0.0113    0.0000    0.0002    0.0837    0.6187    0.0837    0.0002    0.0000    0.0113    0.0837    0.0113    0.0000    0.0000    0.0000    0.0002    0.0000    0.0000
>> G=fspecial('gaussian',5,1.5)%1.5为滤波器的标准差。
G =     0.0144    0.0281    0.0351    0.0281    0.0144    0.0281    0.0547    0.0683    0.0547    0.0281    0.0351    0.0683    0.0853    0.0683    0.0351    0.0281    0.0547    0.0683    0.0547    0.0281    0.0144    0.0281    0.0351    0.0281    0.0144
>>
>> G=fspecial('average')%默认为3*3的矩阵。均值滤波
G =     0.1111    0.1111    0.1111    0.1111    0.1111    0.1111    0.1111    0.1111    0.1111
>> G=fspecial('average',5)%会产生5*5的矩阵。
————————————————

 
 
来源参考:https://ww2.mathworks.cn/help/images/ref/fspecial.html?searchHighlight=fspecial&s_tid=doc_srchtitle#d117e81606
 

fspecial

Create predefined 2-D filter

collapse all in page
 

Description

example

h = fspecial(type) creates a two-dimensional filter h of the specified type. Some of the filter types have optional additional parameters, shown in the following syntaxes. fspecial returns h as a correlation kernel, which is the appropriate form to use with imfilter.

h = fspecial('average',hsize) returns an averaging filter h of size hsize.

h = fspecial('disk',radius) returns a circular averaging filter (pillbox) within the square matrix of size 2*radius+1.

h = fspecial('gaussian',hsize,sigma) returns a rotationally symmetric Gaussian lowpass filter of size hsize with standard deviation sigma. Not recommended. Use imgaussfilt or imgaussfilt3 instead.

h = fspecial('laplacian',alpha) returns a 3-by-3 filter approximating the shape of the two-dimensional Laplacian operator, alpha controls the shape of the Laplacian.

h = fspecial('log',hsize,sigma) returns a rotationally symmetric Laplacian of Gaussian filter of size hsize with standard deviation sigma.

h = fspecial('motion',len,theta) returns a filter to approximate, once convolved with an image, the linear motion of a camera. len specifies the length of the motion and theta specifies the angle of motion in degrees in a counter-clockwise direction. The filter becomes a vector for horizontal and vertical motions. The default len is 9 and the default theta is 0, which corresponds to a horizontal motion of nine pixels.

h = fspecial('prewitt') returns a 3-by-3 filter that emphasizes horizontal edges by approximating a vertical gradient. To emphasize vertical edges, transpose the filter h'.

[ 1  1  1
0 0 0
-1 -1 -1 ]

h = fspecial('sobel') returns a 3-by-3 filter that emphasizes horizontal edges using the smoothing effect by approximating a vertical gradient. To emphasize vertical edges, transpose the filter h'.

[ 1  2  1
0 0 0
-1 -2 -1 ]
 

Examples

collapse all

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

collapse all

type — Type of filter
'average' | 'disk' | 'gaussian' | 'laplacian' | 'log' | 'motion' | 'prewitt' | 'sobel'

Type of filter, specified as one of the following values:

Value

Description

'average'

Averaging filter

'disk'

Circular averaging filter (pillbox)

'gaussian'

Gaussian lowpass filter. Not recommended. Use imgaussfilt or imgaussfilt3 instead.

'laplacian'

Approximates the two-dimensional Laplacian operator

'log'

Laplacian of Gaussian filter

'motion'

Approximates the linear motion of a camera

'prewitt'

Prewitt horizontal edge-emphasizing filter

'sobel'

Sobel horizontal edge-emphasizing filter

Data Types: char | string

hsize — Size of the filter
positive integer | 2-element vector of positive integers

Size of the filter, specified as a positive integer or 2-element vector of positive integers. Use a vector to specify the number of rows and columns in h. If you specify a scalar, then h is a square matrix.

When used with the '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].

Data Types: double

radius — Radius of a disk-shaped filter
5 (default) | positive number

Radius of a disk-shaped filter, specified as a positive number.

Data Types: double

sigma — Standard deviation
0.5 (default) | positive number

Standard deviation, specified as a positive number.

Data Types: double

alpha — Shape of the Laplacian
0.2 (default) | scalar in the range [0 1]

Shape of the Laplacian, specified as a scalar in the range [0 1].

Data Types: double

len — Linear motion of camera
9 (default) | numeric scalar

Linear motion of camera, specified as a numeric scalar, measured in pixels.

Data Types: double

theta — Angle of camera motion
0 (default) | numeric scalar

Angle of camera motion, specified as a numeric scalar, measured in degrees, in a counter-clockwise direction.

Data Types: double

Output Arguments

collapse all

h — Correlation kernel
matrix

Correlation kernel, returned as a matrix.

Data Types: double

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)n1n2hg

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)σ4n1n2hg

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:

  1. Construct an ideal line segment with the length and angle specified by the arguments len and theta, centered at the center coefficient of h.

  2. For each coefficient location (i,j), compute the nearest distance between that location and the ideal line segment.

  3. h = max(1 - nearest_distance, 0);

  4. Normalize h: h = h/(sum(h(:)))

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB Coder.

Usage notes and limitations:

  • fspecial supports 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.

GPU Code Generation
Generate CUDA code for NVIDIA GPUs using GPU Coder.

Usage notes and limitations:

  • When generating code, all inputs must be constants at compilation time.

 
 
 
 
 
 
 
 
 

Matlab中fspecial的用法的更多相关文章

  1. Matlab中fspecial的用法【转】

    Fspecial函数用于创建预定义的滤波算子,其语法格式为:h = fspecial(type)h = fspecial(type,parameters,sigma) 参数type制定算子类型,par ...

  2. MATLAB中“fitgmdist”的用法及其GMM聚类算法

    MATLAB中“fitgmdist”的用法及其GMM聚类算法 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ 高斯混合模型的基本原理:聚类——GMM,MA ...

  3. MATLAB中冒号的用法

    MATLAB中冒号的用法 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ matlab中冒号代表步长,用实例来说明 >> A=[1 2 3 ...

  4. MATLAB中冒号的用法解析

    MATLAB中冒号的用法解析 1.: 表示所有的意思. (1)如:a(1,:) 表示a的第1行,示例: 结果: 同样的如果a(2,:)表示a的第2行 (2)反过来,a(:,2) 表示a的第3列,示例: ...

  5. MATLAB中mean的用法

    https://blog.csdn.net/wangyang20170901/article/details/78745587 MATLAB中mean的用法 转载仙女阳 最后发布于2017-12-07 ...

  6. matlab中freqz的用法以及多项式的展开

    对于一个变量a,matlab中定义需要这样 syms a: 定义之后就可以写由变量组成的式子,比如 c=(1+a^-1)^5; 可以用expand(c) 就能把c展开成多项式,每一项的系数就可以看到. ...

  7. Matlab中struct的用法

    struct在matlab中是用来建立结构体数组的.通常有两种用法: s = struct('field1',{},'field2',{},...)  这是建立一个空的结构体,field1,field ...

  8. matlab中句柄@的用法

    @是Matlab中的句柄函数的标志符,即间接的函数调用方法. 1 句柄函数 主要有两种语法: handle = @functionname handle = @(arglist)anonymous_f ...

  9. matlab中fspecial Create predefined 2-D filter以及中值滤波均值滤波以及高斯滤波

    来源: 1.https://ww2.mathworks.cn/help/images/ref/fspecial.html?searchHighlight=fspecial&s_tid=doc_ ...

随机推荐

  1. laravel核心Ioc容器

    laravel容器和依赖注入 啥是Ioc容器,方便我们实现依赖注入的一种实现,也就是说依赖注入不一定需要控制反转容器,只不过使用容器可能会方便些. laravel通过向容器中绑定接口的具体实现,可实现 ...

  2. Unity透明地形

    http://answers.unity3d.com/questions/1162779/unity-5-transparent-terrain-shader.html http://answers. ...

  3. 模拟CMOS集成电路 课后习题总结(2.1)

    前几天开始自学拉扎维的模设教材,看之前浏览了EETOP论坛里面好多大神们对这本书的看法,当然也有人在抱怨,比如冒出“太科幻”.“一年才看完”之类恐怖的修饰语句,因此在开始看的时候就对此书充满了“敬畏” ...

  4. Activiti7 学习总结

    什么是工作流? 就是通过计算机对业务流程进行自动化处理,实现多个参与者按照预定义的流程去自动执行业务流程 什么是Activiti? Activiti是一个工作流引擎,开源的架构,基于BPMN2.0标准 ...

  5. 深入理解 JVM 的内存区域

    深入理解运行时数据区 代码示例: 1. JVM 向操作系统申请内存: JVM 第一步就是通过配置参数或者默认配置参数向操作系统申请内存空间,根据内存大小找到具体的内存分配表,然后把内存段的起始地址和终 ...

  6. linux vi编辑

    编辑模式 使用vi进入文本后,按i开始编辑文本 退出编辑模式 按ESC键,然后: 退出vi :q! 不保存文件,强制退出vi命令 :w 保存文件,不退出vi命令 :wq 保存文件,退出vi命令 中断v ...

  7. yum wget rpm

    wget 类似于迅雷,是一种下载工具          下载安装包 yum: 是redhat, centos 系统下的软件安装方式 下载安装包并自动安装 以及一些依赖关系 基于RPM包管理,能够从指定 ...

  8. Java数组实现随机生成N-M之间不重复的随机数

    接收一个整形数组,使用Math.Random每次在规定的数字范围内随机产生数字,然后嵌套for循环依次判断是否有重复值,如果有既外循环变量减一,直到把数组装满为止. /** * 随机生成 N--M的不 ...

  9. Python爬虫学习第一记 (翻译小助手)

    1 # Python爬虫学习第一记 8.24 (代码有点小,请放大看吧) 2 3 #实现有道翻译,模块一: $fanyi.py 4 5 import urllib.request 6 import u ...

  10. Java-Collection和Map

    创建博客的目的主要帮助自己记忆和复习日常学到和用到的知识:或有纰漏请大家斧正,非常感谢! 之前面试,被问过一个问题:List和Set的区别. 主要区别很明显了,两者都是数组形式存在的,继承了Colle ...