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:
- Load image and convert it to grayscale
- Detect edges - Canny, Sobel try them and find what it suits you best
- Set threshold to a given value that eliminates most background - Binarize image
- Close the image - Morphological close dont close the window!
- Count and identify objects in the image (Blobs, Watershed)
- 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
- 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:
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