Интерфейс скрипта для палитры изображений Fit, представленный в GMS 2.3?

Палитра Fit Image Palette довольно приятная и мощная. Есть ли интерфейс сценария, к которому мы можем получить прямой доступ?


person KEVIVI    schedule 25.04.2015    source источник


Ответы (1)


Существует интерфейс сценария, и приведенный ниже пример сценария поможет вам начать работу. Однако скриптовый интерфейс официально не поддерживается. Поэтому он может содержать ошибки или может измениться в будущих версиях 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()
person BmyGuest    schedule 25.04.2015