直线的极座标表示

考虑一条直线 ax+by+c=0ax+by+c=0,过原点 OO 做这条直线的垂线交于 NN。不妨令 NN 点的极座标为 (rN,θN)(r_N, \theta_N),再任取直线上的一点 P(x,y)P(x,y),显然应该有 ONNPON\perp NP,所以两向量垂直,故

ONNP=0 \vec{ON}\cdot \vec{NP}=0

代入 ON=(rNcos(θN),rNsin(θN)),NP=(xrNcos(θN),yrNsin(θN))\vec{ON}=(r_N\cos(\theta_N), r_N\sin(\theta_N)), \vec{NP}=(x-r_N\cos(\theta_N), y-r_N\sin(\theta_N)),化简并代入点乘公式有

rNcos(θN)(xrNcos(θN))+rNsin(θN)(yrNsin(θN))=0xrNcos(θN)rN2cos2(θN)+yrNsin(θN)rN2sin2(θN)=0xrNcos(θN)+yrNsin(θN)=rN2xcos(θN)+ysin(θN)=rN \begin{aligned} r_N \cos(\theta_N)\cdot\Big( x-r_N\cos(\theta_N) \Big) + r_N\sin(\theta_N)\cdot\Big( y-r_N\sin(\theta_N) \Big)&=0\\ x\cdot r_N\cos(\theta_N)-r_N^2\cos^2(\theta_N) + y\cdot r_N\sin(\theta_N) - r_N^2\sin^2(\theta_N)&=0\\ x\cdot r_N\cos(\theta_N) + y\cdot r_N\sin(\theta_N)&=r_N^2\\ x\cos(\theta_N) + y\sin(\theta_N)&=r_N \end{aligned}

所以直线的表达式是

xcosθ+ysinθ=r \boxed{x\cos\theta + y\sin\theta=r}

Transform from Image Space to Hough Space

(x0,y0)(x_0,y_0) 为图像上一点,对于图像空间来说,横轴为 xx,纵轴为 yy.

我们找出所有 (θ,r)(\theta,r) 满足

x0cosθ+y0sinθ=r x_0\cos\theta + y_0\sin\theta=r

把这些点标在 Hough Space 中。Hough Space 的横轴为 θ\theta,纵轴为 rr. 那么满足条件的 (θ,r)(\theta,r) 在 Hough Space 上的图像为正弦函数的一部分。

这是因为,我们可以把直线的极座标表达式转化成

1x02+y02sin(θ+φ)=r\frac{1}{\sqrt{x_0^2+y_0^2}}\sin(\theta+\varphi)=r

所以 Hough Space 上的曲线是正弦函数.

Curve Voting

对于每一个点 (x,y)(x,y),计算所有 (θ,r)(\theta,r),然后在计数器 AA 里 +1,即 A(θ,r)A(θ,r)+1A(\theta, r)\gets A(\theta, r)+1,最后,我们取得票数最多的 (θ,r)(\theta, r) 视作 Linked Edge.

这个就类似于,我们对每一个点计算它可能属于什么直线,然后对所有点找出那条公共的直线。