This is a library to detect ellipses within an image.
File imageFile = new File("image.png");
BufferedImage bufferedImage = ImageIO.read(imageFile);
CannyEdgeDetector cannyEdgeDetector = new CannyEdgeDetector();
// any parameters you want, these are the defaults from the ellipse reference implementation
cannyEdgeDetector.setAutoThreshold(true);
cannyEdgeDetector.setGaussianKernelRadius(1);
cannyEdgeDetector.setGaussianKernelWidth(5);
cannyEdgeDetector.setSourceImage(bufferedImage);
cannyEdgeDetector.process();
BufferedImage edgeImage = cannyEdgeDetector.getEdgeImage();
EllipseDetector ellipseDetector = new EllipseDetector();
ellipseDetector.setEdgeImage(edgeImage);
ellipseDetector.process();
BufferedImage ellipseImage = ellipseDetector.createFinalEllipseImage();
List<Ellipse> ellipseList = ellipseDetector.getFinalEllipseList();
- Play with the 4 parameters of the Canny edge detector and make sure the ellipse edge is visible here.
- Parameters for the ellipse detection:
minimumArcPixelCount
= remove small ellipses / noise.minimumBoundingBoxSize
= remove straight linesdistanceToEllipseContour
,distanceToEllipseContourScoreCutoff
,reliabilityCutoff
= remove poorly fitting ellipses and ellipse noise
- If things aren't working, check out the example for details how to output intermediate debug images
- Auto-threshold for the Canny edge detector is not fast and linear with the size of the image. Setting low/high threshold is much faster. Also, auto-threshold still has some parameters. Check out the code if it is not working
- Finding straight lines only uses 5 points, but this can be turned off to use all points (but slower)
[1] A fast and effective ellipse detector for embedded vision applications
Michele Fornaciari, Andrea Prati, Rita Cucchiara
http://ieeexplore.ieee.org/document/6470150/
https://sourceforge.net/projects/yaed/
http://www.tomgibara.com/computer-vision/CannyEdgeDetector.java
[2] A Fast Ellipse Detector Using Projective Invariant Pruning
Qi Jia, Xin Fan, Member, IEEE, Zhongxuan Luo, Lianbo Song, and Tie Qiu
http://ieeexplore.ieee.org/document/7929406/
- The canny edge detector is not ported from the reference ellipse implementation. An unrelated implementation was found instead. However, the automatic high/low threshold option was taken from the ellipse implementation and added to this one.
- The paper detects straight lines was done using an oriented bounding box and checking its width. Instead, an axis-oriented bounding box was used and points were checked for distance from the diagonal.
- In the reference implementation, finding parallel chords across two arcs was done by picking one point, then binary searching for a matching point with the closest slope. In this implementation, after the binary search narrowed down to two points, a matching point was interpolated to get the exact slope.
This is released into the public domain with no restrictions or guarantees. This project is not associated with the original authors of any of the papers in any way.
This is intended for single threaded use only.