General Non-Linear Least-Squares Image Fitting
If none of the built-in fitting functions meets your needs, you can build your own using the General Least-Squares tab:

As an example, let's imagine you have a series of gradient-echo images collected different flip angles and a long TR for the purposes of performing a flip-angle calibration. We might expect the signal intensity to vary as the sine of the true flip angle. Thus, you want to fit function of the form:
I=M0*sin(k*α)
where I is the measured signal intensity; M0 is the fully-relaxed signal intensity for a 90° pulse; α is the nominal flip angle and k is a spatially-dependent multiplier that converts the nominal flip angle into the actual flip angle. The objective is to map k. The function to be fitted is entered in the Fit function panel:

You can either type in the function, or you can build up the function from the Operators, Functions and Constants menus: clicking on one of the items in the menus inserts an appropriate piece of text to help build up the function. In the function, you can use:
-
Parentheses ( ).
-
Addition (+), subtraction (-), multiplication (*), division (/) and power (^) operators.
-
Built-in functions. See the
Functionsmenu for a list of built-in functions. -
User-defined constants. To define a constant, increment the number of constants using the spinner and the set the constant name and value as shown below:

You can then refer to the constant value in your formula by its name.
-
Built-in constants. See the
Constantsmenu for a list of built-in constants. -
The independent variable name ("x", by default) and the fit variable names.
If the function contains any illegal elements, you will be notified when you try to perform the fit.
The Independent Variable Name
By default, the independent variable in the fit function is "x". You can change this so that the fit function is easier to read and more physically meaningful. In our example, we are varying the flip angle, we we have changed the independent variable name to "alpha".

Optionally, you can scale all the values of the independent variable that you enter by a scaling factor. In this example we want to enter the flip angles in degrees, but the sine function requires angles to be specified in radians. To convert degrees to radians, we enter an independent variable scaling factor of 0.0174533, since 1 degree equals 0.0174533 radians.
Built-in Functions
The fitter has the following built-in functions that you can use in your fit function:
- sin(x) - gives the sine of x
- asin(x) - gives the arc sine of x
- cos(x) - gives the cosine of x
- acos(x) - gives the arc cosine of x
- tan(x) - gives the tangent of x
- atan(x) - gives the arc tangent of x
- ln(x) - gives the natural log of x
- exp(x) - gives the exponential of x
- pow(x, y) - gives x raised to the power y
- abs(x) - gives the absolute value (modulus) of x
- step(t, t0, y) - when t>t0 gives y, otherwise gives 0
- max(a, b) - gives the maximum of a and b
- min(a, b) - gives the minimum of a and b
- diff(e, x) - gives the derivative of e w.r.t. x
- rand(a, b) - gives a random number between a and b
- gauss(m, s) - gives Gaussian noise with mean m and standard deviation s
- gamma(t, t0, h, l) - a gamma probability density function equivalent to gamma(t-t0, h, l) with a shape parameter h, and a scale parameter l.
Built-in Constants
The fitter has the following built-in constants:
- pi - the ratio of the circumference of a circle to its diameter.
- e - the base of natural logarithms.
The fit variables
The fit variables are estimated on a pixel-by-pixel basis, and must appear in the fit function. You set the number of fit variables, their names and other parameters in the Fit variables panel. We have done below that for our example, which requires two fit variables:

First set the number of fit variables (in the above example, 2); this sets up the Variables panel for you to enter the details of each of the fit variables.
Then, for each of the fit variables, enter:
-
The name of the fit variable. This should be a physically-meaningful name that you used in the fit function.
-
The minimum physically-meaningful value for the fit variable. For example, if a fit variable is a time constant, such as a relaxation time, then it not physically meaningful for the fitted value to be below zero. It a fit variable falls below the minimum for any pixel, that pixel will have a value of zero in all the output images. If you do not wish to set a minimum, then leave this field blank.
-
The maximum physically-meaningful value for the fit variable. For example, if a fit variable is a time constant, such as a relaxation time, then it may not be physically meaningful for the fitted value to be above 4000 ms (the relaxation time of water). It a fit variable is above the maximum for any pixel, that pixel will have a value of zero in all the output images. If you do not wish to set a maximum, then leave this field blank.
-
The initial guess (starting value) for the fit variable. The fitting procedure is an iterative process and is quite time-consuming. The closer your initial guess is to the average fitted value, then the quicker will be the fitting procedure. Note: if you provide very poor initial guesses, or guesses that are not physically meaningful (for example, negative time constants) then the fitting may fail because the iterative procedure can become trapped in a local minimum. If you do not enter a value, the initial guess defaults to 1.0.
-
The output scaling factor. The output images created by the Image Fitter are normally of the same type as the first input image. Since medical images are normally of integer type, it is important to scale the output appropriately for representation by an integer value. For example, if the fit variable is expected to give output values between 0.0 and 1.0 then an appropriate scaling factor might be 1000, so that the intensity resolution of the output image is 1/1000th of the dynamic range. If no scaling factor were applied, then output pixels would have values of either 0 or 1, with nothing in between. If you do not enter a value, the scaling factor defaults to 1.0.
Note: You can force the Image Fitter to always produce output images of floating-point datatype if you wish. To do this, select the
check-box. This makes scaling the output images unnecessary, unless you have other reasons for doing so.