I have a couple of three-band satellite images that I want to apply an expression to and get a three-band output.

The expression is of a simple form: output_pixel= (input_pixel*d^2)/cos e

After reading the OTB cookbook I believe BandmathX is the application I need. However i am unsure how to formulate the command to get my expression applied to each pixel in all three bands.

What is the correct command to achieve this?

  • are d and e constant values or do they come from another raster ? – radouxju Jan 11 '17 at 8:57

I confirm that this can be done with BandMathX

in the command line, you need three inputs parameters

  • -il for the list of input images

  • -out for the name of output image. Note that you can use extended filenames and specify the output type, e.g.

-out "myOutput.tif?&gdal:co:COMPRESS=LZW&gdal:co:TILED=YES" uint8

  • -exp for the expression

the "easy" and most flexible way to write a multiple band output is to write the expression for each band individually, separated by a semi-colon. For example, with an RGB image, you can do :

-exp "(im1b1*d^2)/cos(e);(im1b3*d^2)/cos(e);(im1b3*d^2)/cos(e)"

of course, I assume that d and e are constant values, which you enter manually. They could also be store in another image, in this case you can refer to them as im2b1 and im3b1.

Alternatively, you can use vector operation with im1 (a row vector). This is shorter but you must use the right operators: mlt and dv to multiply/divide a vector by a scalar, mult and div to elementwise multiply/divide with a vector.

-exp "im1 mlt (d^2) dv cos(e)"

-exp "im1 mult {d^2,d^2,d^2} div {cos(e),cos(e),cos(e)}"

You could try the built-in bandmathx application in OTB. you can run this application through monteverdi2.

A daily generated installer for monteverdi2 is available for windows and osx from orfeo-toolbox.org

Here is the bandmathx recipe in the OTB Cookbook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.