GMS 2.3 中引入的适合图像调色板的脚本接口?

Script interface for the Fit image Palette introduced in GMS 2.3?

Fit Image Palette 非常好用而且功能强大。有没有我们可以直接访问的脚本接口?

有一个脚本界面,下面的示例脚本将帮助您入门。但是,官方不支持脚本接口。因此,它可能存在错误或可能会在未来的 GMS 版本中发生变化。

对于 GMS 2.3,以下脚本有效:

// create the input image:
Image input := NewImage("formula test", 2, 100)
input = 500.5 - icol*11.1 + icol*icol*0.11

// add some random noise:
input += (random()-0.5)*sqrt(abs(input))

// create image with error data (not required)
Image errors := input.ImageClone()
errors = tert(input > 1, sqrt(input), 1)

// setup fit:
Image pars := NewImage("pars", 2, 3)
Image parsToFit := NewImage("pars to fit", 2, 3)
pars = 10;          // starting values
parsToFit = 1;
Number chiSqr = 1e6
Number conv_cond = 0.00001

Result("\n starting pars = {")
Number xSize = pars.ImageGetDimensionSize(0)
Number i = 0
for (i = 0; i < xSize; i++)
{
    Result(GetPixel(pars, i, 0))
    if (i < (xSize-1)) Result(", ")
}
Result("}")

// fit:
String formulaStr = "p0 + p1*x + p2*x**2"
Number ok = FitFormula(formulaStr, input, errors, pars, parsToFit, chiSqr, conv_cond)

Result("\n results  pars = {")
for (i = 0; i < xSize; i++)
{
    Result(GetPixel(pars, i, 0))
    if (i < (xSize-1)) Result(", ")
}
Result("}")
Result(", chiSqr ="+ chiSqr)

// plot results of fit:
Image plot := PlotFormula(formulaStr, input, pars)

// compare the plot and original data:
Image compare := NewImage("Compare Fit", 2, 100, 3)
compare[icol, 0] = input        // original data
compare[icol, 1] = plot         // fit function
compare[icol, 2] = input - plot // residuals

ImageDocument linePlotDoc = CreateImageDocument("Test Fitting")
ImageDisplay linePlotDsp = linePlotDoc.ImageDocumentAddImageDisplay(compare, 3)
linePlotDoc.ImageDocumentShow()