使用 计算梯度时imgradientxy(I,'intermediate')
:
GX(j, i) = I(j, i+1) - I(j, i)
GY(j, i) = I(j+1, i) - I(j, i)
和拉普拉斯算子:
L(j, i) = I(j, i-1) + I(j, i+1) + I(j-1, i) + I(j+1, i) - 4*I(j, i)
现在如果我们计算GX
和的梯度GY
:
GGX(j, i) = GX(j, i) - GX(j, i-1)
= I(j, i+1) - I(j, i) - I(j, i) + I(j, i-1)
= I(j, i-1) + I(j, i+1) - 2*I(j, i)
GGY(j, i) = I(j-1, i) + I(j+1, i) - 2*I(j, i)
所以
L(j, i) = GGX(j, i) + GGY(j, i)
请注意,用于查找 和 的梯度的方法之间存在像素I
偏移。GX
GY
I = im2double(imread('coins.png'));
[GX, GY] = imgradientxy(I,'intermediate');
L = imfilter(I, [0 1 0; 1 -4 1; 0 1 0], 'replicate');
GGX = imfilter(GX, [0 0 0; -1 1 0; 0 0 0], 'replicate');
GGY = imfilter(GY, [0 -1 0; 0 1 0; 0 0 0], 'replicate');
L2 = GGX+GGY;
E = (L2-L).^2;