关于梯度计算和相关原理
2014-07-03 16:35
627 查看
原谅我没认真上《数字图像处理》,相关理论基础实在差劲,现在为了解决一篇论文中的这句话(Calculate the gradient magnitude image G of the smoothed image, using, e.g., Sobel’s edge operator)的matlab实现,找了如下资料,特此记录。其中,Sobel's edge operator 换做Canny来实现
网站http://bbs.csdn.net/topics/390450485中说
function ***EGRAD=avegrad(img)
%%%% this function is used to calculate the average gradient of an image.
%%%% 平均梯度可敏感地反映图像对微小细节反差表达的能力,可用来评价图像的模糊程度在图像中,某一方向的灰度级变化率大,它的梯
%%%% 度就大。因此,可以用平均梯度值来衡量图像的清晰度,还同时反映出图像中微小细节反差和纹理变换特征。
img=double(img);
[M,N]=size(img);
gradval=zeros(M,N); %%% save the gradient value of single pixel
diffX=zeros(M,N); %%% save the differential value of X orient
diffY=zeros(M,N); %%% save the differential value of Y orient
tempX=zeros(M,N);
tempY=zeros(M,N);
tempX(1:M,1:(N-1))=img(1:M,2:N);
tempY(1:(M-1),1:N)=img(2:M,1:N);
diffX=img-tempX;
diffY=img-tempY;
diffX(1:M,N)=0; %%% the boundery set to 0
diffY(M,1:N)=0;
diffX=diffX.*diffX;
diffY=diffY.*diffY;
***EGRAD=sum(sum(diffX+diffY));
***EGRAD=sqrt(***EGRAD/2);
***EGRAD=***EGRAD/((M-1)*(N-1));
end
http://blog.csdn.net/KevinTq/article/details/8634533中的内容如下:
matlab 中gradient()是求数值梯度函数的命令。计算原理是:Fx为其水平方向上的梯度,Fy为其垂直方向上的梯度,Fx(i,j)={ Fx(i,j+1)-Fx(i,j-1)}/2,其中要注意的首尾两列分别是第二列和第一列的差值,最后一列和其一列的差值。同理我们也可以求出Fy方向的梯度。
用[Fx,Fy]=gradient(x) 函数直接实现
上述两种算法比较简单,而且没用到Sobel operator,所以不是我想要的,但是基本说出了梯度的基本概念。
关于Sobel operator的wiki定义如下http://en.wikipedia.org/wiki/Sobel_operator
就是用上述算子来计算梯度,当然G=sqrt(Gx.*Gx+Gy.*Gy);
所以,用Sobel算子计算gradient magnitude的方法已经知道了。
关于Canny算子的定义参考http://en.wikipedia.org/wiki/Canny_operator和http://codesmesh.com/canny-edge-detection-with-matlab/
当然,使用 edit edge可以查看canny的源码,应该可以看到怎么用CANNY算子计算gradient magnitude的方法,我去试试就来
网站http://bbs.csdn.net/topics/390450485中说
function ***EGRAD=avegrad(img)
%%%% this function is used to calculate the average gradient of an image.
%%%% 平均梯度可敏感地反映图像对微小细节反差表达的能力,可用来评价图像的模糊程度在图像中,某一方向的灰度级变化率大,它的梯
%%%% 度就大。因此,可以用平均梯度值来衡量图像的清晰度,还同时反映出图像中微小细节反差和纹理变换特征。
img=double(img);
[M,N]=size(img);
gradval=zeros(M,N); %%% save the gradient value of single pixel
diffX=zeros(M,N); %%% save the differential value of X orient
diffY=zeros(M,N); %%% save the differential value of Y orient
tempX=zeros(M,N);
tempY=zeros(M,N);
tempX(1:M,1:(N-1))=img(1:M,2:N);
tempY(1:(M-1),1:N)=img(2:M,1:N);
diffX=img-tempX;
diffY=img-tempY;
diffX(1:M,N)=0; %%% the boundery set to 0
diffY(M,1:N)=0;
diffX=diffX.*diffX;
diffY=diffY.*diffY;
***EGRAD=sum(sum(diffX+diffY));
***EGRAD=sqrt(***EGRAD/2);
***EGRAD=***EGRAD/((M-1)*(N-1));
end
http://blog.csdn.net/KevinTq/article/details/8634533中的内容如下:
matlab 中gradient()是求数值梯度函数的命令。计算原理是:Fx为其水平方向上的梯度,Fy为其垂直方向上的梯度,Fx(i,j)={ Fx(i,j+1)-Fx(i,j-1)}/2,其中要注意的首尾两列分别是第二列和第一列的差值,最后一列和其一列的差值。同理我们也可以求出Fy方向的梯度。
用[Fx,Fy]=gradient(x) 函数直接实现
上述两种算法比较简单,而且没用到Sobel operator,所以不是我想要的,但是基本说出了梯度的基本概念。
关于Sobel operator的wiki定义如下http://en.wikipedia.org/wiki/Sobel_operator
就是用上述算子来计算梯度,当然G=sqrt(Gx.*Gx+Gy.*Gy);
所以,用Sobel算子计算gradient magnitude的方法已经知道了。
关于Canny算子的定义参考http://en.wikipedia.org/wiki/Canny_operator和http://codesmesh.com/canny-edge-detection-with-matlab/
当然,使用 edit edge可以查看canny的源码,应该可以看到怎么用CANNY算子计算gradient magnitude的方法,我去试试就来
相关文章推荐
- 关于android内存管理的原理,及相关自动内存管理软件原理
- 分布式计算原理之二:关于计算的模型
- Java关于JIT的原理和相关知识
- 计算机组成原理--编址与存储相关计算
- 关于JVM中方法调用的相关指令,以及解析(Resolution)和分派(Dispatch)的解释——重载的实现原理与重写的实现原理
- ke隆系统中关于Windows 硬件抽象层(HAL)的相关原理
- 关于PPP认证中的PAP和CHAP原理取证与相关疑问
- matlab 梯度计算原理
- 关于郭天祥单片机书上第四十七页延时函数的相关计算问题
- 数学计算相关算法原理及实现
- 关于抗菌药的限定日计量DDD的相关计算
- 关于strut1 对比 servlet 的内部原理及相关实现方案
- 发光二极管原理,理解,相关计算
- 关于android内存管理的原理,及相关自动内存管理软件原理
- 关于android内存管理的原理,及相关自动内存管理软件原理 .
- Opencv中计算梯度、梯度幅值以及梯度方向的相关函数
- 关于计算机类期刊投稿心得 & 演化计算&演化硬件相关会议评价
- 关于计算机类期刊投稿心得 & 演化计算&演化硬件相关会议评价
- 关于编译原理中的follow集的计算
- 关于两个日期间隔计算及日期其他相关