-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBeanShell05-3.bsh
44 lines (39 loc) · 1.53 KB
/
BeanShell05-3.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* BeanShell05-3.bsh
* IJ BAR: https://github.com/tferr/Scripts#scripts
* *************************************************
* 5.3 Scripting using BAR libs III
* *************************************************
*/
// <<Enough with this silly SMA method. I need some real
// math. I want... a Gaussian fitted to all my profiles!>>
// OK! That will be easy. Here is what we have to do:
//
// 1. Create a method for the new functionality
// 2. Place it in a lib
// 3. Instruct Smoothed_Plot_Profile.bsh to use the new
// method
// STEP 1:
// I propose using the built-in CurveFitter of ImageJ1
// (but go ahead and use one of Fiji's third-party
// libraries if you prefer otherwise). Something like:
/** This method returns a gaussian fit from X,Y data */
double[] getGaussian(double[]xvalues, double[] yvalues) {
import ij.measure.CurveFitter; // http://javadoc.imagej.net/ImageJ1/index.html?ij/measure/CurveFitter.html
cf = new CurveFitter(xvalues, yvalues);
cf.doFit(CurveFitter.GAUSSIAN);
fittedValues = new double[xvalues.length];
for (i=0; i<xvalues.length; i++)
fittedValues[i] = cf.f(xvalues[i]);
return fittedValues;
}
// STEP 2:
// Now, let's create a shiny new lib. In the future, BAR
// will have a command for this, but meanwhile we'll do
// it the old fashion way:
// We will added to the existing BARlib.bsh file, right
// below the SMA method (getSimpleMovingAverage()).
// Cannot find it BARlib.bsh? Don't worry press <<Run>>
// and I'll open it for you:
import bar.Utils;
Utils.openScript(Utils.getLibDir(), "BARlib.bsh");