expr

Description

Expression evaluator. The node box will show the text of the expression. The "run" button must be clicked (or ctrl+enter) to set the node to the new expression and perform it. The input can accept any type of data and the output type is determined when the node is run.

The four inputs are assigned to the variables a, b, c, and d. They are typically (but not necessarily) images or numeric values. If an input is not connected it has the "none" value.

The standard operators +,/,*,- and ^ all have their usual meanings. When applied to images they work in a pixel-wise fashion, so if a is an image, 2*a will double the brightness. If b is also an image, a+b will add the two images, pixel by pixel. There are two non-standard operators: . for properties and $ for band extraction. These are described below.

Image/numeric operators:

operator description precedence (higher binds tighter)
A + B add A to B (can act on ROIs) 10
A - B subtract A from B (can act on ROIs and Image and ROI (see "making a hole" below) 10
A / B divide A by B (can act on ROIs) 20
A * B multiply A by B (can act on ROIs) 20
A ^ B exponentiate A to the power B (can act on ROIs) 30
-A element-wise negation of A (can act on ROIs) 70
A.B property B of entity A (e.g. a.h is height of image a) 80
A$546 extract single band image of wavelength 546 (number is >=20 so treated as a wavelength) 100
A$2 extract single band image from band index 2 (number is <20 so treated as a band index) 100
A$_2 extract single band image from band index 2 (legacy notation, same as A$2) 100
A$RED extract single band image from filter named RED 100
A&B element-wise minimum of A and B (Zadeh's AND operator) 20
A|B element-wise maximum of A and B (Zadeh's OR operator) 20
!A element-wise 1-A (Zadeh's NOT operator) 80
A < B returns 1 if A is less than B (pixel-wise test if one argument is an image) 60
A > B returns 1 if A is greater than B (pixel-wise test if one argument is an image) 60

All operators can act on images, 1D vectors and scalars with the exception of . and $ which have images on the left-hand side and identifiers or integers on the right-hand side.

Comparisons involving strict equality checks (equal, greater-or-equal, less-or-equal) have deliberately been omitted; rounding errors could cause problems.

Those operators marked with (can act on ROIs) can also act on pairs of ROIs (regions of interest, see below).

Binary operations on image pairs

These act by performing the binary operation on the two underlying Numpy arrays. This means you may need to be careful about the ordering of the bands in the two images, because they will simply be operated on in the order they appear.

For example, consider adding two images $a$ and $b$ with the same bands in a slightly different order:

image a image b result of addition
480nm 480nm sum of 480nm bands
500nm 500nm sum of 500nm bands
610nm 670nm a's 610nm band plus b's 670nm band
670nm 610nm copy of previous band (addition being commutative)

This probably isn't what you wanted. Note that this is obviously not an issue when an operation is being performed on bands in a single image.

Binary operators on images with regions of interest

If one of the two images has an ROI, the operation is only performed on that ROI; the remaining area of output is taken from the image without an ROI. If both images have an ROI an error will result - it is likely that this is a mistake on the user's part, and doing something more "intelligent" might conceal this. The desired result can be achieved using expr nodes on ROIs and an importroi node.

Making a "hole" with ROIs

Sometimes you may need to operate on part of an image which is NOT covered by an ROI - for example, you might want to omit the calibration target. To do this, you can subtract an ROI from the image. For example, if you have an image on input "a" and an ROI on input "b" and your expression is "a-b", the result will be the image "a" with an ROI covering all pixels NOT inside the ROI "b".

For more complex operations you can use the .all property, which is an ROI covering the entire image.

Boolean values (true or false)

Some functions and operators work on boolean values, such as

  • The | (or), & (and) and ! (not) operators
  • The comparison operators < and > which produce boolean output
  • The ifelse function

In PCOT, booleans are just numbers - any value greater than or equal to 0.5 is considered true.

Operations with vectors

Some functions can generate vectors, such as mean for getting the means of the bands, and vec for generating vectors by hand.

If an image is used in a binary operation with a vector on the other side, the vector must have the same number of elements as there are bands in the image. The operation will be performed on each band. Consider a 3-band image and the vector [2,3,4]. If we multiply them, the result will an image with the first band multiplied by 2, the second band multiplied by 3, and the third band multiplied by 4.

Operators on ROIs themselves (as opposed to images with ROIs)

operator description
a+b union
a*b intersection
a-b difference

You can source ROIs from the "roi" output of ROI nodes, and impose resulting ROIs on images with "importroi" node.

Band extraction

The notation $name or $number takes an image on the left-hand side and extracts a single band, generating a new monochrome image.

The right-hand side is either a filter name, a filter position, a wavelength or a band index. A number less than 20 is treated as a band index, while 20 or greater is treated as a wavelength (real wavelengths are always much greater than 20nm). A band index N can also be written $_N - this older notation is retained for compatibility.

Depending on the camera, all these could be valid:

expression meaning
a$780 the 780nm band in image a
a$2 band 2 in the image a
(a+b)$G0 the band named G0 in the image formed by adding images a and b
((a+b)/2)$780 the average of the 780nm bands of images a and b

Be aware of caveats in the "binary operations on image pairs" section above: it may be better to extract the band before performing the operation, thus:

old expression better expression
(a+b)$G0 a$G0 + b$G0
((a+b)/2)$780 (a$780+b$780)/2

It's possible to extract multiple bands from an image using the square bracket notation (see below). For example, a[640,550] will generate a single image from the 640nm and 550nm bands of the input. As noted above, numbers less than 20 are assumed to be band indices, so a[5,6] will make a single image out of bands 5 and 6.

Names of filters can also be used, or RGB names for images loaded by the RGB input: a[R,G] selects just the red and green channels from an RGB image.

Brackets

Round brackets are used to group expressions as usual, but square brackets are used for indexing into a vector. For example, a[3] will extract the fourth element of the vector a. Square brackets can also create a vector, so [1,2,3] will create a vector.

Band extraction can be performed by giving a list of values (either numbers or identifiers) to an image in square brackets:

expression meaning
a[640,540] create an image from the 640nm and 540nm bands of input a
a[R,G] create an 2-band image from the R,G bands of input a (an RGB image)
a[R,R,R] create an RGB image consisting of only the red band of input a

Band extraction can also be performed with vectors provided the vector elements are numeric (i.e. wavelengths): a $ [640,550,440] is valid, but it's better to use the form a[640,550,440].

Extracting data from tables (e.g. spectra)

It's possible to use brackets to extract data from tables. In a spectrum, for example, the rows are labelled by ROI and the columns by wavelength (prefixed by 'm' for mean, 's' for standard deviation). We can extract a particular datum from such a table by using a[row,column], e.g. a[patchA, m440] would get the mean of the 440nm band for the roi "patchA". If two column names are given, a numeric value made up of mean and standard deviation are extracted, e.g. a[patchA, m440, s440].

Properties

Properties are indicated by the . operator, e.g. a.w to find an image's width.

Help on functions and properties

A list of functions can be obtained by right-clicking on either the log pane or function entry pane and selecting "List all functions." Help on an individual function can be found by hovering over the name of a function, right-clicking and selecting "Get help on 'somefunction'". Similar actions are supported for properties.

Uncertainties are assumed to be independent in all binary operations

While uncertainty is propagated through operations (as population standard deviation) all quantities are assumed to be independent (calculating covariances is beyond the scope of this system). Be very careful here. For example, the uncertainty for the expression tan(a) will be calculated correctly, but if you try to use sin(a)/cos(a) the uncertainty will be incorrect because the nominator and denominator are not independent.


Connections

Inputs

Index Name Type Desc
0 a any (none)
1 b any (none)
2 c any (none)
3 d any (none)

Outputs

Index Name Type Desc
0 (none) none (none)

Parameters

exprexpr: string (default '')Expression to evaluate

Automatically generated by generate_autodocs.py

Date: 2026-09-16T16:31:48.206090