Script

The Script uses Lua 5.1 in order to read or modify header keys of the I/O. E.g. The dimension of an image stack can be read into a Variable by the Script and used as a factor in a different logic like BoxManipulation.

To add or modify header values with the Script it is necessary to connect the I/O of the logic to the Flow Control element Script. By double clicking on the graphic element Script a new window opens. This is the editor to write the Lua script. After clicking OK the window closes. The advantage of the editor is that it shows the Lua syntax highlighting. Another possibility to edit the script is in the properties window.

To access an image in the I/O

cow.io[number of the image in the I/O]

Example
The following line reads the 100-th image in the current I/O.

cow.io[100]

To read a header key of the I/O

cow.io[number of the image in the I/O] ["image header value name"]

Example
The following line reads the Euler angle β of the 0-th image in the current I/O.

cow.io[0]["eulerBeta"] 

To read a header key of the I/O and write it to a Variable

cow.VariableName = cow.io[number of the image in the IO]["image header values name"] 

Example
The following line reads the dimension in X of the 100-th image in the current I/O to the Variable dimension, which is of type integer.

cow.dimension = cow.io[100]["dimX"] 

To overwrite the header value in the I/O

temporary variable name                             = cow.io[number of the image in the IO]
temporary variable name["image header values name"] = new value
cow.io[number of the image in the IO]               = temporary variable name 

Example
The following lines reads the 0-th image of the current I/O to temp. In the second line the header value dimX of the temporary variable temp is set to 100. The last line of code passes the temporary variable back to the 0-th position of the I/O.

temp         = cow.io[0]
temp["dimX"] = 100
cow.io[0]    = temp  

The following lines manipulate the header value dimX of the 100-th image in the I/O. The header dimX is set to the Variable of type Sting with value dimension. The header key is not of type Integer anymore.

temp         = cow.io[100]
temp["dimX"] = cow.dimension
cow.io[100]  = temp  

To write new header values to the I/O

temporary variable name                                = cow.io[number of the image in the IO]
temporary variable name["new image header value name"] = new value
cow.io[number of the image in the IO]                  = temporary variable name 

Example
The following lines write a new header key named linearFactor to the header of the 0-th image in the I/O. The header linearFactor is set to a Variable of type String with value factor.

temp                 = cow.io[0]
temp["linearFactor"] = cow.factor
cow.io[0]            = temp 

Manipulate the whole I/O
If each image in the I/O is supposed to be manipulated by its header value, the Script needs to be extended by the Flow Control elements Queue, Calculate and an additional iteration Variable.

cow.VariableName = cow.io[cow.IterationVariableName]["image header values name"]

Example
The following line reads the header key dimX of the i-th image in the I/O and passes it to the Variable dimension. In order to iterate though the whole I/O it is necessary to set up a Variable named e.g. iter of type integer, which is incremented at the end of the script.

cow.dimension = cow.io[cow.iter]["dimX"]
cow.iter      = cow.iter + 1  

Properties Window

In the properties window the Script lines is shown. Here the dimension in X is read from the header key “dimX” and passed to the Variable dimension.
The Variable of type decimal is called dim. The default value is zero.
The value of the Variable dim after executing the Script can be checked by clocking into the work space of a Group.

Properties Window

Here a new header key is added to the image in the I/O. The first position in the current I/O is read to the temporary variable temp. To add a new header key and value we just call temp of the preferred new key and set is to a any value. There is no need to define it before hand. In addition it is possible to use a Variable as a value for the header key as explained in To write new header values to the I/O.
After running the Script it is possible to open the Viewer and check if the header key war written to the I/O. On the left side is a screenshot showing the new header key and value as well as the preexisting header key pixel size. All header keys are alphabetically ordered.

Properties Window

The scirpt writes to the current position in the I/O the iteration variable value as header value to the header key “imageNumber”.
The Variable of type integer is called iter. The default value is zero.
The element Calculate iterates through the I/O. It is linked with the output of the Script and the input of the Queue. After each execution of the Script the calculation element takes the Variable iter and adds one to it.
The value of the Variable iter after executing the Script can be checked by clocking into the work space of a Group.
Input Description
FirstInput Input to be modified by the script
Output Description
FirstOutput Output with either un- or modified header values

The Script elements works withLua 5.1 Reference Manual. In the following link all Lua functions are listed at the end of the page.