hibyegh / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Comments for Hough line transform #109

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There are some uncertain things about Hough line transform. It would be nice if 
they 
were obvious from documentation.
1. Coordinate system: left/right, translation of origin (in comparison with 
GDI+ 
coordinate system), axes direction.
2. Degrees or radians are used to measure theta.
3. Range of theta variation.
4. Range of rho variation.
5. Actual meaning of absolute/relative intensity.
6. Formula of converting linear equation from normal form to slope-intercept 
form 
and vice versa.

Original issue reported on code.google.com by Qbi...@gmail.com on 24 Aug 2009 at 3:15

GoogleCodeExporter commented 9 years ago
I've just started working with the Hough line transform and can answer some of 
the 
questions for AForge 2.0.0

1. Coordinate system: left/right, translation of origin (in comparison with 
GDI+ 
coordinate system), axes direction.
ANSWER: Coordinate system is polar centered on the image and 0 degrees is 
directly 
right. GDI+, or at least the Image class, is cartesian, in pixels, with 0,0 at 
the 
top left and increasing down and right (I think).

2. Degrees or radians are used to measure theta.
ANSWER: Degrees are used to measure theta.

3. Range of theta variation.
ANSWER: I've seen negative Radius and at least 0-180 Theta. I don't know if 
those 
are the limits or just what I've seen.

4. Range of rho variation.
ANSWER: I don't know what rho is. HoughLine uses Theta in degrees and Radius in 
pixels.

5. Actual meaning of absolute/relative intensity.
ANSWER: Relative intensity appears to be measured 0-1.0
I *think* what happens is if you GetLinesByRelativeIntensity with 0.0 you get 
all 
the lines and 1.0 you get none (maybe one line?). I'm not sure if it's average 
or 
median, so it's unclear if 0.5 would get you half the lines.

6. Formula of converting linear equation from normal form to slope-intercept 
form 
and vice versa.
ANSWER: I thought slope-intercept is "normal form". Do you mean converting 
from "polar form"?

You can read some of the pointed-to documents to learn about Hough Transform. 
Essentially, the HoughLine Theta and Radius--again, measured from the image 
center--
describe a vector (line) that is perpendicular to the found line and whose 
endpoint 
is on the possibly-extrapolated found line. Because of the nature of the 
HoughLine, 
it is entirely possible that this point lies off the image.

As explained by the author in one of the forums, the line described by 
HoughLine 
does not indicate the endpoints of the line at all, it only indicates the slope 
and 
position.

Converting from HoughLine to found line in GDI+ coordinates can be thought of 
in 
multiple steps.
First convert Theta, Radius to a point in "regular" cartesian coords.
   ("regular" in this context means 0,0 at center, positive numbers up and right).
Slope of found line is (Theta + 90) degrees.
Transpose and flip the point and slope to match GDI+ coordinate system.

Further, to draw the line on the image, you'll need to find two points outside 
(or 
on the edge) of the image that are on the found line, to then use GDI+ DrawLine.

// Example code in C#
            // Radius and Theta are polar coordinates.
            float x, y;
            // calculate from polar coords Radius (from center) and Theta
            // using geometry: 
            //   sine(theta) = (y / radius);
            //   cosine(theta) = (x/ radius);
            y = (float)Math.Sin(hLine.Theta / 180.0 * (Math.PI)) * hLine.Radius;
            x = (float)Math.Cos(hLine.Theta / 180.0 * (Math.PI)) * hLine.Radius;

            // Get slope of line, note Math.Tan expects radians, so convert from 
degrees. 
            // Also, Theta (slope of vector) is perpendicular to the found line so 
add 90 degrees to get the found line slope.
            float m = (float)Math.Tan((Math.PI / 180.0) * (hLine.Theta + 90.0));// 
0=>0; 45=>1;90=>inf;135=>-1;180=>0;; tan(theta+90)=y/x
            float b = y - m * x;

            // found line is now described as a slope of m and y-intercept of b
            // Note that the image center is at 0,0 and positive numbers exending up 
and right.
            // to use with GDI+, you'll need to convert to 0,0 = top-left positive 
down and right.

This code and comments are original, mine, and hereby placed in the public 
domain.

Original comment by ecomput...@gmail.com on 28 Aug 2009 at 2:20

GoogleCodeExporter commented 9 years ago
It seems my issue to be somewhat misunderstood. Anyway, thanks a lot for your 
comment!

In fact a do know answers for my questions (otherwise i'd have posted them to 
the forum, not issue tracker). I just suggested developers to 
clarify this questions in 1) documentation, 2) comments in source code, 
3) hints in Visual Studio (this things apparently are 
interrelated).

>I don't know what rho is. HoughLine uses Theta in degrees and Radius in 
pixels.

I meant radius saying “rho”. It should be clear from documentation that
ρ ∈ (−∞, +∞)
θ ∈ [0°, 180°)
and not
ρ ∈ (−∞, +∞)
θ ∈ [−90°, 90°)
and not
ρ ∈ [0, +∞)
θ ∈ [0°, 360°)

>>6. Formula of converting linear equation from normal form to slope-intercept 
form 
and vice versa.

I mean this formula:
y(x) = (−cos θ∕sin θ)·x + ρ∕sin θ
Just let it be in <remarks> section of C# comments.

>I thought slope-intercept is "normal form". Do you mean converting 
from "polar form"?

I'm using terms from this article: http://en.wikipedia.org/wiki/Linear_equation

>You can read some of the pointed-to documents to learn about Hough Transform.

Yes, I've already read Gonzalez—Woods book.

>// Example code in C#

It would be nice to see such examples in source code comments.

Original comment by Qbi...@gmail.com on 28 Aug 2009 at 7:51

GoogleCodeExporter commented 9 years ago
Excellent feedback! Hopefully the author will include your clarifications and 
my 
comments and code to the source and documentation.

My apologies for me not knowing the terminology. Thanks for the link.

Good point on the "forums" vs. "issues". I'll try to find this on the forums if 
we're to continue this discussion. The reason I'm being wordy is that it seems 
like 
it might be helpful to get to final comment wording suggestions so they might 
be 
dropped in as appropriate rather than have to be created by the core dev team.

p.s. this is an awesome library of tools!

Original comment by ecomput...@gmail.com on 28 Aug 2009 at 5:26

GoogleCodeExporter commented 9 years ago
i liked very much your explanation but when you say :
found line is now described as a slope of m and y-intercept of b
can  you be more clear how to draw that line in GDI ?
tHanks

Original comment by jweiz...@gmail.com on 9 Sep 2009 at 1:42

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 19 Sep 2009 at 12:10

GoogleCodeExporter commented 9 years ago
Updated documentation to HoughLineTransformation and HoughLine clarifying 
different 
aspects of Hough Line transformation. Provided sample code to highlight 
detected 
lines. Provided sample image with annotation to clarify meaning of Theta and 
Radius 
values of detected Hough lines.

Committed in revision 1069. Will be released in 2.0.1 version.

Original comment by andrew.k...@gmail.com on 19 Sep 2009 at 2:33

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 19 Sep 2009 at 7:12