fitting a 2d gaussian using lsqcurvefit
12 views (last 30 days)
Show older comments
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);
0 Comments
Answers (0)
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!