We are happy to announce a brand new band raster calculator in OTB. This band math is implemented in a new filter (otbBandMathXImageFilter) and this feature is also available through in a new OTB application otbBandMathX.

The letter X indicates that now the filter relies on the muparserx library, which has allowed the introduction of new functionalities, which are listed below:

## Batch mode

If the same mathematical operation must be performed on every band of an input image, it is now possible to do it with a unique formula. For example, the addition of two images im1 and im2 is simply performed by simple addition:

im1 + im2

instead of (the old fashioned way):

im1b1+im2b1 im1b2+im2b2 …

This is possible since muparserX has capabilities to represent vectors and perform mathematical operations on them. Here, a pixel from a multi-band image is then represented as a muparserX vector: im1 (for image 1), with im1 = (im1b1, im1b2, …).

Note that it is still possible to access the pixel of a particular band from a given input image; for instance the variable im1b1 represents a pixel from first band of first input image.

## Pixel neighborhoods access

muparserX is also able to process matrices, which allows the representation of neighborhoods of pixels. Such neighborhoods can be represented by simply providing *nxm* along with the image and band, e.g.:

Fig. 1 : Naming convention for accessing pixel neighborhoods.

A lot of useful operators come with these variables: it is possible to get the mean value of a neighborhood, as well as its median/variance/min/max values. For instance, with the expression below, we can perform a simple **high-pass filter**:

im1 - mean(im1b1N5x5, im1b2N5x5, im1b3N5x5, im1b4N5x5)

In the expression above, the operator **mean** is used with 4 neighborhoods as inputs, which means that it will produce a vector of four components. If first input image (represented by the variable *im1*) is made of four bands, then the expression is consistent:

Fig. 2 : High pass filter with new raster calculator

## Use of global statistics

It is also possible to have access to global statistics of input images. For example, the variable im1b1Mean allows getting the mean value of band 1 from first input image. Min/max/sum/variance values are also available and use “behind the scene” OTB filters which allow to perform those computation on huge images using streaming and multi-threading.

## Fine multi-expressions management

If many expressions must be interpreted, the user has the choice of:

- Produce as many output images as there are expressions
- Concatenate the results of the expressions into bands of a single output image

In the first case, you have to call the method *SetExpression* each time a new expression must be processed. In the second one, you just have to separate expressions by semicolons when calling the same method. Of course, these two solutions can be mixed together. For instance:

//producing 1st output image //by concatenating the results of two expressions

Filter->SetExpression(“im1 + im2 ; vabs(im1-im2)”);

//producing 2nd output image

Filter->SetExpression(“im1 - mean(im1b1N5x5, im1b2N5x5, im1b3N5x5, im1b4N5x5)”);

Note that historically, OTB applications are only able to produce a single output; so the BandMathX application is a little bit more limited than the filter itself for now, which can produce multiple output images.

## Constants and expressions saving capabilities

You can save constant or expression definitions in a text file, and import them into the application (or the filter) later, e.g.:

#F expo 1.1

#M kernel { 0.1 , 0.2 , 0.3; 0.4 , 0.5 , 0.6; 0.7 , 0.8 , 0.9; 1 , 1.1 , 1.2; 1.3 , 1.4 , 1.5}

#E dotpr(kernel,im1b1N3x5,im1b2N3x5) ; im2b1^expo

Here, we can see the definitions of a constant, a matrix and finally an expression.

## Learn more

All of this is already available in the development version of OTB and Monteverdi2. There are also other useful information and examples that can be found in the **cookbook** and in the new **BandMathX application **documentation.

We hope you will enjoy these new features and the new application.

Don’t hesitate to test and give feedback on the otb-users mailing list!