Main Content

伙计

霍夫变换

Description

例子

[[H,,,,Theta,,,,] = hough(BW计算二进制图像的标准霍夫变换(SHT)BW。The伙计function is designed to detect lines. The function uses the parametric representation of a line:rho = x*cos(theta) + y*sin(theta)。The function returns,,,,the distance from the origin to the line along a vector perpendicular to the line, andTheta,在X- 轴和该向量。该功能还返回SHT,H,,,,which is a parameter space matrix whose rows and columns correspond toandTheta值分别。有关更多信息,请参阅Algorithms

例子

[[H,,,,Theta,,,,] = hough(BW,,,,名称,价值computes the SHT of the binary imageBW使用名称值参数来影响计算。

Examples

全部收缩

阅读图像,然后将其转换为灰度图像。

RGB = imread('gantrycrane.png');I = im2gray(RGB);

提取边缘。

bw = edge(i,'canny');

计算霍夫变换。

[H,T,R] = Hough(BW,'RhoResolution',,,,0.5,'theta',-90:0.5:89);

显示原始图像和脚腕矩阵。

子图(2,1,1);IMShow(RGB);标题('gantrycrane.png');subplot(2,1,2); imshow(imadjust(rescale(H)),'xdata',,,,T,'ydata',,,,R,...“初始磁化”,,,,'合身');标题('gantrycrane.png的霍夫变换');Xlabel('\theta'),,,,ylabel('\ rho');轴on,轴普通的,,,,holdon;colormap(GCA,热);

Figure contains 2 axes objects. Axes object 1 with title Hough transform of gantrycrane.png contains an object of type image. Axes object 2 with title gantrycrane.png contains an object of type image.

Read an image, and convert it to grayscale.

RGB = imread('gantrycrane.png');I = im2gray(RGB);

提取边缘。

bw = edge(i,'canny');

计算在有限的角度范围内的霍夫变换。

[H,T,R] = Hough(BW,'theta',44:0.5:46);

显示霍夫变换。

图Imshow(Imadjust(recale(h)),'xdata',,,,T,'ydata',,,,R,...“初始磁化”,,,,'合身');标题(“有限的theta范围hough gantrycrane图像”);Xlabel('\theta')ylabel('\ rho');轴on,轴普通的;Colormap(GCA,热)

Figure contains an axes object. The axes object with title Limited Theta Range Hough Transform of Gantrycrane Image contains an object of type image.

输入参数

全部收缩

二进制图像,指定为2D逻辑矩阵或二维数字矩阵。For numeric input, any nonzero pixels are considered to be1((true)。

数据类型:单身的|双倍的|int8|在t16|在t32|INT64|UINT8|uint16|UINT32|Uint64|逻辑

名称值参数

Specify optional pairs of arguments asname1 = value1,...,namen = valuen, 在哪里姓名是参数名称和Value是the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example:[H,Theta,Rho] = Hough(BW,Rhoresolution = 0.5)

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:[H,Theta,Rho] = Hough(BW,“ Rhoresolution”,0.5)

Spacing of Hough transform bins along the轴,指定为0和0规范(大小(BW)), 独家的。

数据类型:双倍的

Thetavalues for the SHT, specified as a numeric vector with elements in the range [-90, 90).

Example:-90:0.5:89.5

数据类型:双倍的

输出参数

全部收缩

霍夫变换矩阵,返回为大小的数字矩阵nrho-by-ntheta。The rows and columns correspond toandThetavalues. For more information, seeAlgorithms

Angle between theX-axis and the矢量以数字矩阵返回。有关更多信息,请参阅Algorithms

数据类型:双倍的

从原点到线的距离沿垂直于线的向量,作为数字阵列返回。有关更多信息,请参阅Algorithms

数据类型:双倍的

Algorithms

The Standard Hough Transform (SHT) uses the parametric representation of a line:

rho = x*cos(theta) + y*sin(theta)

假定坐标系的原点位于左上角像素的中心。

The variable是the perpendicular distance from the origin to the line.

The variableTheta是从原点到线的垂直投影的角度,以顺时针式测量X-轴。范围Theta–90°≤θ<90°。线本身的角度是θ + 90°,也相对于阳性进行顺时针测量X-轴。

theta和rho的图形表示相对于绿色,相对于垂直投影,以黑色为绿色。

SHT是一个参数空间矩阵,其行和列对应于andThetavalues, respectively. The elements in the SHT represent accumulator cells. Initially, the value in each cell is zero. Then, for every non-background point in the image,计算每个Theta将四舍五入到SHT中最近的允许行。该累加器单元已增加。在此过程结束时,值SHT(R,C)意思是点数xy- 平面位于指定的线上theta(c)andRho(R)。Peak values in the SHT represent potential lines in the input image.

The Hough transform matrix,H,,,,是nrho-by-ntheta在哪里:

nrho = 2*(ceil(d/rhoresolution)) + 1,,,,and
d = sqrt((numrowsinbw -1)^2 +(numcolsinbw -1)^2)
值范围从-对角线diagonal, 在哪里
对角线= rhoresolution*ceil(d/rhoresolution)

ntheta =长度(theta)

扩展功能

版本历史记录

Introduced before R2006a