您的问题暗示您认为需要将图像中的每个 (X,Y) 兴趣点映射到 Hough 中的 ONE (rho, theta) 向量空格。
事实上,图像中的每个点都映射到一个曲线,即霍夫空间中的SEVERAL个向量。每个输入点的向量数量取决于您决定的一些“任意”分辨率。例如,对于 1 度分辨率,您将在霍夫空间中获得 360 个向量。
对于 (rho, theta) 向量,有两种可能的约定:对于 theta 使用 [0, 359] 度范围,在这种情况下 rho 始终为正,或者对于 theta 和使用 [0,179] 度范围允许 rho 为正或负。后者通常用于许多实现中。
一旦你理解了这一点,累加器只不过是一个二维数组,它涵盖了 (rho, theta) 空间的范围,并且每个单元格都初始化为 0。它是用于统计输入中不同点的各种曲线共有的向量个数。
因此,该算法为输入图像中的每个 兴趣点计算所有 360 个向量(假设 theta 的分辨率为 1 度)。对于这些向量中的每一个,在将 rho 舍入到最接近的整数值之后(取决于 rho 维度的精度,例如,如果我们每单位有 2 个点,则为 0.5),它会在累加器中找到相应的单元格,并增加该单元格中的值.
当对所有兴趣点都完成此操作后,算法会搜索累加器中所有值高于所选阈值的单元格。这些单元格的 (rho, theta) “地址”是 Hough 算法已识别的线(在输入图像中)的极坐标值。
现在,请注意,这会为您提供 line 方程,通常剩下的就是找出有效属于输入图像的这些线的 segment。
上面的一个非常粗略的伪代码“实现”
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.
总的来说,这是一个相当简单的算法。复杂性主要在于与单位保持一致,例如用于度数和弧度之间的转换(大多数数学库的三角函数都是基于弧度的),以及用于输入图像的坐标系。