Pixelmath Expressions

Pkay

Member
This thread is for pixelmath expressions.
It is good to study the syntax of how the functions, operators, punctuators and symbols work.

Place the working and tested example here with an explanation of what it does.
If in your experience, you spot errors in the explanations then make comment.
Please keep chat to a minimum :)


Here is a simple example:

The iif( cond, expr_true, expr_false ) function.

I applied this to an Ha linear image to eliminate noise.

iif($T>0.0033, $T, 0)

What it does:
If any pixel is greater than a certain brightness (in this case 0.0033) it is set to $T (same value). If less, it is set to 0.
$T returns the pixel value.
 
Last edited:
Another example:
This will set all pixels to 0 outside area of interest:


iif((x()<1035) | (x()>2400) | (y()<795) | (y()>1590), 0, $T)

The | operator is a logical OR
x() and y() return the current pixel value
The numbers define the area of interest.
 
The above expression should be written:

iif( x() < 1035 || x() > 2400 || y() < 795 || y() > 1590, 0, $T )

Note that the logical OR operator is two vertical bars: ||. A single vertical bar denotes the bitwise OR operator, which is not really what you need here. Note also that the parentheses around logical expressions are superfluous here, since relational operators (==, !=, <, >, <=, >=) have higher evaluation precedence than logical operators.

The above expression is equivalent to:

iif( inrect( 1035, 795, 2400-1035+1, 1590-795+1 ), $T, 0 )

because the inrect function returns true (1) when the current pixel coordinates are interior to the specified rectangle, false (0) otherwise. Finally, this expression is equivalent to the much simpler form:

$T * inrect( 1035, 795, 2400-1035+1, 1590-795+1 )

because the logical true and false values are represented as the integers 1 and 0, respectively, which makes the use of iif unnecessary in this case.

Thank you for opening this interesting and instructive thread.
 
Example 3: Combining images.

Pre requisites:
Open 2 images say image_Ha and image_Red.
They must be registered (aligned).
It does not matter if the images are linear or non linear (for this example).

In pixelmath RGB/K tab enter the expression:

$T + image_Ha

Drag the triangle process icon onto image_Red.
You can select create 'new image' in the destination tab.

This adds the pixel values of both images.
 
Last edited:
Example 4: Combining images with scaling.

Pre requisites:
Open 2 images say image_Ha and image_Red.
They must be registered (aligned).
It does not matter if the images are linear or non linear (for this example).

In pixelmath RGB/K tab enter the expression:

$T + image_Ha*0.5

Drag the triangle process icon onto image_Red.
You can select create 'new image' in the destination tab.

This halves the pixel values of image_Ha and then adds them to image_Red.
 
Last edited:
Example 5: Introduction to Symbols tab.

Pre requisites:
Open 2 images say image_Ha and image_Red.
They must be registered (aligned).
It does not matter if the images are linear or non linear (for this example).

In pixelmath RGB/K tab enter the expression:

$T + image_Ha*Scaling_factor

In Symbols tab enter:
Scaling_factor=0.5

Drag the triangle process icon onto image_Red.
You can select create 'new image' in the destination tab.

This adds the pixel values of both images (after scaling the image_Ha).
You change the variable 'Scaling_factor' in the Symbols tab.
This will make life easier when expressions become more complicated (and they will).
 
Last edited:
Back
Top