The Algebra Formula

The formula is applied to the input images on a pixel-by-pixel basis. The formula tells the Algebra tool how to combine the input images. A simple example would be to take an average of three input images. With the default variable names of the input images being I1, I2 and I3, the formula to do that would be:

(I1+I2+I3)/3

In the formula, you can use:

  • Parentheses ( ).
  • Addition (+), subtraction (-), multiplication (*), division (/) and power (^) operators.
  • Built-in functions. See the Functions menu for a list of built-in functions.
  • Built-in constants. See the Constants menu for a list of built-in constants.
  • The input image variable names (by default, these are I1, I2, I3 etc.).

You can either type in the formula, or you can build up the formula from the Operators, Functions and Constants menus: clicking on one of the items in the menus inserts an appropriate piece of text at the cursor position to help build up the formula.

You type in or modify the formula in the Formula field: this example shows the correct formula for calculating the magnetisation transfer ratio.

algebra_formula

Note that this formula has a scaling factor of 100 applied. The output image created by the Algebra tool is always of the same type as the first input image. In fact, the output image is a clone of the first input image, but with the pixel values replaced. 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 formula is expected to give output values between 0.0 and 1.0 (as some sort of normalisation operation would give), 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.

All algebraic operations are performed using double-precision arithmetic, and the output pixel intensity is rounded and truncated appropriately according to the data type of the output image. In addition, you can further restrict the dynamic range of the output by setting the limits on output pixel values.

If the formula contains any illegal elements, you will be notified when you try to apply the formula.

Built-in Functions

Algebra tool has the following built-in functions:

  • 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

Built-in Constants

Algebra tool has the following built-in constants:

  • pi - the ratio of the circumference of a circle to its diameter.
  • e - the base of natural logarithms.