Thread Subject: 3d Gauss fitting

Subject: 3d Gauss fitting

From: Aishwarya

Date: 17 Nov, 2009 21:09:04

Message: 1 of 7

Hi ppl
I have a 100 x 100 data which is in the form of a gaussian distribution.The data has too much noise and I want to fit a 3d gaussian to the data. I have the surface fitting tool box but it says that x,y,z dimensions should be same. But my data is like x=1x100 y=1x100 and z is 100x100. Any help would be highly appreciated.

Subject: 3d Gauss fitting

From: Richard Willey

Date: 17 Nov, 2009 22:01:55

Message: 2 of 7

Try the following

[X,Y] = meshgrid(x,y)

X = X(:)
Y = Y(:)
Z = z(:)



"Aishwarya " <icemails@yahoo.co.in> wrote in message
news:hdv3dg$8in$1@fred.mathworks.com...
> Hi ppl
> I have a 100 x 100 data which is in the form of a gaussian
> distribution.The data has too much noise and I want to fit a 3d gaussian
> to the data. I have the surface fitting tool box but it says that x,y,z
> dimensions should be same. But my data is like x=1x100 y=1x100 and z is
> 100x100. Any help would be highly appreciated.

Subject: 3d Gauss fitting

From: ImageAnalyst

Date: 17 Nov, 2009 23:40:23

Message: 3 of 7

On Nov 17, 4:09 pm, "Aishwarya " <icema...@yahoo.co.in> wrote:
> Hi ppl
> I have a 100 x 100 data which is in the form of a gaussian distribution.The data has too much noise and I want to fit a 3d gaussian to the data. I have the surface fitting tool box but it says that x,y,z dimensions should be same. But my data is like x=1x100 y=1x100 and z is 100x100. Any help would be highly appreciated.

--------------------------------
How is this 3D data? You have two independent variables, x and y, and
a value - this makes it a 2D function. Repeat: a 2D function.

What is your z variable? Some kind of image? It's a 2D array of
100x100 but what is it?

Subject: 3d Gauss fitting

From: Aishwarya

Date: 18 Nov, 2009 06:48:04

Message: 4 of 7

Ya.It is a 2d function as in z is a function of x and y.

I did not get that question reg z

Subject: 3d Gauss fitting

From: ImageAnalyst

Date: 18 Nov, 2009 11:23:35

Message: 5 of 7

On Nov 18, 1:48 am, "Aishwarya " <icema...@yahoo.co.in> wrote:
> Ya.It is a 2d function as in z is a function of x and y.
>
> I did not get that question reg z

--------------------------------------------------
Maybe there's a built in function but you can do it the regular,
normal manual way where
xMean = sum(x *z) / sum(z)
yMean = sum(y * z) / sum(z)
and the standard deviations are the usual formulas
xStd = sqrt( mean(x^2 - xMean))
etc.
Of course you have to scan every pixel in the array to calculate these
values.

Subject: 3d Gauss fitting

From: Aishwarya

Date: 19 Nov, 2009 06:34:07

Message: 6 of 7

Hi,
I tried the following code in MATLAB 2009b :
clc;
clear all;
[X,Y] = meshgrid(1:100,1:100);
% x=1:1:100;
% y=1:1:100;
x=X(:);
y=Y(:);
xdata = {x,y};
fid = fopen('S3D6.bin','r+');
A = fread(fid,'double');
size(A);
%figure,imagesc(A)
fid = fopen('D6S3.bin','r+');
B = fread(fid,'double');
size(B);
%figure,imagesc(B)
C=A.*B;
size(C);
D= reshape(C,100,100,100);
D1=D(:,:,10);
D2=D1(:);
fun = @(c,xdata) c(1)*exp(-((c(2)*(xdata{1}-30)^2)+(2*c(3)*(xdata{1}-30)*(xdata{2}-40))+(c(4)*(xdata{2}-40)^2)));
c_start=[30 50 30 50];
options=optimset('TolFun',1e-12,'TolX',1e-12,'MaxFunEvals',40000,'MaxIter',50000);
     t = lsqcurvefit(fun,c_start,xdata,D1,options);
% [INLP,ILP] = fminspleas(funlist,NLPstart,xdata,D1)
mesh(D1);
op= t(1)*exp(-((t(2)*(xdata{1}-30)^2)+(2*t(3)*(xdata{1}-30)*(xdata{2}-40))+(t(4)*(xdata{2}-40)^2)));
figure,mesh(op);


and im getting the error as: lsqcurvefit accepts input of type double when i include options.
When I dont include options it takes the initial params as the fitting params since the tolerance is 1e-6 and my data is e-20 range.

Any idea???

Subject: 3d Gauss fitting

From: Steven Lord

Date: 19 Nov, 2009 14:53:28

Message: 7 of 7


"Aishwarya " <icemails@yahoo.co.in> wrote in message
news:he2osv$a73$1@fred.mathworks.com...
> Hi,
> I tried the following code in MATLAB 2009b :

*snip*

> t = lsqcurvefit(fun,c_start,xdata,D1,options);

*snip*

> and im getting the error as: lsqcurvefit accepts input of type double when
> i include options.
> When I dont include options it takes the initial params as the fitting
> params since the tolerance is 1e-6 and my data is e-20 range.
>
> Any idea???

Yes -- you're calling LSQCURVEFIT incorrectly. If you don't want to specify
some of the inputs, you can't just leave them out. Use empty matrices for
the bound inputs instead of omitting them. Reread HELP LSQCURVEFIT for a
description of the correct calling syntax.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com