From 68fd0602616f8c24e8895e74d9b3d77077492b0e Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Wed, 19 Sep 2012 23:35:55 -0400 Subject: use of more general fit image function --- fit_image.m | 11 +++++++++++ fitgaussian2D.m | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 fit_image.m diff --git a/fit_image.m b/fit_image.m new file mode 100644 index 0000000..e682e4d --- /dev/null +++ b/fit_image.m @@ -0,0 +1,11 @@ +function fit_params=fit_image(f,init_params,X,Y,img, pLowBound, pUpperBound, options) + +%options = optimset('lsqnonlin'); +%options.Display = 'iter'; +%options.TolFun = tolerance; + +fit_params = lsqnonlin( ... + @(p) Gaussian2D(p,X,Y) - img, ... + init_params,pLowBound,pUpperBound,options ... + ); + diff --git a/fitgaussian2D.m b/fitgaussian2D.m index 817cb77..c3a7051 100644 --- a/fitgaussian2D.m +++ b/fitgaussian2D.m @@ -78,7 +78,7 @@ initpar = [cx,cy,sx,sy,PeakOD,theta,background]; %this is to avoid errors when doing fits on the image full of zeros if isnan(sum(sum(Gaussian2D(initpar,X,Y)-m))) < 1 % Here is the actual fit - fp = lsqnonlin( @(pt) Gaussian2D(pt,X,Y)-m,initpar,LB,UB,options); + fp = fit_image(@Gaussian2D, initpar, X, Y, m, LB, UB, options); else fp = [0,0,0,0,0,0,0]; end; -- cgit v1.2.3