Bandmath and limit value

Hello,

I want to use the bandmath algorithm to create a raster allowing me to polygonize the data with Qgis
my order is:

“otbcli_BandMath.bat” -il E: /M.tif -out E: /r/M_class.tif uint16 -exp "im1b1 <0? im1b1: im1b1 <= 25? 25: im1b1 <= 50? 50: im1b1 <= 75? 75: im1b1 <= 100? 100: im1b1 <= 125? 125: 150 "

but it causes me problem because I lose the extreme values ​​higher than 150.

how can I create a class 125 to infinity?

Thanks,
fcka

Hello,

I am not sure to understand, the expression used is not doing what you want ? i.e. assigning the class 150 to each value superior to 125 ?

Cédric

Hello,pj.pdf (275.5 KB)
I am trying to merge the pixels belonging to the class having the extreme values ​​(from 110 to infinity).

in reality my order is “otbcli_BandMath.bat” -il F:/3d/MNT_pourcent.tif -out F:/3d/MNT_pourcent_class.tif uint16 -exp “im1b1 < 0?im1b1:im1b1 <= 5?5:im1b1 <= 10?10:im1b1 <= 15?15:im1b1 <= 20?20:im1b1 <= 25?25:im1b1 <= 30?30:im1b1 <= 35?35:im1b1 <= 40?40:im1b1 <= 45?45:im1b1 <= 50?50:im1b1 <= 55?55:im1b1 <= 60?60:im1b1 <= 65?65:im1b1 <= 70?70:im1b1 <= 75?75:im1b1 <= 80?80:im1b1 <= 85?85:im1b1 <= 90?90:im1b1 <= 95?95:im1b1 <= 100?100:110”
I don’t know how to create a class [110, infinte [

attached a document to illustrate my point

fcka

Hello,

your expression assigns the value 110 to [100, infinity[ right ? if you want a class [110, infinity[ can’t you simply add a test case for values between 100 to 110 and assign the [110, infinity[ label to pixels failing the test ? But maybe I am missing something here.

Cédric

Hello
Thank you for your interest in my question.
For values ​​greater than 110, I would like to merge the pixels by assigning them an extreme value (999 for example)

I launched the following command:

“otbcli_BandMath.bat” -il E:/MNT_2017_RASTER_PENTE_pourcent.tif -out E:/o/MNT_2017_RASTER_PENTE_pourcent_class.tif uint16 -exp “im1b1 < 0?im1b1:im1b1 <= 5?5:im1b1 <= 10?10:im1b1 <= 15?15:im1b1 <= 20?20:im1b1 <= 25?25:im1b1 <= 30?30:im1b1 <= 35?35:im1b1 <= 40?40:im1b1 <= 45?45:im1b1 <= 50?50:im1b1 <= 55?55:im1b1 <= 60?60:im1b1 <= 65?65:im1b1 <= 70?70:im1b1 <= 75?75:im1b1 <= 80?80:im1b1 <= 85?85:im1b1 <= 90?90:im1b1 <= 95?95:im1b1 <= 100?100:im1b1 <= 110?110:im1b1<=vmax(im1b1)?999:999”

I have the following error message:

2021-09-01 15:46:05 (INFO) BandMath: Default RAM limit for OTB is 256 MB
2021-09-01 15:46:05 (INFO) BandMath: GDAL maximum cache size is 812 MB
2021-09-01 15:46:05 (INFO) BandMath: OTB will use at most 4 threads
2021-09-01 15:46:05 (INFO) BandMath: Image #1 has 1 components

2021-09-01 15:46:05 (INFO): Estimated memory for full processing: 10070.8MB (avail.: 256 MB), optimal image partitioning: 40 blocks
2021-09-01 15:46:05 (INFO): File E:/o/MNT_2017_RASTER_PENTE_pourcent_class.tif will be written in 41 blocks of 22000x488 pixels
Writing E:/o/MNT_2017_RASTER_PENTE_pourcent_class.tif…: 0% [ ]2021-09-01 15:46:05 (FATAL) BandMath: itk::ERROR: MultiThreader(000001DEA8CE5020): Exception occurred during SingleMethodExecute
c:\build\otb\modules\filtering\mathparser\include\otbBandMathImageFilter.hxx:282:
itk::ERROR: BandMathImageFilter(000001DEA8CE2480):
itk::ExceptionObject (00000042CA389730)
Location: “unknown”
File: …\Modules\Filtering\MathParser\src\otbParser.cxx
Line: 170
Description: itk::ERROR: ParserImpl(000001DEA72A0410):
Message: Unexpected token “vmax” found at position 340.
Formula: im1b1 < 0?im1b1:im1b1 <= 5?5:im1b1 <= 10?10:im1b1 <= 15?15:im1b1 <= 20?20:im1b1 <= 25?25:im1b1 <= 30?30:im1b1 <= 35?35:im1b1 <= 40?40:im1b1 <= 45?45:im1b1 <= 50?50:im1b1 <= 55?55:im1b1 <= 60?60:im1b1 <= 65?65:im1b1 <= 70?70:im1b1 <= 75?75:im1b1 <= 80?80:im1b1 <= 85?85:im1b1 <= 90?90:im1b1 <= 95?95:im1b1 <= 100?100:im1b1 <= 110?110:im1b1<=vmax(im1b1)?999:999
Token: vmax
Position: 340

Do you think the error message is related to a memory problem or to my order?

Thanks
fcka

Hello,

vmax is bot available in BandMath, it is available in BandMathX which support operation vectors while BandMath only supports scalar expression. vmax returns the maximum of a vector. For example the expression "vmax(im1)" return, for each ouput pixel, the maximal component of the corresponding input vector pixel.

In your expression I think you are looking for the “im1b1Maxi” expression, which is also only available in BandMathX. im1b1Maxi is the maximum of the first band of the input image. Your input would be something like:

“otbcli_BandMathX.bat” -il E:/MNT_2017_RASTER_PENTE_pourcent.tif -out E:/o/MNT_2017_RASTER_PENTE_pourcent_class.tif uint16 -exp “im1b1 < 0?im1b1:im1b1 <= 5?5:im1b1 <= 10?10:im1b1 <= 15?15:im1b1 <= 20?20:im1b1 <= 25?25:im1b1 <= 30?30:im1b1 <= 35?35:im1b1 <= 40?40:im1b1 <= 45?45:im1b1 <= 50?50:im1b1 <= 55?55:im1b1 <= 60?60:im1b1 <= 65?65:im1b1 <= 70?70:im1b1 <= 75?75:im1b1 <= 80?80:im1b1 <= 85?85:im1b1 <= 90?90:im1b1 <= 95?95:im1b1 <= 100?100:im1b1 <= 110?110:im1b1<=im1b1Maxi ? 999 : 999”

But then again, im1b1 <= im1b1Maxi is always true so the expression can be simplified as

“otbcli_BandMath.bat” -il E:/MNT_2017_RASTER_PENTE_pourcent.tif -out E:/o/MNT_2017_RASTER_PENTE_pourcent_class.tif uint16 -exp “im1b1 < 0?im1b1:im1b1 <= 5?5:im1b1 <= 10?10:im1b1 <= 15?15:im1b1 <= 20?20:im1b1 <= 25?25:im1b1 <= 30?30:im1b1 <= 35?35:im1b1 <= 40?40:im1b1 <= 45?45:im1b1 <= 50?50:im1b1 <= 55?55:im1b1 <= 60?60:im1b1 <= 65?65:im1b1 <= 70?70:im1b1 <= 75?75:im1b1 <= 80?80:im1b1 <= 85?85:im1b1 <= 90?90:im1b1 <= 95?95:im1b1 <= 100?100:im1b1 <= 110?110 : 999”

Cédric

Hello,
it works !
thank you very much for your explanations and your help.
fcka