图像边缘检测拉普拉斯推导

图像点、线、边缘检测(1)——拉普拉斯

闲着无聊,整理一下图像中拉普拉斯算子的计算过程(离散差分方程)
公式来源:Digital Image Processing, 4th

关于 f ( x ) f(x) f(x)的导数公式推导

  • 将函数 f ( x + Δ x ) f(x + \Delta{x}) f(x+Δx) 关于 x x x 进行泰勒系数展开:
    f ( x + Δ x ) = f ( x ) + Δ x ∂ f ( x ) ∂ x + Δ x 2 2 ! ∂ 2 f ( x ) ∂ x 2 + Δ x 3 3 ! ∂ 3 f ( x ) ∂ x 3 + . . . = ∑ n = 0 ∞ ( Δ x ) n n ! ∂ n f ( x ) ∂ x n (1) \begin{aligned} f(x+\Delta{x})&=f(x)+\Delta{x} \frac{\partial{f(x)}}{\partial x}+\frac{\Delta{x^2}}{2!}\frac{\partial^2f(x)}{\partial x^2}+\frac{\Delta{x^3}}{3!}\frac{\partial^3f(x)}{\partial x^3} + {...} \\ &=\sum_{n=0}^{\infty}\frac{(\Delta x)^n}{n!}\frac{\partial^nf(x)}{\partial x^n} \end{aligned} \tag{1} f(x+Δx)=f(x)+Δxxf(x)+2!Δx2x22f(x)+3!Δx3x33f(x)+...=n=0n!(Δx)nxnnf(x)(1)

  • Δ x = 1 \Delta x =1 Δx=1(即像素后一位):
    f ( x + 1 ) = f ( x ) + ∂ f ( x ) ∂ x + 1 2 ! ∂ 2 f ( x ) ∂ x 2 + 1 3 ! ∂ 3 f ( x ) ∂ x 3 + … = ∑ n = 0 ∞ 1 n ! ∂ n f ( x ) ∂ x n (2) \begin{aligned} f(x+1)&=f(x)+\frac{\partial f(x)}{\partial x}+\frac{1}{2!}\frac{\partial ^2f(x)}{\partial x^2}+\frac{1}{3!}\frac{\partial ^3 f(x)}{\partial x^3}+… \\ &=\sum_{n=0}^{\infty}\frac{1}{n!}\frac{\partial ^n f(x)}{\partial x^n} \tag {2} \end{aligned} f(x+1)=f(x)+xf(x)+2!1x22f(x)+3!1x33f(x)+=n=0n!1xnnf(x)(2)

  • Δ x = − 1 \Delta x=-1 Δx=1(即像素前一位):
    f ( x − 1 ) = f ( x ) − ∂ f ( x ) ∂ x + 1 2 ! ∂ 2 f ( x ) ∂ x 2 − 1 3 ! ∂ 3 f ( x ) ∂ x 3 + . . . = ∑ n = 0 ∞ ( − 1 ) n n ! ∂ n f ( x ) ∂ x n (3) \begin{aligned} f(x-1)&=f(x)-\frac{\partial f(x)}{\partial x}+\frac{1}{2!}\frac{\partial ^2f(x)}{\partial x^2}-\frac{1}{3!}\frac{\partial ^3f(x)}{\partial x^3}+... \\ &=\sum_{n=0}^{\infty}\frac{(-1)^n}{n!}\frac{\partial ^n f(x)}{\partial x^n} \tag{3} \end{aligned} f(x1)=f(x)xf(x)+2!1x22f(x)3!1x33f(x)+...=n=0n!(1)nxnnf(x)(3)

  • E q . ( 2 ) Eq.(2) Eq.(2)得到前向差分:
    ∂ f ( x ) ∂ x = f ( x + 1 ) − f ( x ) (4) \frac {\partial f(x)}{\partial x}=f(x+1)-f(x) \tag{4} xf(x)=f(x+1)f(x)(4)

  • 同理, 由 E q . ( 3 ) Eq.(3) Eq.(3)得到后向差分:
    ∂ f ( x ) ∂ x = f ( x ) − f ( x − 1 ) (5) \frac{\partial f(x)}{\partial x}=f(x)-f(x-1) \tag{5} xf(x)=f(x)f(x1)(5)

  • E q . ( 3 ) Eq.(3) Eq.(3) - E q . ( 2 ) Eq.(2) Eq.(2)得到中心差分:
    ∂ f ( x ) ∂ x = f ′ ( x ) = f ( x + 1 ) − f ( x − 1 ) 2 (6) \frac{\partial f(x)}{\partial x} =f'(x)= \frac{f(x+1)-f(x-1)}{2} \tag{6} xf(x)=f(x)=2f(x+1)f(x1)(6)

  • 二阶导数, ∂ 2 f ( x ) / ∂ x 2 \partial ^2f(x)/\partial x^2 2f(x)/x2 E q . ( 2 ) Eq.(2) Eq.(2) E q . ( 3 ) Eq.(3) Eq.(3):
    ∂ 2 f ( x ) ∂ x 2 = f ′ ′ ( x ) = f ( x + 1 ) − 2 f ( x ) + f ( x − 1 ) (7) \frac{\partial ^2f(x)}{\partial x^2} = f''(x) = f(x+1)-2f(x)+f(x-1) \tag{7} x22f(x)=f(x)=f(x+1)2f(x)+f(x1)(7)

f ( x , y ) f(x,y) f(x,y)的导数推导

  • E q . ( 7 ) Eq.(7) Eq.(7)扩展至 f ( x , y ) f(x,y) f(x,y),对 x x x求导可得:
    ∂ 2 f ( x , y ) ∂ x 2 = f ( x + 1 , y ) − 2 f ( x , y ) + f ( x − 1 , y ) (8) \frac{\partial ^2f(x,y)}{\partial x^2} = f(x+1, y)-2f(x,y)+f(x-1,y) \tag{8} x22f(x,y)=f(x+1,y)2f(x,y)+f(x1,y)(8)

  • 同理,对 y y y求导得:
    ∂ 2 f ( x , y ) ∂ y 2 = f ( x , y + 1 ) − 2 f ( x , y ) + f ( x , y − 1 ) (9) \frac{\partial ^2f(x,y)}{\partial y^2} = f(x,y+1)-2f(x,y)+f(x,y-1) \tag{9} y22f(x,y)=f(x,y+1)2f(x,y)+f(x,y1)(9)

拉普拉斯算子

  • 拉普拉斯算子(Laplacian):
    ∇ 2 f ( x , y ) = ∂ 2 f ( x , y ) ∂ x 2 + ∂ 2 f ( x , y ) ∂ y 2 (10) \nabla ^2f(x,y) = \frac{\partial ^2f(x,y)}{\partial x^2}+\frac{\partial ^2f(x,y)}{\partial y^2} \tag{10} 2f(x,y)=x22f(x,y)+y22f(x,y)(10)

  • 根据 E q . ( 8 ) Eq.(8) Eq.(8) E q . ( 9 ) Eq.(9) Eq.(9)以及拉普拉斯算子可得二阶差分展开式:
    ∇ 2 f ( x , y ) = f ( x + 1 , y ) − 2 f ( x , y ) + f ( x − 1 , y ) + f ( x , y + 1 ) − 2 f ( x , y ) + f ( x , y − 1 ) = f ( x + 1 , y ) + f ( x − 1 , y ) + f ( x , y + 1 ) + f ( x , y − 1 ) − 4 f ( x , y ) (11) \begin{aligned} \nabla ^2f(x,y)&=f(x+1,y)-2f(x,y)+f(x-1,y)+f(x,y+1)-2f(x,y)+f(x,y-1) \\ &=f(x+1,y)+f(x-1,y)+f(x,y+1)+f(x,y-1)-4f(x,y) \tag{11} \end{aligned} 2f(x,y)=f(x+1,y)2f(x,y)+f(x1,y)+f(x,y+1)2f(x,y)+f(x,y1)=f(x+1,y)+f(x1,y)+f(x,y+1)+f(x,y1)4f(x,y)(11)

你可能感兴趣的:(线性代数,概率论,机器学习)