Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于C中的hough变换,如何将X,Y点转换为ρ,θ?_C_Hough Transform - Fatal编程技术网

对于C中的hough变换,如何将X,Y点转换为ρ,θ?

对于C中的hough变换,如何将X,Y点转换为ρ,θ?,c,hough-transform,C,Hough Transform,所以我尝试在C语言上编码Hough变换。我有一个二值图像,并从图像中提取了二值。现在要进行hough变换,我必须将图像中的[X,Y]值转换成[rho,theta]来进行形式的参数变换 rho=xcos(θ)+ysin(θ) 我不太明白它实际上是如何转变的,看看其他在线代码。任何解释算法以及如何基于[X,Y]进行[rho,theta]值累加器的帮助都将不胜感激。提前感谢。:) 您的问题暗示了一个事实,即您认为需要将图像中的每个(X,Y)关注点映射到Hough空间中的一个(rho,θ)向量 事实上,

所以我尝试在C语言上编码Hough变换。我有一个二值图像,并从图像中提取了二值。现在要进行hough变换,我必须将图像中的[X,Y]值转换成[rho,theta]来进行形式的参数变换

rho=xcos(θ)+ysin(θ)


我不太明白它实际上是如何转变的,看看其他在线代码。任何解释算法以及如何基于[X,Y]进行[rho,theta]值累加器的帮助都将不胜感激。提前感谢。:)

您的问题暗示了一个事实,即您认为需要将图像中的每个(X,Y)关注点映射到Hough空间中的一个(rho,θ)向量

事实上,图像中的每个点都映射到一条曲线,即Hough空间中的几个向量。每个输入点的向量数取决于您决定的某种“任意”分辨率。例如,对于1度分辨率,可以在Hough空间中获得360个向量

对于(ρ,θ)向量,有两种可能的约定:要么使用[0359]度范围表示θ,在这种情况下,ρ始终为正,要么使用[0179]度表示θ,并允许ρ为正或负。后者通常用于许多实现中

一旦您理解了这一点,累加器只不过是一个二维数组,它覆盖了(ρ,θ)空间的范围,其中每个单元格都初始化为0。它用于计算输入中不同点的各种曲线共有的向量数

因此,该算法计算输入图像中每个感兴趣点的所有360个矢量(假设θ的分辨率为1度)。对于这些向量中的每一个,在将rho四舍五入到最接近的整数值(取决于rho维度的精度,例如,若我们每单位有2个点,则为0.5)后,它会在累加器中找到相应的单元格,并增加该单元格中的值。
对所有感兴趣的点执行此操作后,算法将搜索累加器中值高于选定阈值的所有单元格。这些单元的(ρ,θ)“地址”是Hough算法识别的线(在输入图像中)的极坐标值

现在,请注意,这将为您提供直线方程,通常只需计算出这些直线中实际上属于输入图像的线段

上面的一个非常粗糙的伪代码“实现”

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.

总的来说,这是一个相当简单的算法。复杂性主要在于与单位一致,例如度和弧度之间的转换(大多数数学库的trig函数基于弧度),以及输入图像所用的坐标系。

谢谢。不可能要求一个更好更简单的解释。