From f87ee565c1c4157b880c729d04b1d21d1f6dcc2f Mon Sep 17 00:00:00 2001 From: Olzhas Zhumabek Date: Wed, 18 May 2022 02:03:36 +0600 Subject: [PATCH] In depth explanation for Hough line Added in depth explanation for Hough line transform in the associated markdown file --- example/histogram_equalization.md | 46 +++++++++++++++++++++++++++++++ example/hough_transform_line.cpp | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/example/histogram_equalization.md b/example/histogram_equalization.md index c3dcd57832..eb71568dac 100644 --- a/example/histogram_equalization.md +++ b/example/histogram_equalization.md @@ -7,6 +7,52 @@ Histogram equalization capabilities in GIL are demonstrated by the program `hist The program doesn't take any argument on the command line. +Hough line transform solves the equation of a line in reverse, but in *polar coordinates*! The implementation will make each pixel vote on all possible lines it could be part of, limited by input Hough parameters. + +A line in polar coordinates is represented by normal to it in polar coordinates, as shown in example here +https://docs.opencv.org/3.4/d9/db0/tutorial_hough_lines.html + +Since real line is the diagonal throughout the image, the angle of normal to it will 45 degrees. (1s represent real line, 5s represent normal to it). + +``` +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 +0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 +0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 +0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 +0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 +0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 +0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 +5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +``` + +It is obvious that the angle for the expected Hough transform is 45 degrees (angle between 5s and bottom 0s). Now we +need to find the length of 5s. Since 5s, 1s and bottom 0s form a right triangle, we know that bottom 0s are 32 in length +and is a hypotenuse! Using trivial trigonometry we know that the length we are searching for is 32 * cos(45). + `histogram_equalization` expects to find an image called `test_adaptive.png` in the current directory, and produces an image in return, where the equalization have been applied: `histogram_gray_equalized.png`. ## Specific requirements diff --git a/example/hough_transform_line.cpp b/example/hough_transform_line.cpp index 0d9a14f943..d67fff5b59 100644 --- a/example/hough_transform_line.cpp +++ b/example/hough_transform_line.cpp @@ -25,7 +25,7 @@ namespace gil = boost::gil; int main() { - std::ptrdiff_t size = 32; + const std::ptrdiff_t size = 32; gil::gray16_image_t input_image(size, size); auto input_view = gil::view(input_image);