Matlab中fspecial的用法
来源: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。
————————————————
fspecial
Create predefined 2-D filter
Syntax
Description
returns a rotationally symmetric Gaussian lowpass filter of size h = fspecial('gaussian',hsize,sigma)hsize with standard deviation sigma. Not recommended. Use imgaussfilt or imgaussfilt3 instead.
returns a filter to approximate, once convolved with an image, the linear motion of a camera. h = fspecial('motion',len,theta)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.
returns a 3-by-3 filter that emphasizes horizontal edges by approximating a vertical gradient. To emphasize vertical edges, transpose the filter h = fspecial('prewitt')h'.
[ 1 1 1
0 0 0
-1 -1 -1 ]
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 = fspecial('sobel')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
type — Type of filter
'average' | 'disk' | 'gaussian' | 'laplacian' | 'log' | 'motion' | 'prewitt' | 'sobel'
Type of filter, specified as one of the following values:
|
Value |
Description |
|---|---|
|
|
Averaging filter |
|
|
Circular averaging filter (pillbox) |
|
|
Gaussian lowpass filter. Not recommended. Use |
|
|
Approximates the two-dimensional Laplacian operator |
|
|
Laplacian of Gaussian filter |
|
|
Approximates the linear motion of a camera |
|
|
Prewitt horizontal edge-emphasizing filter |
|
|
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
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)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
C/C++ Code Generation
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.
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的用法的更多相关文章
- Matlab中fspecial的用法【转】
Fspecial函数用于创建预定义的滤波算子,其语法格式为:h = fspecial(type)h = fspecial(type,parameters,sigma) 参数type制定算子类型,par ...
- MATLAB中“fitgmdist”的用法及其GMM聚类算法
MATLAB中“fitgmdist”的用法及其GMM聚类算法 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ 高斯混合模型的基本原理:聚类——GMM,MA ...
- MATLAB中冒号的用法
MATLAB中冒号的用法 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ matlab中冒号代表步长,用实例来说明 >> A=[1 2 3 ...
- MATLAB中冒号的用法解析
MATLAB中冒号的用法解析 1.: 表示所有的意思. (1)如:a(1,:) 表示a的第1行,示例: 结果: 同样的如果a(2,:)表示a的第2行 (2)反过来,a(:,2) 表示a的第3列,示例: ...
- MATLAB中mean的用法
https://blog.csdn.net/wangyang20170901/article/details/78745587 MATLAB中mean的用法 转载仙女阳 最后发布于2017-12-07 ...
- matlab中freqz的用法以及多项式的展开
对于一个变量a,matlab中定义需要这样 syms a: 定义之后就可以写由变量组成的式子,比如 c=(1+a^-1)^5; 可以用expand(c) 就能把c展开成多项式,每一项的系数就可以看到. ...
- Matlab中struct的用法
struct在matlab中是用来建立结构体数组的.通常有两种用法: s = struct('field1',{},'field2',{},...) 这是建立一个空的结构体,field1,field ...
- matlab中句柄@的用法
@是Matlab中的句柄函数的标志符,即间接的函数调用方法. 1 句柄函数 主要有两种语法: handle = @functionname handle = @(arglist)anonymous_f ...
- matlab中fspecial Create predefined 2-D filter以及中值滤波均值滤波以及高斯滤波
来源: 1.https://ww2.mathworks.cn/help/images/ref/fspecial.html?searchHighlight=fspecial&s_tid=doc_ ...
随机推荐
- JVM 垃圾收集算法 标记-清楚、标记-复制、标记-整理
摘要 Java程序在运行过程中会产生大量的对象,但是内存大小是有限的,如果光用而不释放,那内存迟早被耗尽.如C.C++程序,需要程序员手动释放内存,Java则不需要,是由垃圾回收器去自动回收. 垃圾回 ...
- amd、cmd、CommonJS以及ES6模块化
AMD.CMD.CommonJs.ES6的对比 他们都是用于在模块化定义中使用的,AMD.CMD.CommonJs是ES5中提供的模块化编程的方案,import/export是ES6中定义新增的 什么 ...
- 入门的艰难——关于LR的使用
这年头做一件事真是TM不容易啊.做测试也很纠结,不是都说商业工具很强大么,我去,这个不支持那个不支持的,这还有什么搞头,还非要按照你说的这个版本的才行,高一点的就crash了,结果连最初级的录制脚本都 ...
- Python技术调查
1. IDE 2. Local Debugging & Remote Debugging 3. Profiling
- Azure Storage 系列(二) .NET Core Web 项目中操作 Blob 存储
一,引言 上一篇文章,我们介绍到在实际项目中系统会产生大量的日志文件,用户上传的头像等等,同时也介绍到可以使用Azure Blob Storage 来存储项目中的一些日志文件,用户头像,用户视频等等. ...
- HDU多校-1004-Vacation(思维)
Tom and Jerry are going on a vacation. They are now driving on a one-way road and several cars are i ...
- html打印后不刷新当前页
这种方法可以在打印的页面中添加样式,新页面跳转打印 doPrint(ids){ var titleHTML=document.getElementById(ids).innerHTML; var Op ...
- 2020年的UWP——通过Radio类控制Cellular(1)
最近在做UWP的项目,在2020年相信这已经是相对小众的技术了,但是在学习的过程中,发现某软这么几年仍然添加了不少的API,开放了相当多的权限.所以打算总结一下最近的一些经验和收获,介绍一下2020年 ...
- python3之print()函数
print语法格式 print()函数具有丰富的功能,详细语法格式如下: print(value, -, sep=' ', end='\n', file=sys.stdout, flush=False ...
- C++11的decltype关键字
C++11的decltype关键字 概述 decltype关键字和auto有异曲同工之处 有时我们希望从表达式的类型推断出要定义的变量类型,但是不想用该表达式的值初始化变量(如果要初始化就用auto了 ...