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

  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

変数名

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.

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

ダイアログ

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]] [-nosum]
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. Another optional argument, -nosum tells Siril not to sum exposure times. This impacts FITS keywords such as LIVETIME and STACKCNT

関数

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

関数

Use case

定義

abs

abs ( x )

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 )

xの余弦。

cosh

cosh ( x )

xの双曲線余弦。

e

e

定数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 )

xの自然対数。

log

log ( x )

xの10を底とする対数。

log10

log10 ( x )

xの10を底とする対数。

log2

log2 ( x )

xの2を底とする対数。

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

定数π=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 )

xの正弦。

sinh

sinh ( x )

xの双曲線正弦。

sqrt

sqrt ( x )

xの平方根。

tan

tan ( x )

xの正接。

tanh

tanh ( x )

xの双曲線正接。

trunc

trunc ( x )

Truncated integer part of x.

統計関数

関数

Use case

定義

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.

演算子

演算子

演算子

Use case

定義

~

~x

Pixel Inversion operator.

-

-x

Unary Minus operator (sign change).

+

+x

Unary Plus operator.

!

!x

論理NOT演算子。

^

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

論理AND演算子。

||

x || y

論理OR演算子。