MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / _fit

Method _fit

deeplabcut/core/trackingutils.py:177–201  ·  view source on GitHub ↗

Least Squares ellipse fitting algorithm Fit an ellipse to a set of X- and Y-coordinates. See Halir and Flusser, 1998 for implementation details. :param x: ndarray, 1D trajectory :param y: ndarray, 1D trajectory :return: 1D ndarray of 6 coefficients of the general qua

(x, y)

Source from the content-addressed store, hash-verified

175 @staticmethod
176 @jit(nopython=True)
177 def _fit(x, y):
178 """Least Squares ellipse fitting algorithm Fit an ellipse to a set of X- and
179 Y-coordinates. See Halir and Flusser, 1998 for implementation details.
180
181 :param x: ndarray, 1D trajectory
182 :param y: ndarray, 1D trajectory
183 :return: 1D ndarray of 6 coefficients of the general quadratic curve: ax^2 +
184 2bxy + cy^2 + 2dx + 2fy + g = 0
185 """
186 D1 = np.vstack((x * x, x * y, y * y))
187 D2 = np.vstack((x, y, np.ones_like(x)))
188 S1 = D1 @ D1.T
189 S2 = D1 @ D2.T
190 S3 = D2 @ D2.T
191 T = -np.linalg.inv(S3) @ S2.T
192 temp = S1 + S2 @ T
193 M = np.zeros_like(temp)
194 M[0] = temp[2] * 0.5
195 M[1] = -temp[1]
196 M[2] = temp[0] * 0.5
197 E, V = np.linalg.eig(M)
198 cond = 4 * V[0] * V[2] - V[1] ** 2
199 a1 = V[:, cond > 0][:, 0]
200 a2 = T @ a1
201 return np.hstack((a1, a2))
202
203 @staticmethod
204 @jit(nopython=True)

Callers 1

fitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected