Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 梯度和imgradient的区别是什么?_Algorithm_Matlab_Image Processing_Computer Vision - Fatal编程技术网

Algorithm 梯度和imgradient的区别是什么?

Algorithm 梯度和imgradient的区别是什么?,algorithm,matlab,image-processing,computer-vision,Algorithm,Matlab,Image Processing,Computer Vision,我想计算图像I的梯度。我有两个选项 [Gx, Gy] = gradient(I); g = sqrt(Gx.^2+Gy.^2); 及 我的问题是 梯度法在第一个选项中使用的是什么 用索贝尔法求梯度有什么好处 谢谢大家 这就是我试过的 I=zeros([128 128]); I(50:100,50:100)=100; [Gx, Gy] = gradient(I); g1 = sqrt(Gx.^2+Gy.^2); [g2,~] = imgradient(I, 'sobel'); subplot(1

我想计算图像I的梯度。我有两个选项

[Gx, Gy] = gradient(I);
g = sqrt(Gx.^2+Gy.^2);

我的问题是

  • 梯度法在第一个选项中使用的是什么

  • 用索贝尔法求梯度有什么好处

  • 谢谢大家

    这就是我试过的

    I=zeros([128 128]);
    I(50:100,50:100)=100;
    [Gx, Gy] = gradient(I);
    g1 = sqrt(Gx.^2+Gy.^2);
    [g2,~] = imgradient(I, 'sobel');
    subplot(121);imshow(g1,[]);title('First option')
    subplot(122);imshow(g2,[]);title('Second option')
    

    当噪声加入到图像中时,不同的图像会更清晰

    I=zeros([128 128]);
    I(50:100,50:100)=100;
    %% Add noise image;
    noiseStd=5;
    I_noise = I + (noiseStd * randn([128, 128]));
    [Gx, Gy] = gradient(I_noise);
    g1 = sqrt(Gx.^2+Gy.^2);
    [g2,~] = imgradient(I_noise, 'sobel');
    subplot(121);imshow(g1,[]);title('First option')
    subplot(122);imshow(g2,[]);title('Second option')
    


    作为可视化,第二个选项提供了更多的亮度值

    区别在于“Sobel”操作符。sobel算子是一个矩阵,它与图像卷积以计算其方向梯度

    sobel运算符定义为(来自wikipedia):

    gradient
    所做的只是方向差异。你可以把它解释为梯度

    Gx=[ 0 0 0;                Gx=[ 0 -1 0;
        -1 0 1;         and         0  0 0;
         0 0 0]                     0  1 0];
    
    这种差异是因为当一个人有一个图像时,我们知道它是一个连续域的离散化。Sobel操作符有助于考虑“围绕”给定像素发生的事情。

    专门使用中心差,并为您提供选择,例如
    'central'
    或默认的
    'Sobel'
    。使用第一个选项
    imgradient
    看起来与
    gradient
    相同:

    I=zeros([128 128]);
    I(50:100,50:100)=100;
    %% Add noise image;
    noiseStd=5;
    I_noise = I + (noiseStd * randn([128, 128]));
    [Gx, Gy] = gradient(I_noise);
    g1 = sqrt(Gx.^2+Gy.^2);
    [g2,~] = imgradient(I_noise, 'sobel');
    [g3,~] = imgradient(I_noise, 'central');
    subplot(131);imshow(g1,[]);title('gradient')
    subplot(132);imshow(g2,[]);title('imgradient sobel')
    subplot(133);imshow(g3,[]);title('imgradient central')
    


    对于
    imgradient
    有五个可用选项:

    • “sobel”sobel渐变运算符(默认值)
    • “prewitt”prewitt梯度算子
    • “中心”中心差梯度:dI/dx=(I(x+1)-I(x-1))/2
    • “中间”中间差梯度:dI/dx=I(x+1)-I(x)
    • “roberts”roberts梯度算子
    文件说明:

    imgradient
    中针对每个列出的 梯度法首先计算方向梯度,
    Gx
    Gy
    , 相对于x轴和y轴。x轴沿轴方向定义 列向右移动,y轴沿向右移动的行定义 放下。然后根据以下公式计算梯度大小和方向: 它们的正交分量
    Gx
    Gy


    你试过比较吗?amin的不同之处在于,一个是用于图像的工具箱,另一个适用于任何眼睛。我更新了它。请看我更新的问题嗨!考虑接受一个答案作为有效,如果我只考虑梯度没有它的方向作为我上面的代码。这两个梯度有什么不同?@user8430
    imgradient
    只将
    sqrt(Gx^2+Gy^2)
    作为输出,而
    gradient
    则分别为您提供。正是这样。从我的结果可以清楚地看出,中心差分法比索贝尔法产生更多的噪声。因此,与中心差分法相比,Sobel法通过使用不同的核和设计的系数实现了更好的噪声抑制。你同意我的看法吗?@user8430当然同意。因为它不仅考虑了像素的两个邻域,而且还考虑了6个邻域,因此噪声得到了一点“平均值”@user8430很好的回答,但除了Ander所说的“噪声得到了一点平均值”之外,注意Sobel在中心的权重也更大。这几乎就像(低分辨率)高斯平滑滤波器。prewitt滤波器(真实平均值)将使用
    Gy=[1,1,1;0,0,0;-1,-1]
    ,虽然这将去除一些噪声,但结果与sobel不同。将这些过滤器视为预先设定的。由边缘检测器
    [1,0,-1]*平滑函数构成
    ,因此只需考虑平均模糊和高斯模糊之间的差异。希望这能给你更多的洞察力谢谢你的中心差异的例子。那么,sobel算子的优点是什么呢。正如小猪所说,它提供了更平滑的图像。@user8430答案将在StackOverflow的范围之后,我实际上不知道。您需要对单个算法进行一些研究。
    I=zeros([128 128]);
    I(50:100,50:100)=100;
    %% Add noise image;
    noiseStd=5;
    I_noise = I + (noiseStd * randn([128, 128]));
    [Gx, Gy] = gradient(I_noise);
    g1 = sqrt(Gx.^2+Gy.^2);
    [g2,~] = imgradient(I_noise, 'sobel');
    [g3,~] = imgradient(I_noise, 'central');
    subplot(131);imshow(g1,[]);title('gradient')
    subplot(132);imshow(g2,[]);title('imgradient sobel')
    subplot(133);imshow(g3,[]);title('imgradient central')