0

Given an Image How can I find that there is some curve or a straight line in image. HoughLine transform can be used to find a straight line but I want to find if there is some curve in an image or not.

Following is a rough technique in matlab to detect curve in binary image mentioned at https://www.mathworks.com/matlabcentral/answers/127190-how-can-i-detect-whether-a-line-is-a-straight-line-or-curve-from-an-binary-image but I want to code it in python.

1- call regionprops to get area and pixeled_list

2- use pythagorean theorm to get distance between two farthest points.

3- Comapre that to area which is then length along the curve.

4- divide on some ratio that divides straight fro curvy.

Binary Image

Roshni Amber
  • 552
  • 5
  • 19
  • 4. sounds a bit hopeful to me. I think a threshold can at best only differentiate between *"direct/straight-ish"* and *"indirect/meandering"* rather than *"straight"* and *"curvy"*. – Mark Setchell Sep 08 '18 at 08:26
  • I think you need to find contours in the image, check this docs.opencv.org/3.0.0/d4/d73/tutorial_py_contours_begin.html . You can then check whether all points in contour are collinear? If yes then line is a straight line otherwise it is a curve – user8190410 Sep 08 '18 at 09:15
  • Check [this](https://stackoverflow.com/a/37027329/5008845) – Miki Sep 08 '18 at 13:25
  • The area is the number of pixels, and doesn’t equate the length of a line. A straight line a 0 degrees will have `sqrt(2)` more pixels than a line of the same length at 45 degrees. – Cris Luengo Sep 08 '18 at 13:46
  • @user8190410 is there any python library to check if these contour points are collinear. – Roshni Amber Sep 09 '18 at 16:51
  • @CrisLuengo can you please elaborate it a bit ? – Roshni Amber Sep 09 '18 at 16:55
  • Imagine a 2-pixel line. If the two are next to each other, Pythagoras says the distance is 1. If they are diagonally adjacent, Pythagoras says their distance is sqrt(2). The area is 2 in both cases. – Cris Luengo Sep 09 '18 at 17:09
  • see these links https://stackoverflow.com/questions/3813681/checking-to-see-if-3-points-are-on-the-same-line https://stackoverflow.com/questions/1211212/how-to-calculate-an-angle-from-three-points – user8190410 Sep 09 '18 at 17:18
  • take three points and find angle between them if angle is 180 or 0 then points are collinear, do this for all three adjacent points – user8190410 Sep 09 '18 at 17:20

0 Answers0