Straight line Hough transform
c
The Hough transform constructs a histogram array representing the parameter
space (i.e., an M×N matrix, for M different values of
the radius and N different values of θ). For each
parameter combination, r and θ, we then find the number
of non-zero pixels in the input image that would fall close to the
corresponding line, and increment the array at position (r,θ)
appropriately.
We can think of each non-zero pixel “voting” for potential line candidates. The
local maxima in the resulting histogram indicates the parameters of the most
probable lines. In our example, the maxima occur at 45 and 135 degrees,
corresponding to the normal vector angles of each line.
Another approach is the Progressive Probabilistic Hough Transform [2]. It is
based on the assumption that using a random subset of voting points give a good
approximation to the actual result, and that lines can be extracted during the
voting process by walking along connected components. This returns the
beginning and end of each line segment, which is useful.
The function probabilistic_hough has three parameters: a general threshold
that is applied to the Hough accumulator, a minimum line length and the line
gap that influences line merging. In the example below, we find lines longer
than 10 with a gap less than 3 pixels.
,
2
,
1
,
25
)
=
(
,
threshold
=
10
,
line_length
=
5
,
line_gap
=
3
)
,
=
(
1
,
3
,
figsize
=
(
15
,
5
),
sharex
=
True
,
sharey
=
True
)
=
.
ravel
()
[
0
]
.
imshow
(
,
cmap
=
)
[
0
]
.
set_title
(
'Input image'
)
[
1
]
.
imshow
(
,
cmap
=
)
[
1
]
.
set_title
(
'Canny edges'
)
[
2
]
.
imshow
(
*
0
)
for
in
:
,
=
[
2
]
.
plot
((
[
0
],
[
0
]),
(
[
1
],
[
1
]))
[
2
]
.
set_xlim
((
0
,
[
1
]))
[
2
]
.
set_ylim
((
[
0
],
0
))
[
2
]
.
set_title
(
'Probabilistic Hough'
)
for
in
:
()
()
()
Total running time of the script: (0 minutes 2.372 seconds)