Hamed
Hamed

Reputation: 199

Finding the angle of stripeline/ Angle of rotation

So I’m trying to find the rotational angle for stripe lines in images like the attached photo. The only assumption is that the lines are parallel, and their orientation is about 90 degrees approximately more or less [say 5 degrees tolerance]. I have to make sure the stripe lines in the result image will be %100 vertical. The quality of the images varies as well as their histogram/greyscale values. So methods based on non-adaptive thresholding already failed for my cases [I’m not interested in thresholding based methods if I cannot make it adaptive]. Also, there are some random black clusters on top of the stripe lines sometimes.

What I did so far: 1) Of course HoughLines is the first option, but I couldn’t make it work for all my images, I had some partial success though following this great article: http://felix.abecassis.me/2011/09/opencv-detect-skew-angle/. The main reason of failure to my understanding was that, I needed to fine tune the parameters for different images. Parameters such as Canny/BW/Morphological edge detection (If needed) | parameters for minLinelength/maxLineGap/etc. For sure there’s a way to hack into this and make it work, but, to me this is a fragile solution!

2) What I’m working on right now, is to divide the image to a top slice and a bottom slice, then find the peaks and valleys of each slice. Then basically find the angle using the width of the image and translation of peaks. I’m currently working on finding which peak of the top slice belongs to which of the bottom slice, since there will be some false positive peaks in my computation due to existence of black/white clusters on top of the strip lines.

Example: Location of peaks for slices: Top Slice = { 1, 33,67,90,110} BottomSlice = { 3, 14, 35,63,90,104}

I am actually getting similar vectors when extracting peaks. So as can be seen, the length of vector might vary, any idea how can I get a group like:

{{1,3},{33,35},{67,63},{90,90},{110,104}}

I’m open to any idea about improving any of these algorithms or a completely new approach. If needed, I can upload more images.

enter image description here

Upvotes: 1

Views: 665

Answers (2)

Boyko Perfanov
Boyko Perfanov

Reputation: 3047

You can run an accumulator of spatial derivatives along different angles. If you want a half-degree precision and a sample of 5 lines, you have a maximum 10*5*1500 = 7.5m iterations. You can safely reduce the sampling rate along the line tenfold, which will give you a sample size of 150 points per sample, reducing the number of iterations to less than a million. Somewhere around that point the operation of straightening the image ought to become the bottleneck.

Upvotes: 0

Mark Ransom
Mark Ransom

Reputation: 308528

If you can get a list of points for a single line, a linear regression will give you a formula for the straight line that best fits the points. A simple trig operation will convert the line formula to an angle.

You can probably use some line thinning operation to turn the stripes into a list of points.

Upvotes: 1

Related Questions