Extract one object from bunch of objects and detect edges

前端 未结 1 747
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 04:14

For my college project I need to identify a species of a plant from plant leaf shape by detecting edges of a leaf. (I use OpenCV 2.4.9 and C++), but the source image has tak

相关标签:
1条回答
  • 2021-01-01 05:05

    Well there is a similar question that was asked here:

    • opencv matching edge images

    It seems that edge information is not a good descriptor for the image, still if you want to try it I'll do the following steps:

    1. Load image and convert it to grayscale
    2. Detect edges - Canny, Sobel try them and find what it suits you best
    3. Set threshold to a given value that eliminates most background - Binarize image
    4. Close the image - Morphological close dont close the window!
    5. Count and identify objects in the image (Blobs, Watershed)
    6. Check each object for a shape (assuming you have described shapes of the leaf you could find before or a standard shape like an ellipse) features like:
      • http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html
      • http://www.math.uci.edu/icamp/summer/research_11/park/shape_descriptors_survey.pdf
    7. If a given object has a given shape that you described as a leaf then you detected the leaf!.

    I believe that given images are taken in the real world these algorithm will perform poorly but it's a start. Well hope it helps :).

    -- POST EDIT 06/07

    Well since you have no prior information about the leaf, I think the best we could do is the following:

    • Load image
    • Bilateral filter
    • Canny
    • Extract contours
    • Assume: that the contour with the largest perimeter is the leaf
    • Convex hull the 3 or 2 largest contours (the blue line is the convex hull done)
    • Use this convex hull to do a graph cut on the image and segmentate it

    If you do those steps, you'll end up with images like these:

    Leaf 1 segmentation

    Leaf 2 segmentation

    I won't post the code here, but you can check it out in my messy github. I hope you don't mind it was made in python.

    Leaf - Github

    Still, I have a couple of things to finish that could improve the result.. Roadmap would be:

    • Define the mask in the graphcut (like its described in the doc)
    • Apply region grow may give a better convex hull
    • Remove all edges that touch the border of the image can help to identify larger edges

    Well, again, I hope it helps

    0 讨论(0)
提交回复
热议问题