Wiki

Clone wiki

enmap-box-idl / imageMath

Overview

imageMath is an IDL based application for evaluating mathematical expressions, which are not only consisting of simple number arguments, but also complete images, image bands or image profiles. The goal of imageMath is to provide an calculator that (1) is easy to use, (2) has a graphical user interface with the look-and-feel of a common hand-held calculator, (3) is enhanced by image processing functionality and (4) is easily extendable by user-written functions. imageMath is part of the EnMAP-Box Software.

Graphical User Interface (GUI)

For lunching the imageMath calculator

  • select Applications > imageMath Calculator

image001.png imageMath Calculator GUI.

  • The input field is used to enter the mathematical expression via the keybord. For evaluating the expression enter '=' or press the '=' button. To evaluate a subexpression (of the entered expression), select it and press the '=' button.
  • The output field is used to provide information to the user, e.g. the result of the calculation, usage information for function menu function, or error messages.
  • The control panel is organized into different button groups to enter simple expressions via the mouse. It contains buttons for entering operators (i.e. arithmetic, logical, bitwise and type casting operators), for clearing text (i.e. Backspace and Clear) and a '=' button for evaluating the entered expression.
  • The function menu is a set of functions, which are registered to the imageMath calculator. By selecting a specific function (clicking on the function name) the user is provided by a usage/syntax description. By double clicking, the function is inserted into the input field.

If the expression contains variables, the variable selection dialog appears.

  • For each input variable select an Image. To use a specific image band or profile, select a Band or Pixel Position. To select a single image value, select both.
  • Select a Result File

image003.png imageMath variable selection dialog.

Understanding Operators

The operators supported by imageMath are supposed to behave the same way as the corresponding IDL operators do. So, for comprehension questions it is a good idea to consult the IDL Help under Table of Contents -> Language Components: Bitwise Operators, Logical Operators, Mathematical Operators, Minimum and Maximum Operators; Operator Precedence, Relational Operators. The evaluation of an unary operator, like ~ or NOT, will always lead to an output argument with same type. So if the input argument is an image, band, profile or number the result argument is also an image, band, profile or number, respectively. The evaluation of a binary operator, like +, ^, -, / or mod, will lead to an output argument with a potentially different type, compared to the inputs. Binary operators can be applied on any input argument combination, by replicating missing dimensions. For example, to apply a binary operator to an image-band combination, the band is replicated along the spectral dimension, to fit the image's spectral dimension. Than, the binary operator is applied value-wise. This replication is straightforward for all argument pairs:

  • image-image: no replication needed; spatial and spectral dimensions must match
  • image-band: replicate band along image's spectral dimension, spatial dimensions must match
  • image-profile: replication profile along image's spatial dimension, spectral dimension must match
  • image-number: replicate number along image's spatial and spectral dimension
  • band-band: no replication needed; spatial dimension must match
  • band-profile: replicate band along profile's spectral dimension and replicate profile along band's spatial dimension
  • band-number: replicate number along band's spatial dimension
  • profile-profile: no replication needed; spectral dimension must match
  • profile-number: replicate number along profile's spectral dimension
  • number-number: no replication needed

When, for example, the expression 'A+B/C' is evaluated, where A is an image, B is a band and C is a number:

image006.gif

imageMath replicates B's spectral dimension and C's spatial and spectral dimensions:

image008.gif

Finally, the + and / operators are applied value-wise.

Understanding Data Types

The data types supported by imageMath are supposed to behave the same way as the corresponding IDL operators do. So, for comprehension questions it is a good idea to consult the IDL Help under Table of Contents -> Language Components: IDL Data Types. Every argument in an expression has a specific data type, which is given by the selected image (see image header file). In case of a number a specific type postfix can be specified (e.g. '10b' for byte number with value 10). Explicite data type casting functions and data type number postfixes can be entered via the buttons:

image009.png

Note that it is a difference, if you evaluate the expression '1/2', in comparison to '1./2.'. In the first case, the two integers will be divided by using integer division leading to another integer '0'. In the second case, the '.' marks the numbers as floats which will be divided by using floating-point division leading to another float '0.5'.

Another common problem with data types is the data type range, which can easily overflow (or underflow). Try to evaluate '-1b', which is the negation of the byte number with value 1. This will, due to an underflow, evaluate to '255b', which is the biggest byte number in IDL. Now try to evaluate '0-1b', this will NOT evaluate to '255b', but to '-1', which is because of the implicite type casting of the binary '-' operator. Try to remember that if your calculated images are all black, or appear to be randomly generated, it is most likely an issue of data types.

Understanding Functions

imageMath comes along with a set of predefined functions, which can be selected from the function menu:

image011.png

In principle, imageMath functions can be arbitrary complex, ranging from simple type casting functions like byte() or float() to whole processing chains. To give an idea about the range of possibilities, here are some examples.

Image in Image out

All of the Trigonometric and Miscellaneous Math functions behave the way, that they take an input image, calculate something (e.g. the Sine or the Square Root) for each component, and return a result image of same size.

image013.png

Example:

image015.png image017.png
image and alog(image)

Image in Band out

All of the Profile Statistics functions behave in the way that they take an input image, calculate a profile-wise statistic (e.g. the Mean or the Variance) for each profile, and return a result band of same spatial size.

image019.png

Example:

image015.png image021.png
image and spectralVariance(image)

Image in Profile out

All of the Band Statistics functions behave in the way that they take an input image, calculate a band-wise statistic (e.g. the Mean or the Variance) for each band, and return a result profile of same spectral size.

image023.png

Example:

image015.png image025.png
image and spatialMean(image)

Image in Number out

All of the Image Statistics functions behave in the way that they take an input image, calculate an image-wise statistic (e.g. the Mean or the Variance), and return it as a scalar number.

image027.png

Example:

image015.png 1584.4194
image and imageMean(image)

Usage Examples

Functions and operators can be combined to more complex expressions. This section will provide some examples on how to use the calculator. The hubAPI test images are used for demonstration purposes:

  • start the EnMAP-Box
  • select File > Open > hubAPI Test Images from the EnMAP-Box main menu

Masking an Image

Masking an image by multiplying it with a mask.
Evaluate:

image*mask

Inputs:

image029.png image031.png

Result:

image033.png

Extracting Class-Specific Regions from an Image

Use a classification image to identify vegetated areas (vegetation is class 1, colored in green) and extract it from an image.
Evaluate:

image*(mask eq 1)

Inputs:

image029.png image036.png

Result:

image038.png

Scale Image Profiles

Scale each image profile into the range between -10 and 10. Therefore we need the minimum and the span of each profile, which are available via the spectralMinimum and the spectralRange functions.
Evaluate:

((float(image)-spectralMinimum(image))
/
spectralSpan(image))
*20-10

Note that the subexpression in the first three lines, scales each profile between 0 and 1, and the last line is stretching it into the range between -10 and 10.

Inputs:

image015.png image040.png

Result:

image042.png image044.png

Scale Image Bands

Scale each image band into the range between -10 and 10. Therefore we need the minimum and the span of each band, which are available via the spatialMinimum and the spatialSpan functions.
Evaluate:

((float(image)-spatialMinimum(image))
/
spatialSpan(image))
*2*10-10

Note that the subexpression in the first three lines, scales each band between 0 and 1, and the last line is stretching it into the range between -10 and 10.

Inputs:

image015.png image040.png

Result:

image046.png image048.png

Updated