Next: Mathematical morphology operators, Previous: Dimensionality changing operators, Up: Arithmetic operators [Contents][Index]

Conditional operators take two inputs and return a binary output that can only have two values 0 (for pixels where the condition was false) or 1 (for the pixels where the condition was true).
Because of the binary (2-valued) nature of their outputs, the output is therefore stored in an `unsigned char`

data type (see Numeric data types) to speed up process and take less space in your storage.
There are two exceptions to the general features above: `isblank`

only takes one input, and `where`

takes three, while not returning a binary output, see their description for more.

`lt`

Less than: creates a binary output (values either 0 or 1) where each pixel will be 1 if the second popped operand is smaller than the first popped operand and 0 otherwise. If both operands are images, then all the pixels will be compared with their counterparts in the other image.

For example, the pixels in the output of the command below will have a value of 1 (true) if their value in

`image1.fits`is less than their value in`image2.fits`. Otherwise, their value will be 0 (false).$ astarithmetic image1.fits image2.fits lt

If only one operand is an image, then all the pixels will be compared with the single value (number) of the other operand. For example:

$ astaithmetic image1.fits 1000 lt

Finally if both are numbers, then the output is also just one number (0 or 1).

$ astarithmetic 4 5 lt

`le`

Less or equal: similar to

`lt`

(‘less than’ operator), but returning 1 when the second popped operand is smaller or equal to the first. For example$ astaithmetic image1.fits 1000 le

`gt`

Greater than: similar to

`lt`

(‘less than’ operator), but returning 1 when the second popped operand is greater than the first. For example$ astaithmetic image1.fits 1000 gt

`ge`

Greater or equal: similar to

`lt`

(‘less than’ operator), but returning 1 when the second popped operand is larger or equal to the first. For example$ astaithmetic image1.fits 1000 ge

`eq`

Equality: similar to

`lt`

(‘less than’ operator), but returning 1 when the two popped operands are equal (to double precision floating point accuracy).$ astaithmetic image1.fits 1000 eq

`ne`

Non-Equality: similar to

`lt`

(‘less than’ operator), but returning 1 when the two popped operands are*not*equal (to double precision floating point accuracy).$ astaithmetic image1.fits 1000 ne

`and`

Logical AND: returns 1 if both operands have a non-zero value and 0 if both are zero. Both operands have to be the same kind: either both images or both numbers and it mostly makes meaningful values when the inputs are binary (with pixel values of 0 or 1).

$ astarithmetic image1.fits image2.fits -g1 and

For example if you only want to see which pixels in an image have a value

*between*50 (greater equal, or inclusive) and 200 (less than, or exclusive), you can use this command:$ astarithmetic image.fits set-i i 50 ge i 200 lt and

`or`

Logical OR: returns 1 if either one of the operands is non-zero and 0 only when both operators are zero. Both operands have to be the same kind: either both images or both numbers. The usage is similar to

`and`

.For example if you only want to see which pixels in an image have a value

*outside of*-100 (greater equal, or inclusive) and 200 (less than, or exclusive), you can use this command:$ astarithmetic image.fits set-i i -100 lt i 200 ge or

`not`

Logical NOT: returns 1 when the operand is 0 and 0 when the operand is non-zero. The operand can be an image or number, for an image, it is applied to each pixel separately. For example if you want to know which pixels are not blank, you can use not on the output of the

`isblank`

operator described below:$ astarithmetic image.fits isblank not

`isblank`

Test for a blank value (see Blank pixels). In essence, this is very similar to the conditional operators: the output is either 1 or 0 (see the ‘less than’ operator above). The difference is that it only needs one operand. For example:

$ astarithmetic image.fits isblank

Because of the definition of a blank pixel, a blank value is not even equal to itself, so you cannot use the equal operator above to select blank pixels. See the “Blank pixels” box below for more on Blank pixels in Arithmetic.

`where`

Change the input (pixel) value

*where*/if a certain condition holds. The conditional operators above can be used to define the condition. Three operands are required for`where`

. The input format is demonstrated in this simplified example:$ astarithmetic modify.fits binary.fits if-true.fits where

The value of any pixel in

`modify.fits`that corresponds to a non-zero*and*non-blank pixel of`binary.fits`will be changed to the value of the same pixel in`if-true.fits`(this may also be a number). The 3rd and 2nd popped operands (`modify.fits`and`binary.fits`respectively, see Reverse polish notation) have to have the same dimensions/size.`if-true.fits`can be either a number, or have the same dimension/size as the other two.The 2nd popped operand (

`binary.fits`) has to have`uint8`

(or`unsigned char`

in standard C) type (see Numeric data types). It is treated as a binary dataset (with only two values: zero and non-zero, hence the name`binary.fits`

in this example). However, commonly you won’t be dealing with an actual FITS file of a condition/binary image. You will probably define the condition in the same run based on some other reference image and use the conditional and logical operators above to make a true/false (or one/zero) image for you internally. For example the case below:$ astarithmetic in.fits reference.fits 100 gt new.fits where

In the example above, any of the

`in.fits`pixels that has a value in`reference.fits`greater than`100`

, will be replaced with the corresponding pixel in`new.fits`. Effectively the`reference.fits 100 gt`

part created the condition/binary image which was added to the stack (in memory) and later used by`where`

. The command above is thus equivalent to these two commands:$ astarithmetic reference.fits 100 gt --output=binary.fits $ astarithmetic in.fits binary.fits new.fits where

Finally, the input operands are read and used independently, so you can use the same file more than once as any of the operands.

When the 1st popped operand to

`where`

(`if-true.fits`) is a single number, it may be a NaN value (or any blank value, depending on its type) like the example below (see Blank pixels). When the number is blank, it will be converted to the blank value of the type of the 3rd popped operand (`in.fits`

). Hence, in the example below, all the pixels in`reference.fits`that have a value greater than 100, will become blank in the natural data type of`in.fits`(even though NaN values are only defined for floating point types).$ astarithmetic in.fits reference.fits 100 gt nan where

GNU Astronomy Utilities 0.16 manual, October 2021.