Running a Gaussian Fit in a Beanshell Script

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Running a Gaussian Fit in a Beanshell Script

Burni
Greetings,

I'm writing a little programm with Beanshell and at one point I need to fit a set of points with a Gaussian function.
Theoretically, it should look something like this:

double[] x = new double [] {0, 1, 2, 3, 4, 5};
double[] y = new double [] {0, 0.9, 4.5, 8, 18, 24};

//ij.Fit.doFit("Gaussian", x, y);
ij.IJ.run("Curve Fitting...");

With the last line, I can at least start the Curve Fitter, but I want to automatically use the the values of the arrays x and y. The command I made a comment would work in the ImageJ macro language, but I don't know how to use it in Beanshell.
Also, after the fit is done, I want to automatically extract the values of the fitting parameters (a, b, c....).
Could someone please help me with this?

Burni
Reply | Threaded
Open this post in threaded view
|

Re: Running a Gaussian Fit in a Beanshell Script

bnorthan
Hi Burni

You can access the functionality by using the CurveFitter class directly.
http://imagej.nih.gov/ij/developer/api/ij/measure/CurveFitter.html

double[] x = new double [] {0, 1, 2, 3, 4, 5};
double[] y = new double [] {0, 0.9, 4.5, 8, 18, 24};

CurveFitter fitter=new CurveFitter(x, y);

fitter.doFit(1);

double[] results=fitter.getParams();

for (double d:results)
{
    print(d);
}

Brian


On Sun, Mar 30, 2014 at 5:40 PM, Burni <[hidden email]> wrote:

> Greetings,
>
> I'm writing a little programm with Beanshell and at one point I need to fit
> a set of points with a Gaussian function.
> Theoretically, it should look something like this:
>
> double[] x = new double [] {0, 1, 2, 3, 4, 5};
> double[] y = new double [] {0, 0.9, 4.5, 8, 18, 24};
>
> //ij.Fit.doFit("Gaussian", x, y);
> ij.IJ.run("Curve Fitting...");
>
> With the last line, I can at least start the Curve Fitter, but I want to
> automatically use the the values of the arrays x and y. The command I made
> a
> comment would work in the ImageJ macro language, but I don't know how to
> use
> it in Beanshell.
> Also, after the fit is done, I want to automatically extract the values of
> the fitting parameters (a, b, c....).
> Could someone please help me with this?
>
> Burni
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Running-a-Gaussian-Fit-in-a-Beanshell-Script-tp5007134.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Running a Gaussian Fit in a Beanshell Script

Burni
Hi Brian,

thanks for your help! Is there a way to activate the plot window that would be shown when using the curve fitter in ImageJ manually? For example this:



I know the getresiduals function gives me the error values, but having the actual image of the fitted curve and the points is an easy way to get a quick impression of the quality of the fit.

Burni
Reply | Threaded
Open this post in threaded view
|

Re: Running a Gaussian Fit in a Beanshell Script

bnorthan
Hi Burni

You can access the plot function of the plugin.

http://rsb.info.nih.gov/ij/developer/source/ij/plugin/frame/Fitter.java.html

You need to pass the plot function the CurveFitter instance.  This line
should do it -

ij.plugin.frame.Fitter.plot(fitter);

//////////////////////////////////////////////////////////////////////////

double[] x = new double [] {0, 1, 2, 3, 4, 5};
double[] y = new double [] {0, 0.9, 4.5, 8, 18, 24};

CurveFitter fitter=new CurveFitter(x, y);

fitter.doFit(1);

double[] results=fitter.getParams();

for (double d:results)
{
    print(d);
}

ij.plugin.frame.Fitter.plot(fitter);


On Mon, Mar 31, 2014 at 5:31 AM, Burni <[hidden email]> wrote:

> Hi Brian,
>
> thanks for your help! Is there a way to activate the plot window that would
> be shown when using the curve fitter in ImageJ manually? For example this:
>
> <http://imagej.1557.x6.nabble.com/file/n5007142/GaussianFit.png>
>
> I know the getresiduals function gives me the error values, but having the
> actual image of the fitted curve and the points is an easy way to get a
> quick impression of the quality of the fit.
>
> Burni
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Running-a-Gaussian-Fit-in-a-Beanshell-Script-tp5007134p5007142.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Running a Gaussian Fit in a Beanshell Script

Burni
Hi Brian,

thanks again! That's exactly what I was looking for.

Burni