Error function (erf) fitting in macro

Hi there. So as of late, ImageJ’s Curve Fitter tool includes the error function as:

y = a+b*erf((x-c)/d)

The fit runs fine when called as

Fit.doFit("Error Function", values, counts);

but since I’m doing a reconvolution of a biexponential curve by a Gaussian, I need to fit to an equation with two terms that are both multiplied by an error function. The macro however does not recognize the “erf” substring as an operator in a function when it’s entered in an equation.

I tried simply executing a macro code that called the same equation as the default “Error Function” option:

Fit.doFit("y=a+b*erf((x-c)/d)", values, counts);

and, again, it doesn’t recognize the “erf” operator.

Any suggestion as to why this keeps happening and/or how to avoid it? I tried using numerical approximations to the error function, but those led to an extremely cumbersome equation that was prone to give very… inaccurate fits.

Thanks in advance.

Update: After upgrading FIJI’s ImageJ jar, the following happens:

In the “Curve Fitter” plugin, any fit using the operator “Math.erf()” gets recognized and plotted.

In a macro, neither “erf” nor “Math.erf” get recognized.

Is there a way for me to command the Curve Fitter to open, paste my data as text in two columns and order it to perform a custom fit?

EDIT: It would seem that the problem is based on some case-insensitive conversion. When I call the fit with an equation string containing “Math.erf” as an operator, I get an error message saying that “math.erf” is not recognized. When I input the same string (capital M) in the curve fitter custom settings, it works.

Is there any way for me to avoid this conversion? Or make the Curve Fitter case-insensitive?

Bump again. I came up with a temporary solution where the macro generates an equation (some terms depend on the data) which I manually paste into the Curve Fitter together with the data displayed in arrays.

Works fine for single fits, but it will be clunky if I decide to automate things for batch processing.

What version of ImageJ are you using? Math.erf() was added in Image 1.52v.

I updated to 1.53c. While Math.erf(x) is now recognized in macro if I call it directly (I can, for example, call


I cannot include it in a fitting equation and use Fit.doFit();

The reason seems to be that somewhere along the line the equation string from the macro gets converted to lower-case and thus “Math.erf(xyz)” gets converted to “math.erf(xyz)”, which then is not recognized and is reported as an “Invalid custom function: <math.erf>(xyz)”.

As I said above, the issue does not occur when I manually enter a custom equation through the Curve Fitter, so the issue must be with passing the command to the Curve Fitter tool.

This bug is fixed in the ImageJ 1.53d34 daily build. This macro reproduces the problem:

  xpoints= newArray(0,1,2,3,4,5);
  ypoints = newArray(0,0.9,4.5,8,18,24);  


Thanks a whole lot! Problem solved.