我正在使用名为ImageJ的免费软件分析gafchromic过滤器,该软件使用Java的简化形式编写宏。
我有一组数据点,我已经成功地连接了不同的方法,并确定三次多项式最适合该数据,但是我需要使用实际曲线,因此我需要以某种方式提取该多项式的方程式/公式。这应该是可能的,因为定义多项式的变量已在生成的图形中列出,但是我似乎找不到在代码中提取它们的方法。
到目前为止,这是我的代码:
n = nResults();
x = newArray(n);
for (i=0; i<x.length; i++)
{
x[i] = getResult("Grays ", i);
}
y = newArray(n);
for (i=0; i<y.length; i++)
{
y[i] = getResult("Mean ", i);
}
// Do all possible fits, plot them and add the plots to a stack
setBatchMode(true);
for (i = 0; i < Fit.nEquations; i++) {
Fit.doFit(i, x, y);
Fit.plot();
if (i == 0)
stack = getImageID;
else {
run("Copy");
close();
selectImage(stack);
run("Add Slice");
run("Paste");
}
Fit.getEquation(i, name, formula);
print(""); print(name+ " ["+formula+"]");
print(" R^2="+d2s(Fit.rSquared,3));
for (j=0; j<Fit.nParams; j++)
print(" p["+j+"]="+d2s(Fit.p(j),6));
}
setBatchMode(false);
run("Select None");
rename("Curve Fits");
}
如上所述,我已经在其他地方得到了答案。尽管如此,我也想将其保留在这里作为记录。基本上,答案已经包含在原始帖子中,因为它将单个变量打印到“日志”窗口中。
对于三次多项式,我可以使用:
Fit.doFit(2, x, y); // 2 is 3rd Degree Polynomial
Fit.plot();
rename("Calibrating curve");
然后可以轻松提取出:
a = Fit.p(0);
b = Fit.p(1);
c = Fit.p(2);
d = Fit.p(3);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句