您的位置:首页 > 其它

关于梯度计算和相关原理

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_operatorhttp://codesmesh.com/canny-edge-detection-with-matlab/

当然,使用 edit edge可以查看canny的源码,应该可以看到怎么用CANNY算子计算gradient magnitude的方法,我去试试就来
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: