Created
October 9, 2015 14:16
-
-
Save tama-sh/9bc6d49a2b4fbddf5068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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