MCPcopy Index your code
hub / github.com/DeepLabCut/DeepLabCut / calc_parameters

Method calc_parameters

deeplabcut/core/trackingutils.py:224–264  ·  view source on GitHub ↗

Calculate ellipse center coordinates, semi-axes lengths, and the counterclockwise angle of rotation from the x-axis to the ellipse major axis. Visit http://mathworld.wolfram.com/Ellipse.html for how to estimate ellipse parameters. :param coeffs: list of fitt

(coeffs)

Source from the content-addressed store, hash-verified

222 @staticmethod
223 @jit(nopython=True)
224 def calc_parameters(coeffs):
225 """
226 Calculate ellipse center coordinates, semi-axes lengths, and
227 the counterclockwise angle of rotation from the x-axis to the ellipse major axis.
228 Visit http://mathworld.wolfram.com/Ellipse.html
229 for how to estimate ellipse parameters.
230
231 :param coeffs: list of fitting coefficients
232 :return: center: 1D ndarray, semi-axes: 1D ndarray, angle: float
233 """
234 # The general quadratic curve has the form:
235 # ax^2 + 2bxy + cy^2 + 2dx + 2fy + g = 0
236 a, b, c, d, f, g = coeffs
237 b *= 0.5
238 d *= 0.5
239 f *= 0.5
240
241 # Ellipse center coordinates
242 x0 = (c * d - b * f) / (b * b - a * c)
243 y0 = (a * f - b * d) / (b * b - a * c)
244
245 # Semi-axes lengths
246 num = 2 * (a * f * f + c * d * d + g * b * b - 2 * b * d * f - a * c * g)
247 den1 = (b * b - a * c) * (np.sqrt((a - c) ** 2 + 4 * b * b) - (a + c))
248 den2 = (b * b - a * c) * (-np.sqrt((a - c) ** 2 + 4 * b * b) - (a + c))
249 major = np.sqrt(num / den1)
250 minor = np.sqrt(num / den2)
251
252 # Angle to the horizontal
253 if b == 0:
254 if a < c:
255 phi = 0
256 else:
257 phi = np.pi / 2
258 else:
259 if a < c:
260 phi = np.arctan(2 * b / (a - c)) / 2
261 else:
262 phi = np.pi / 2 + np.arctan(2 * b / (a - c)) / 2
263
264 return [x0, y0, 2 * major, 2 * minor, phi]
265
266
267class EllipseTracker(BaseTracker):

Callers 1

fitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected