Pixel Math
One of the most powerful tools in Siril is the Pixel Math. It allows you to manipulate the pixels of the images using mathematical functions. From simple addition or subtraction, to more advanced functions, like MTF, Pixel Math is a perfect tool for astronomical image processing.
This page aims to describe the tool entirely, to see detailed examples, please refer to the excellent tutorial on the site.
The window is divided into 5 parts.
The first one, including 3 text zones receiving the mathematical formulas. Only the first one is used if you want to produce a monochrome image. Uncheck the Use single RGB/K expression button to produce RGB output.
The second is the variables area with the selection of Functions and Operators. Each variable is an image that must be loaded beforehand with the + button. You can click on the desired function and/or operator to make it appear in the formula entry to make it appear in the formula entry.
The third, the parameters field, allows the user to define parameters that are separated by
,
. For example, if you set parameters with the expressionfactor=0.8, K=0.2
, all the occurences offactor
andK
in the formula above will be replaced by 0.8 and 0.2 respectively.Ha * factor + OIII * K
would therefore evaluate toHa * 0.8 + OIII * 0.2
.The output field is reserved for scaling the image within a given range and to enable or not the Sum exposure time. This last option gives the user the option of summing or not the exposures of individual images, storing the result in the FITS header. One need to expand the frame before using it.
Pixel Math rescale box
Finally, the presets area allows the user to reuse previously saved formulas with the button to the right of the formula areas. One need to expand the frame before using it. Double-click on the formula to copy it to the right entry.
Usage
Name of variables
By default it is possible to load 10 images simultaneously. Each image is given
a variable name starting with I followed by a number from 1 to 10. However, if
the loaded image contains the keyword FILTER
, then the value of the latter
becomes the default variable name. Of course it is always possible to change it
by double clicking on it.
$T
is a reference to the current image, meaning the image on which the
PixelMath operations will be applied.
Tip
It is possible to use the currently loaded image by using the $T
token.
Note, however, that unlike other programs, the expression $T[i]
, with
i=0,1,2
, is not recognized.
Examples
Let's take a monochrome image of galaxies This is a linear data seen through the autostretch view.
The following expression:
iif(Image>med(Image)+3*noise(Image), 1, 0)
will produce a star mask.
Siril command line
pm "expression" [-rescale [low] [high]] [-nosum]
Functions
There are two types of functions. Those that apply directly to the pixels and those that apply to the entire image (such as the statistics functions).
Function |
Use case |
Definition |
---|---|---|
abs |
abs ( x ) |
Absolute value of x. |
acos |
acos ( x ) |
Arc cosine of x. |
acosh |
acosh ( x ) |
Hyperbolic arc cosine of x. |
asin |
asin ( x ) |
Arc sine of x. |
asinh |
asinh ( x ) |
Hyperbolic arc sine of x. |
atan |
atan ( x ) |
Arc tangent of x. |
atan2 |
atan2 ( y, x ) |
Arc tangent of y/x. |
atanh |
atanh ( x ) |
Hyperbolic arc tangent of x. |
ceil |
ceil ( x ) |
Round x upwards to the nearest integer. |
cos |
cos ( x ) |
Cosine of x. |
cosh |
cosh ( x ) |
Hyperbolic cosine of x. |
e |
e |
The constant e=2.718282... |
exp |
exp ( x ) |
Exponential function. |
fac |
fac( x ) |
Factorial function. |
iif |
iif( cond, expr_true, expr_false ) |
Conditional function (or inline if function).
Returns expr_true if cond evaluates to nonzero.
Returns expr_false if cond evaluates to zero.
|
floor |
floor ( x ) |
Highest integer less than or equal to x. |
ln |
ln ( x ) |
Natural logarithm of x. |
log |
log ( x ) |
Base-10 logarithm of x. |
log10 |
log10 ( x ) |
Base-10 logarithm of x. |
log2 |
log2 ( x ) |
Base-2 logarithm of x. |
max |
max ( x, y ) |
Maximum function. |
min |
min ( x, y ) |
Minimum function. |
mtf |
mtf ( m, x ) |
Midtones Transfer Function (MTF) of x for a midtones balance parameter m in the [0, 1] range. |
ncr |
ncr ( x, y ) |
Combinations function. |
npr |
npr ( x, y ) |
Permutations function. |
pi |
pi |
The constant π=3.141592... |
pow |
pow ( x, y ) |
Exponentiation function. |
sign |
sign ( x ) |
Sign of x:
\(+1\) if \(x > 0\)
\(−1\) if \(x < 0\)
\(\;0\) if \(x = 0\).
|
sin |
sin ( x ) |
Sine of x. |
sinh |
sinh ( x ) |
Hyperbolic sine of x. |
sqrt |
sqrt ( x ) |
Square root of x. |
tan |
tan ( x ) |
Tangent of x. |
tanh |
tanh ( x ) |
Hyperbolic tangent of x. |
trunc |
trunc ( x ) |
Truncated integer part of x. |
Function |
Use case |
Definition |
---|---|---|
adev |
adev ( Image ) |
Average absolute deviation of the image. |
bwmv |
bwmv ( Image ) |
Biweight midvariance of the image. |
height |
height ( Image ) |
Height in pixels of the specified image. |
mad |
mad ( Image ) |
Median absolute deviation of the image. The use of mdev is also possible. |
max |
max ( Image ) |
Pixel maximum of the image. |
mean |
mean ( Image ) |
Mean of the image. |
med |
med ( Image ) |
Median of the image. The use of median is also possible. |
min |
min ( Image ) |
Pixel minimum of the image. |
noise |
noise ( Image ) |
Estimation of Gaussian noise in the image. |
sdev |
sdev ( Image ) |
Standard deviation of the image. |
width |
width ( Image ) |
Width in pixels of the specified image. |
Operators
Operator |
Use case |
Definition |
---|---|---|
~ |
~x |
Pixel Inversion operator. |
- |
-x |
Unary Minus operator (sign change). |
+ |
+x |
Unary Plus operator. |
! |
!x |
Logical NOT operator. |
^ |
x ^ y |
Exponentiation operator. |
* |
x * y |
Multiplication operator. |
/ |
x / y |
Division operator. |
% |
x % y |
Modulus operator. |
+ |
x + y |
Addition operator. |
- |
x - y |
Subtraction operator. |
< |
x < y |
Less Than relational operator. |
<= |
x <= y |
Less Than Or Equal relational operator. |
> |
x > y |
Greater Than relational operator. |
>= |
x >= y |
Greater Than Or Equal relational operator. |
== |
x == y |
Equal To relational operator. |
!= |
x != y |
Not Equal To relational operator. |
&& |
x && y |
Logical AND operator. |
|| |
x || y |
Logical OR operator. |