Script interface for the Fit image Palette introduced in GMS 2.3? -
the fit image palette quite nice , powerful. there script interface can access directly?
there script interface, , example script below started. however, script interface not officially supported. might therefore buggy or change in future gms versions.
for gms 2.3 following script works:
// create input image: image input := newimage("formula test", 2, 100) input = 500.5 - icol*11.1 + icol*icol*0.11 // add random noise: input += (random()-0.5)*sqrt(abs(input)) // create image 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 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 = 0 (i = 0; < 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 = {") (i = 0; < 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 plot , 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()
Comments
Post a Comment