Open akaihola opened 3 years ago
The Hough Transform finds lines quite beautifully and quickly.
You can try by first turning an image into full black and white (but still RGB) using ImageMagick:
convert -threshold 90% original.png -type TrueColor -define png:color-type=2 black-and-white.png
Then run my branch of rust-hough-transform
on the image:
cargo run --release black-and-white.png space.png line.png 1 1 1200
(replace the value 1200 of houghspace_filter_threshold
with something like 80–90% of the max accumulator value
as shown in terminal output from the command)
You can now inspect line.png
for the strongest lines detected, and space.png
for the raw accumulator output from the Hough Transform.
With 1° resolution, this takes about a second on my laptop for a 1200x1600 image.
So based on lines detected by the Hough Transform, we could easily correct the rotation of a document based on the angles of strongest lines.
But we could also do a very basic "perspective correction", e.g. to straighten a bent book page:
Resources: