The Hough process accumulates counts for every white pixel for every possible orientation (for angles from 0 to 179 in 1 deg increments) and distance from the center of the image to the corner (in 1 px increments) and stores the counts in an accumulator matrix of angle vs distance. The size of the accumulator will be 180x(diagonal/2). It then searches this space for peaks in counts and converts the locations of the peaks to slope and intercept in the normal x,y input image space. The slope/intercepts are used to find the endpoints clipped to the bounds of the image. The lines are then drawn. The counts are a measure of the length of the lines
Given a binary edge image, the syntax is as follows
Code: Select all
convert binary_edge_image -background somecolor1 -fill somecolor2 -hough-lines WxH+threshold hough_lines_image
One may extract a text file of just the line endpoints and counts by using the .mvg suffix on the output file.
Code: Select all
convert binary_edge_image -hough-lines WxH+count hough_lines_image.mvg
Here are some examples.
Code: Select all
convert rectangle.png \
\( +clone -canny 0x1+10%+30% -write rectangle_canny.png \
-background none -fill red -stroke red -strokewidth 2 \
-hough-lines 9x9+40 -write rectangle_lines.png \) -composite rectangle_hough.png
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/rectangle.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/rectangle_canny.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/rectangle_lines.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/rectangle_hough.png)
Code: Select all
convert rectangle.png -canny 0x1+10%+30% -hough-lines 9x9+40 rectangle_lines.mvg
Code: Select all
cat rectangle_lines.mvg
# Hough line transform: 9x9+40
viewbox 0 0 276 276
line 158.785,0 -0.564065,276 # 48
line 0,29.4581 276,188.807 # 99
line 0,87.1932 276,246.542 # 97
line 274.255,0 114.906,276 # 48
Code: Select all
convert rectangle.png -canny 0x1+10%+30% -hough-lines 9x9+40 MVG:-
Code: Select all
convert rectangle.png -canny 0x1+10%+30% -fill white -stroke white \
-define hough-lines:accumulator=true -hough-lines 9x9+40 \
-delete 0 -contrast-stretch 0.1% rectangle_accumulator.png
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/rectangle_accumulator.png)
Code: Select all
convert blocks.gif -median 3 \
\( +clone -canny 0x1+10%+25% -write blocks_canny.png \
-background none -fill red -stroke red -strokewidth 2 \
-hough-lines 9x9+30 -write blocks_lines.png \) -composite blocks_hough.png
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/blocks.gif)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/blocks_canny.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/blocks_lines.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/blocks_hough.png)
Code: Select all
convert fence.png \
\( +clone -canny 0x1+10%+40% -write fence_canny.png \
-background none -fill red -stroke red -strokewidth 2 \
-hough-lines 9x9+150 -write fence_lines.png \) -composite fence_hough.png
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/fence.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/fence_canny.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/fence_lines.png)
![Image](http://www.fmwconcepts.com/misc_tests/hough_tests/fence_hough.png)