How to detect curves in a binary image?

后端 未结 5 1900
囚心锁ツ
囚心锁ツ 2021-02-05 11:39

I have a binary image, i want to detect/trace curves in that image. I don\'t know any thing (coordinates, angle etc). Can any one guide me how should i start? suppose i have thi

5条回答
  •  借酒劲吻你
    2021-02-05 11:57

    Since you already seem to have a good binary image, it might be easiest to just separate the different connected components of the image and then calculate their parameters.

    First, you can do the separation by scanning through the image, and when you encounter a black pixel you can apply a standard flood-fill algorithm to find out all the pixels in your shape. If you have matlab image toolbox, you can find use bwconncomp and bwselect procedures for this. If your shapes are not fully connected, you might apply a morphological closing operation to your image to connect the shapes.

    After you have segmented out the different shapes, you can filter out the curves by testing how much they deviate from a line. You can do this simply by picking up the endpoints of the curve, and calculating how far the other points are from the line defined by the endpoints. If this value exceeds some maximum, you have a curve instead of a line.

    Another approach would be to measure the ratio of the distance of the endpoints and length of the object. This ratio would be near 1 for lines and larger for curves and wiggly shapes.

    If your images have angles, which you wish to separate from curves, you might inspect the directional gradient of your curves. Segment the shape, pick set of equidistant points from it and for each point, calculate the angle to the previous point and to the next point. If the difference of the angle is too high, you do not have a smooth curve, but some angled shape.

    Possible difficulties in implementation include thick lines, which you can solve by skeleton transformation. For matlab implementation of skeleton and finding curve endpoints, see matlab image processing toolkit documentation

提交回复
热议问题