![]() |
![]()
| ![]() |
![]()
NAMEminccalc - perform complex math operations on minc files SYNOPSISmincalc [<options>] <in1>.mnc [<in2>.mnc...] <out>.mnc DESCRIPTIONMinccalc will perform complex, voxel-by-voxel math operations, on one or more minc files of the same shape and having the same coordinate sampling, producing a single output file. The operations to be performed are input using the -expression argument (see EXPRESSIONS). By default, the output file is the last non-option argument. However, if the -outfile option is used, then all non-option arguments are considered input files and the output file names come from the -outfile options, of which there can be more than one. OPTIONSNote that options can be specified in abbreviated form (as long as they are unique) and can be given anywhere on the command line.
EXPRESSIONSThe -expression argument is a single string that describes the function to evaluate. The function expression is typically written in terms of the vector A. For example, the following expression will sum the first two input files together:
Multiple expressions can be given separated by semicolons, in which case only the value of the last expression is used. These expression lists can be used with assignment expressions to make the syntax very C-like:
An expression list in curly brackets is a valid expression and returns the value of last expression in the list. This is particularly useful in for and if expressions (see below). There are two types of values in the language: vectors and scalars. Scalars literals are floating point numbers or may appear as symbols whose name starts with a lowercase letter. Besides normal scalar operators such as +, -, * and /, the expression language also supports the infix exponentiation operator ^ , the usual relational operators <, <=, >, >=, ==, != as well as the boolean operators && (and), || (or) and ! (not). Note that the && and || boolean operators always evaluate both operands, unlike C. Scalar mathematical functions include abs, sqrt, exp, log, sin, cos, tan, asin, acos and atan. There are also some specialized functions:
The scalar constant NaN is defined such that isnan(NaN) return 1. Vectors can be written in the following `extensional' form
or by using the following range-generating notations:
or be generated, by `intension'. The following intension expression generates the vector {3,2,1}:
Vectors may also appear as symbols whose name starts with an uppercase letter. In addition to the scalar operators, the following vector operators are supplied:
Symbol names are introduced into a global symbol table by assignment expressions of the form
Symbols starting with a lowercase letter represent scalars while those starting with an uppercase letter represent vectors. Since = is an operator, its result can be used in an expression (as in C). A few control constructs are provided: For loops can be created to loop over a vector, assigning each value to a symbol and then evaluating an expression. This is done with expressions of the form
which is equivalent to sum(A). Note that this is similar to using
since the for construct is actually an operator (although it is usually only used for changing symbol values). Note also that without the final "total", the expression would not be very useful since it would only return the length of the vector. As in C, a list of expressions can be specified in curlies:
There are also a few forms of the if-then-else construct:
The else is optional. Again, the if construct is an operator, and the then or else expressions can be expression lists in curlies, in which case the value of the last expression is returned. If the else expression is missing, then the value 0 is returned when the test expression is 0 (false). The principal oddity with the for and if constructs is that unlike C statements, they must be separated from the next expression by a semicolon even when an expression list in curlies is used:
An alternative way to introduce symbol names is through let-expressions. For example, the following expression will always evaluate to 3:
These were originally designed to create variables only within the evaluated expression, but modifications have been made so that the global symbol table is changed. EXAMPLESHere is an expression for calculating standard deviation, taking into account the possibility of invalid input data, which is ignored:
The last if could be changed to return 0 if s0 is > 0 but <= 1. We also drop the curly brackets, but then there must not be a ";" between the if and the else
If we want both the mean and the standard deviation, we can use the -outfile option, invoking the command with
And using the expression file (with yet another form of if expression):
CAVEATSA few things you should remember... Vector variables must start with an uppercase letter. Vector variable names must not be one of the function keywords,
For loops and if expressions always need to be separated from the next expression by a semicolon. The symbol table is global. Boolean operators && and || always evaluate both operands. A note on parallelism: For efficiency reasons, evaluations are done on many voxels at once (the number of voxels is referred to as the width of the evaluation and is changed with the -eval_width option). An odd consequence of this is that both sides of an if-else statement are always evaluated (unless all voxels give the same test result), but statements within each consequent are only evaluated on the appropriate voxels. In particular, entries in the symbol table are only modified according to a voxel mask. A side-effect of this is that any vector symbol set in an if-else consequent must not change the length of the symbol (although it can create it) and both sides of the consequent must agree on the length of any vector symbols that they both modify. If this is not clear, just try it - the program will complain if it is not happy. AUTHORAndrew Janke - a.janke@gmail.com COPYRIGHTSCopyright © 2000 by Andrew Janke SEE ALSOmincmath(1)
|