This plugin generates images from mathematical functions and primitive patterns in all ImageJ image types. It can be used to generate synthetic test-cards to analyze for example the behavior of filter-operations or to test the functionality of various algorithms in image-processing. The tool can also be used in a teaching environment, where example images for presentations can be prepared or even to demonstrate basic principles of digital image processing (e.g. by showing the relation between function values and the generated images). Further on an artistic use to create images stacks or videos is also imaginable.
The function value of a two- or three-dimensional function f(x, y) or f(x, y, z) is interpreted as the intensity value of the image. Use the following variables, constants and functions.
| x, y, z | Coordinate variables. |
| w, h, s | Range of axes or width, height and slices of the predefined coordinate system variables. |
| v | Instensity value for 8-bit, 16-bit and 32-bit input |
| r, g, b | Instensity values for RGB input (red, green, blue values) |
| d | Distance of the point of origin |
| a | Angle to the point of origin. |
| random | Random number within [0, 1] |
| PI | The constant π (3.14159265), the ratio of the circumference to the diameter of a circle. |
| E | The exponential number e (2.718) |
| sin(n) | The sine of n (in radians) |
| asin(n) | The inverse sine of n (in radians) |
| cos(n) | The cosine of n (in radians) |
| acos(n) | The inverse cosine of n (in radians) |
| tan(n) | The tangent of n (in radians) |
| atan(n) | Calculates the inverse tangent (arctangent) of n. Returns a value in the range -PI/2 through PI/2. |
| atan2(x,y) | Calculates the inverse tangent of y/x and returns an angle in the range -PI to PI, using the signs of the arguments to determine the quadrant. Multiply the result by 180/PI to convert to degrees. |
| pow(base, exponent) | The value of base raised to the power of exponent. |
| sqrt(n) | The square root of n. Returns NaN if n is less than zero. |
| log(n) | The natural logarithm (base e) of n. Note that log10(n) = log(n)/log(10). |
| maxOf(n1, n2) | The greater of two values. |
| minOf(n1, n2) | The smaller of two values. |
| exp(n) | The exponential number e (i.e., 2.718...) raised to the power of n. |
| abs(n) | The absolute value or modulus |x| |
| floor(n) | Returns the largest value that is not greater than n. |
| round(n) | Returns the closest integer to n. |
| getPixel(x, y) | Returns the value of the pixel at (x,y). Note that pixels in RGB images contain red, green and blue components that need to be extracted using shifting and masking. See the Color Picker Tool macro for an example that shows how to do this. |
You can also use other bulit in ImageJ Macro Functions.
Generate primitive patterns using boolean expressions with ImageJ macro code. The conditional will be executed for each pixel in the image inside the given coordinate range.
The given commands will be interpreted as an if-statements like the following
[variables]
if ([condition]) {
[then_statement]
}
else {
[else_statement]
}
The ImageJ macro language is mostly "typeless". Variables do not need to be declared and do not have explicit data types. Variable names are case-sensitive. "Name" and "name" are different variables.
Assign local variables simply like my_variable = 1.23; and use them later, e.g. for a boolean expression, like x * y >= my_variable
A condition must be a boolean expression with logic operators like AND (conjunctions), OR (disjunctions) or NOT (negations). See the basic behavior of boolean algebra in the following truth tables:
| x | y | x AND y | x OR y |
|---|---|---|---|
| false | false | false | false |
| true | false | false | true |
| false | true | false | true |
| true | true | true | true |
| x | NOT x |
|---|---|
| false | true |
| true | false |
The ImageJ macro language supports almost all of the standard Java operators but with fewer precedence levels.
| Operator | Precedence | Description |
|---|---|---|
| ++ | 1 | pre or post incerement |
| -- | 1 | pre or post decrement |
| - | 1 | unary minus |
| ! | 1 | boolean complement |
| ~ | 1 | bitwise complement |
| * | 2 | multiplication |
| / | 2 | division |
| % | 2 | euclidean division / modulo operation |
| & | 2 | bitwise AND |
| | | 2 | bitwise OR |
| ^ | 2 | bitwise XOR |
| <<, >> | 2 | bitwise left shift, right shift |
| + | 3 | addition or string concatenation |
| -- | 3 | subtraction |
| <, <= | 4 | less than, less than or equal |
| >, >= | 4 | greater than, greater than or equal |
| ==, != | 4 | equal, not equal |
| && | 5 | boolean AND |
| || | 5 | boolean OR |
| = | 6 | assignment |
| *=, -=, *=, /= | 6 | assignment with operation |
For more details see ImageJ Macro Language Programmer’s Reference Guide.