Dekryptor / aforge

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

HoughLineTransform/CollectLines can return near-duplicate lines #144

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
After running the following code fragment (referenced input image attached)
HoughLineTransformation hlt = new HoughLineTransformation();
hlt.StepsPerDegree = 10;
hlt.MinLineIntensity = 20;
hlt.ProcessImage(new Bitmap("image.bmp"));
var lines = hlt.GetMostIntensiveLines(5);

lines[2] is {Intensity = 205, Radius = 15, Theta = 145.3} and lines[3] is 
{Intensity = 205, Radius = 15, Theta = 145.4}. The desired result is that 
something related to that one line appears in lines[2], and that lines[4] 
appears in lines[3].

This is obviously caused by the > at HoughLineTransform.cs:699, but changing it 
to >= will delete the line entirely, which is not at all the desired effect.

A proposed patch is attached. There is at least one major issue in there, 
marked by a TODO. My local copy now has the throw replaced by:
minLineIntensity = (short)(group[0].Intensity + 1);
for ( int i = lines.Count - 1; i >= 0; i-- )
    if ( ( (HoughLine)lines[i] ).Intensity < minLineIntensity )
        lines.RemoveAt( i );
But this has its own potential issues: If the user actually wants the low 
intensity lines, or if there are high intensity lines that can't be joined, 
desirable information may be discarded. I have not seen this, though. On the 
other hand, I've haven't tested on any huge variety of images.

The throw and/or the replacement code can be triggered by removing 
"hlt.MinLineIntensity = 20;" from the demonstrating code fragment.

This issue may also apply to HoughCircleTransform. The code looks suspicious, 
but I do not have images or sufficient understanding to feel comfortable 
changing that.

Original issue reported on code.google.com by dales...@gmail.com on 17 Aug 2010 at 5:30

Attachments:

GoogleCodeExporter commented 8 years ago
Unfortunately, I just found a bug in DuplicateLines.patch.

I did not test the situation where a line with negative radius at 179.9 degrees 
needs to join one with positive radius at 0, and that fails miserably. Here's a 
new one.

Also, I removed the throw in this version, and replaced it with the above 
minLineIntensity-changing code.

Original comment by dales...@gmail.com on 17 Aug 2010 at 10:43

Attachments:

GoogleCodeExporter commented 8 years ago
I found another issue here: If I use the same HoughLineTransformation multiple 
times, the always-increasing MinLineIntensity property can cause unexpected 
results, necessitating a reset before every call to ProcessImage.

This patch, which replaces the above, solves that issue by adding a new 
ResultMinLineIntensity that is set during processing. It also makes this line 
filtering optional.

I left the documentation warning in. There has to be a way to reference all 
overloads, but I couldn't find it.

Original comment by dales...@gmail.com on 11 Jan 2011 at 4:50

Attachments: