def _fit_ellipse(self, arr):
        narr = normalize(arr)
        bounds = [(10, 30), (10, 30), (3, 30), (3, 30), (.5, 3.5), (0, 360)]

        def fun(x):
            e = ellipse(20, 20, *x[2:]).ravel().astype(np.float)
            norm = np.sqrt((e ** 2).sum())
            e = ellipse(*x).ravel().astype(np.float) / norm
            return np.dot(narr, e) * (-1)

        x0 = self.best_match(narr)
        result = minimize(fun, x0, bounds=bounds, approx_grad=True)
        return result[0], fun(result[0])
dataset/ETHPy150Open ChrisBeaumont/brut/bubbly/extractors.py/EllipseExtractor._fit_ellipse/original