彩色图像边缘检测

回顾灰度图像边缘检测,我们一般求出图像的梯度:

fx(x,y)=f(x+1,y)f(x,y)fy(x,y)=f(x,y+1)f(x,y)
<script type="math/tex; mode=display" id="MathJax-Element-1">\nabla f_{x}(x,y)=f(x+1,y)-f(x,y)\\ \nabla f_{y}(x,y)=f(x,y+1)-f(x,y)</script>或者求出图像的二阶差分:
Δfx(x,y)=f(x+1,y)+f(x1,y)2f(x,y)Δfy(x,y)=f(x,y+1)+f(x,y1)2f(x,y)
<script type="math/tex; mode=display" id="MathJax-Element-2">\Delta f_{x}(x,y)=f(x+1,y)+f(x-1,y)-2f(x,y)\\ \Delta f_{y}(x,y)=f(x,y+1)+f(x,y-1)-2f(x,y)</script>然后根据梯度和二阶差分的大小,以及最大变化率方向来寻找可能存在的图像边缘。

彩色图像的每个像素包含红绿蓝三个分量,这样每个像素可以由一个三维向量来表示。但是在进行图像边缘检测的时候,我们遇到一个问题,那就是向量并不存在梯度概念。单独对每个颜色分量进行边缘检测,其梯度不能反映图像整体彩色的差异变化。

一个广为使用的彩色图像梯度方法来自Zenzo[1986]的论文

u⃗ =Rxr⃗ +Gxg⃗ +Bxb⃗ 
<script type="math/tex; mode=display" id="MathJax-Element-3">\vec{u}=\frac{\partial{R}}{\partial{x}}\vec{r}+\frac{\partial{G}}{\partial{x}}\vec{g}+\frac{\partial{B}}{\partial{x}}\vec{b} </script>
v⃗ =Ryr⃗ +Gyg⃗ +Byb⃗ 
<script type="math/tex; mode=display" id="MathJax-Element-4"> \vec{v}=\frac{\partial{R}}{\partial{y}}\vec{r}+\frac{\partial{G}}{\partial{y}}\vec{g}+\frac{\partial{B}}{\partial{y}}\vec{b}</script>
其中R,G,B是图像分量,r⃗ ,g⃗ ,b⃗ <script type="math/tex" id="MathJax-Element-5">\vec{r},\vec{g},\vec{b}</script>等是单位向量,表征颜色分量坐标。然后继续计算有:
gxx=u⃗ Tu⃗ =Rx2+Gx2+Bx2
<script type="math/tex; mode=display" id="MathJax-Element-6">g_{xx}=\vec{u}^T\vec{u}=\left|\frac{\partial{R}}{\partial{x}} \right|^2+\left|\frac{\partial{G}}{\partial{x}} \right|^2+\left|\frac{\partial{B}}{\partial{x}} \right|^2</script>
gyy=v⃗ Tv⃗ =Ry2+Gy2+By2
<script type="math/tex; mode=display" id="MathJax-Element-7">g_{yy}=\vec{v}^T\vec{v}=\left|\frac{\partial{R}}{\partial{y}} \right|^2+\left|\frac{\partial{G}}{\partial{y}} \right|^2+\left|\frac{\partial{B}}{\partial{y}} \right|^2</script>
gxy=u⃗ Tv⃗ =RxRy+GxGy+BxBy
<script type="math/tex; mode=display" id="MathJax-Element-8">g_{xy}=\vec{u}^T\vec{v}=\frac{\partial{R}}{\partial{x}}\frac{\partial{R}}{\partial{y}}+\frac{\partial{G}}{\partial{x}}\frac{\partial{G}}{\partial{y}}+\frac{\partial{B}}{\partial{x}}\frac{\partial{B}}{\partial{y}}</script>
注意这里执行的是向量乘法,而不是进一步求导。梯度方向为:
θ=12arctan[2gxy(gxxgyy)]
<script type="math/tex; mode=display" id="MathJax-Element-9">\theta=\frac{1}{2} \arctan{\left[ \frac{2g_{xy}}{(g_{xx}-g_{yy})} \right]}</script>由梯度方向才能计算梯度:
F(θ)={12[(gxx+gyy)+(gxxgyy)cos2θ+2gxysin2θ]}12
<script type="math/tex; mode=display" id="MathJax-Element-10">F(\theta)= \{\frac{1}{2} [(g_{xx}+g_{yy})+(g_{xx}-g_{yy}) \cos{2\theta}+2g_{xy} \sin{2\theta}] \}^{\frac{1}{2}}</script>

matlab上自带的edge函数目前没发现可以对彩色图像直接进行边缘检测的方法,C++的openCV库也没有发现。上述工具一般会对彩色图像进行灰度化再执行边缘检测,效果也不算差。

Zenzo, A Note on the Gradient of a Multi-Image,º Computer[C]// Vision Graphics Image Processing. 1986.

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐