所以我试图在C上编码Hough变换.我有一个二进制图像并从图像中提取了二进制值.现在做霍夫变换我必须将图像中的[X,Y]值转换为[rho,theta]来进行形式的参数变换
RHO = xcos(THETA)+ ysin(THETA)
我不太明白它是如何实际转换的,看看其他在线代码.任何帮助解释算法以及如何根据[X,Y]完成[rho,theta]值的累加器将不胜感激.谢谢.提前.:)
你的问题暗示你认为你需要将图像中的每个(X,Y)兴趣点映射到Hough空间中的ONE(rho,theta)向量.
事实是,图像中的每个点都映射到曲线,即霍夫空间中的几个向量.每个输入点的向量数取决于您决定的某些"任意"分辨率.例如,对于1度分辨率,您将在霍夫空间中获得360个向量.
对于(rho,theta)向量,有两种可能的约定:要么使用[0,359]度范围为theta,在这种情况下rho总是正数,或者你使用[0,179]度为theta并允许rho到无论是积极的还是消极的.后者通常用于许多实现中.
一旦你理解了这一点,累加器只是一个二维数组,它涵盖了(rho,theta)空间的范围,并且每个单元格用0初始化.它用于计算常见的向量数量输入中不同点的各种曲线.
因此,该算法针对输入图像中的每个感兴趣点计算所有360个矢量(假设θ的分辨率为1度).对于这些向量中的每一个,在将rho舍入到最接近的整数值(取决于rho维度的精度,例如,如果我们每单位有2个点,则为0.5)之后,它在累加器中找到相应的单元格,并递增该单元格中的值.
当针对所有感兴趣点完成此操作时,算法搜索累加器中具有高于所选阈值的值的所有单元.这些单元的(rho,theta)"地址"是霍夫算法已经识别的线(在输入图像中)的极坐标值.
现在,请注意,这给你行方程,一个通常留下了身影了段,这些线路输入图像中属于有效的.
一个非常粗略的伪代码"实现"以上
Accumulator_rho_size = Sqrt(2) * max(width_of_image, height_of_image)
* precision_factor // e.g. 2 if we want 0.5 precision
Accumulator_theta_size = 180 // going with rho positive or negative convention
Accumulator = newly allocated array of integers
with dimension [Accumulator_rho_size, Accumulator_theta_size]
Fill all cells of Accumulator with 0 value.
For each (x,y) point of interest in the input image
For theta = 0 to 179
rho = round(x * cos(theta) + y * sin(theta),
value_based_on_precision_factor)
Accumulator[rho, theta]++
Search in Accumulator the cells with the biggest counter value
(or with a value above a given threshold) // picking threshold can be tricky
The corresponding (rho, theta) "address" of these cells with a high values are
the polar coordinates of the lines discovered in the the original image, defined
by their angle relative to the x axis, and their distance to the origin.
Simple math can be used to compute various points on this line, in particular
the axis intercepts to produce a y = ax + b equation if so desired.
Run Code Online (Sandbox Code Playgroud)
总的来说这是一个相当简单的算法.复杂性主要在于与单元一致,例如用于度和弧度之间的转换(大多数数学库的trig函数是基于弧度的),并且还涉及用于输入图像的坐标系.