fitting a 2d gaussian using lsqcurvefit

12 visualizaciones (últimos 30 días)
Sohrab Salimian
Sohrab Salimian el 30 de En. de 2020
Below is the code i am using to fit a 2d gaussian to an image (40 *40), however whenever i run this my results a dont look quite right and b the lsqcurvefit keeps stopping prematurely any help is seriously appreciated.
ydata = y(:);
size(ydata)
[n, m] = size(y);
[X,Y]=meshgrid(1:n,1:m);
x = zeros(n*m, 2);
x(:, 1)= X(:);
x(:, 2)=Y(:);
c0 = [1, 20, 40];
options=optimset('TolX',1e-6);
fun = @(c, x) (1/(sqrt(2*pi*c(1)^2)))*exp(-((c(2)-x(:, 1)).^2 + (c(3) - x(:, 2)).^2)/2*(c(1)));
cc = lsqcurvefit(fun, c0, x, ydata, [], [], options);
Ifit = fun(cc, x);

Respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by