From 46eaef925f60d6681cca8b2a8017415c7c6f172d Mon Sep 17 00:00:00 2001 From: Jean-Yves TINEVEZ <jean-yves.tinevez@pasteur.fr> Date: Sat, 4 Jul 2020 22:40:35 +0200 Subject: [PATCH] Also center points before fitting the 2D ellipse. --- src/fit_ellipse_2d.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/fit_ellipse_2d.m b/src/fit_ellipse_2d.m index 26575d6..c994b89 100644 --- a/src/fit_ellipse_2d.m +++ b/src/fit_ellipse_2d.m @@ -4,6 +4,9 @@ function [ f, Q ] = fit_ellipse_2d( p, method ) if nargin < 2 method = 'direct'; end + + c = mean( p ); + p = p - repmat( c, size( p, 1 ), 1 ); switch( lower( method ) ) @@ -14,6 +17,8 @@ function [ f, Q ] = fit_ellipse_2d( p, method ) end f = quadratic_to_cartesian2( Q ); + f( 1 ) = f( 1 ) + c( 1 ); + f( 2 ) = f( 2 ) + c( 2 ); %% Subfunctions -- GitLab