I have been using the Canny edge detection function in OpenCV to detect the edge of an elliptic annulus (light object, dark background). In theory there should be two edges. However, it sometimes does not all edges on the outer ring.

Canny edges

So if I radially plot my detected points it looks like this (x: angle, y: radius from center of mass)

Rad v. angle

There is a wavy line which is the outer border of my object and a few outliers which are the inner border (you can tell because they look like they are systematically offset). I don't know the exact breadth of the annulus.

Q: Is there any way to programmatically get rid of these "obvious" outliers so that the exact outer contour is interpolated?


1 Answer 1


Please see my answer to this question: Detecting and isolating part of an image

You can use circular shortest path to do this quite elegantly. You are using OpenCV and and not MATLAB so some modification of my code is required.

  • $\begingroup$ Quick question before I implement: Is this also capable of handling the gap in the upper left by filling the missing values? $\endgroup$
    – ChrisF
    Commented Jul 23, 2015 at 8:03
  • $\begingroup$ Yes, it will always make a continuous line from the left of the polar image to the right. For two lines you will need two starting positions for the back tracking. I think in the code I just pick the max because I only needed one. There are a few circular shortest path papers out there that help explain it more. I did basically the same thing segmenting a distorted and gappy projection of a circle. $\endgroup$ Commented Jul 23, 2015 at 8:07
  • $\begingroup$ I finally managed to implement it, and I have to say it works awesomely! $\endgroup$
    – ChrisF
    Commented Jul 27, 2015 at 13:57
  • $\begingroup$ @ChrisF Good to hear :D $\endgroup$ Commented Jul 28, 2015 at 11:13
  • $\begingroup$ There is one thing in the code I don't understand though: in linearShortestPath.m, you have "Add energy from difference from optimum" t = t+cv, where cv is a vector with the current value of the investigated pixel and its neighbors. All algorithms I have found only add the current value of the investigated pixel. Why should the neighboring values affect the investigated pixels choice of a predecessor? $\endgroup$
    – ChrisF
    Commented Jul 30, 2015 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.