Bandmathx bitwise operators

hi,

I would like to know if it’s possible to perform bitwise operator throught bandmathx raster calculator. Seems Muparser provide these kind of operator (&, |, <<, >>) but can’t find a working syntax.

For example I want to check the 3rd bit of an 8bits mask which informs about the presence of snow, I tried the following syntaxes with no success

im1b1 & 00000100
im1b1 & 00000100 == 1
im1b1 & 4

The reported error is argument 1 of function/operator “im1b1” is of type ‘f’ whereas type ‘i’ was expected. It’s as if raster values are interpreted as float instead of integer

Thanks in advance for any help.

Regards

Hi Dom,
Unfortunately you won’t be able to use bit manipulation with the OTB application… The issue here is that we are reading the image in float, whereas you need integer to do bit manipulation… I will fill a feature request on the GitLab project.

EDIT: Feature Request

Hi Antoine,

Thank you very much for this fast answer and the feature request, I’ll will follow that.

Have a good day.

EDIT : if it can be usefull to anybody, this kind of operation is possible with GRASS r.mapcalc

Hello,
There is an operator that can be used to convert to int , you can try:

“(int)im1b1 & 0b00000001” (bitwise and)
“(int)im1b1 >> 1” (right shift operator)

I did a few tests and it seems to work (note that you need the 0b to define binary numbers, otherwise it will be parsed as an integer).

Cédric