0

I have an binary image as shown below.

enter image description here

As can be seen in the image there is an edge which looks like an arc of an ellipse, as illustrated below and I manually marked it as red. These red pixels should be found by the code.

enter image description here

My goal is to fit an ellipse to the pixels that are colored in red in the above picture. This fitted ellipse is shown in below.

enter image description here

Could someone kindly tell me how I can get the pixels that are marked as red in the second image using MATLAB? I will then use them for an elliptical fitting.

afp_2008
  • 1,940
  • 1
  • 19
  • 46

1 Answers1

4

The problem you are describing is extremely non-trivial. This article describes some of the existing methods. It is nice because it is a survey that will point you to other articles.

As you may have guessed, not having both ends of the ellipse to work with makes things infinitely more complex. If that were not the case, you could use the Hough transform. There is already a script available on the mathworks site do do this.

All that being said, I recommend Googling "ellipse detection". It may not help directly with the MATLAB implementation, but will at least give you an idea of the magnitude of the problem you are trying to solve.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • 2
    +1 for using Hough. But I would start by computing the skeleton, plus a small pruning. It will make the result more stable. – FiReTiTi Sep 16 '15 at 09:24
  • @Mad Physicist: The MATLAB script that you kindly put its link worked just fine. I played with `params.minMajorAxis` and `params.maxMajorAxis` based on my image, and it was able to detect the ellipse. The trick is to add the flipped version of my image to the original image to provide more information to the code. `c = imread('myellipseimage.jpg');`, `c2 = [c;flipud(c)];`. This way it keeps the symmetry of the ellipse about the horizontal axis. Awesome help. Thanks so much. – afp_2008 Sep 17 '15 at 01:04
  • 2
    No problem. Took me literally 45 seconds of Googling to write this answer. – Mad Physicist Sep 17 '15 at 06:33