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.

диалог

Pixel Math dialog box as shown at opening

The window is divided into 5 parts.

  1. 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.

  2. 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.

  3. The third, the parameters field, allows the user to define parameters that are separated by ,. For example, if you set parameters with the expression factor=0.8, K=0.2, all the occurences of factor and K in the formula above will be replaced by 0.8 and 0.2 respectively. Ha * factor + OIII * K would therefore evaluate to Ha * 0.8 + OIII * 0.2.

    диалог

    Pixel Math parameters box

  4. The output field is reserved for scaling the image within a given range. One need to expand the frame before using it.

    диалог

    Pixel Math rescale box

  5. 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.

    диалог

    Pixel Math presets

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.

диалог

It is possible to change the name of the variable.

Examples

Let's take a monochrome image of galaxies This is a linear data seen through the autostretch view.

диалог

Original image.

The following expression:

iif(Image>med(Image)+3*noise(Image), 1, 0)

will produce a star mask.

диалог

After the formula above.

Командная строка Siril

pm "expression" [-rescale [low] [high]]
This command evaluates the expression given in argument as in PixelMath tool. The full expression must be between double quotes and variables (that are image names, without extension, located in the working directory in that case) must be surrounded by the token $, e.g. "$image1$ * 0.5 + $image2$ * 0.5". A maximum of 10 images can be used in the expression.
Image can be rescaled with the option -rescale followed by low and high values in the range [0, 1]. If no low and high values are provided, default values are set to 0 and 1

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).

Pixel oriented functions

Function

Use case

Definition

abs

abs ( x )

Absolute value of x.

acos

acos ( x )

Арккосинус x.

acosh

acosh ( x )

Гиперболический арксинус x.

asin

asin ( x )

Арксинус x.

asinh

asinh ( x )

Гиперболический арксинус x.

atan

atan ( x )

Арктангенс x.

atan2

atan2 ( y, x )

Арктангенс y/x.

atanh

atanh ( x )

Гиперболический арктангенс x.

ceil

ceil ( x )

Round x upwards to the nearest integer.

cos

cos ( x )

Cosine of x.

cosh

cosh ( x )

Гиперболический косинус x.

e

e

The constant e=2.718282...

exp

exp ( x )

Показательная функция.

fac

fac( x )

Факториал.

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 )

Наибольшее целое значение меньшее или равное x.

ln

ln ( x )

Натуральный логарифм 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 )

Функция максимума.

min

min ( x, y )

Функция максимума.

mtf

mtf ( m, x )

Передаточная функция полутонов (MTF) x для параметра баланса полутонов m в диапазоне [0, 1].

ncr

ncr ( x, y )

Функция сочетаний.

npr

npr ( x, y )

Функция перестановок.

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 )

Гиперболический синус x.

sqrt

sqrt ( x )

Square root of x.

tan

tan ( x )

Tangent of x.

tanh

tanh ( x )

Гиперболический тангенс x.

trunc

trunc ( x )

Усечённая целая часть x.

Statistics functions

Function

Use case

Definition

adev

adev ( Image )

Среднее абсолютное отклонение изображения.

bwmv

bwmv ( 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 )

Максимальное значение пикселей изображения.

mean

mean ( Image )

Mean of the image.

med

med ( Image )

Median of the image. The use of median is also possible.

min

min ( Image )

Минимальное значение пикселей изображения.

noise

noise ( Image )

Оценка Гауссова шума изображения.

sdev

sdev ( Image )

Standard deviation of the image.

width

width ( Image )

Width in pixels of the specified image.

Operators

Operators

Оператор

Use case

Definition

~

~x

Оператор инверсии пикселя.

-

-x

Унарный оператор минус (смена знака).

+

+x

Унарный оператор плюс.

!

!x

Logical NOT operator.

^

x ^ y

Exponentiation operator.

*

x * y

Multiplication operator.

/

x / y

Division operator.

%

x % y

Оператор модуля.

+

x + y

Addition operator.

-

x - y

Subtraction operator.

<

x < y

Оператор сравнения МЕНЬШЕ.

<=

x <= y

Less Than Or Equal relational operator.

>

x > y

Оператор сравнения БОЛЬШЕ.

>=

x >= y

Greater Than Or Equal relational operator.

==

x == y

Оператор сравнения РАВЕН.

!=

x != y

Not Equal To relational operator.

&&

x && y

Логический оператор И.

||

x || y

Logical OR operator.