Skip to content

Instantly share code, notes, and snippets.

@tama-sh
Created October 9, 2015 14:16
Show Gist options
  • Save tama-sh/9bc6d49a2b4fbddf5068 to your computer and use it in GitHub Desktop.
Save tama-sh/9bc6d49a2b4fbddf5068 to your computer and use it in GitHub Desktop.
def ellipse_fit(x, y):
def ellipse_err(p, x, y):
return (x-p[0])**2/p[2]**2 + (y-p[1])**2/p[3]**2 - 1
p = [0]*4
p[0] = np.mean(x)
p[1] = np.mean(y)
p[2] = np.max(np.max(x)-p[0], p[0]-np.min(x))
p[3] = np.max(np.max(y)-p[1], p[1]-np.min(y))
p_opt, success = optimize.leastsq(ellipse_err, p, args=(x,y))
return p_opt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment