Convert deprecated: how to extract bands now?

In order to extract few bands from a multi-band image, this used to work:
otbcli_Convert -in QB_1_ortho.tif?bands=1:2 -out example2.tif

now that Convert is no longer available, how can the same operation be performed?
Thanks
Agus

Hello,

Convert has been replaced by DynamicConvert.

However if you only want to extract bands, you can also use ÈxtractROI with the “Channel” option :

otbcli_ExtractROI -in in.tif -out out.tif -cl Channel1 Channel2

(untested)

Cédric

Thanks.
I had just found this other way:
otbcli_BandMathX -il QB_1_ortho.tif?bands=1,2 -out example2.tif -exp “im1*1”
(tested)

Dear @alobo
Your solution is not optimal, since BandMath will compile the expression and compute pix*1 for each pixel of you image. You should give ExtractROI a try.
Regards.
Julien.

I understand. But this is just an example. What about if the user has to select 25 bands from within a hyperspectral image of 265 bands? Would we be writing Channel* 25 times? It is not CPU time the only thing that matters.
Maybe having BandMathX accepting “im1” as a valid expression would be a better way. Alternatively, include an option for not applying any transform in DynamicConvert.
And/or just have Convert back in the meanwhile: deprecating an application in favor of another (DynamicConvert) that is not able to do at least the same is a bad design.

@alobo

DynamicConvert is basically the new name for Convert (plus some bug fixes), it has been renamed to highlight that there is actually a conversion of the dynamic of the input image between input and output pixel types. If it is what you want, you can use it, and the “bands” extended filename will work.

You are right, the channel parameter is not very user-friendly in command line, and for big images the extended filename is more convenient (it is still possible to generate the channel list with a loop in Python or command line). However this parameter is handy in GUI :

I think @julienosman just wanted to point out that there is more computations that you might think when calling BandMathX. Of course computation time is not everything. Note that the syntax “im1” also works, but still implies evaluating the expression “im1” for each pixel. BandMathX is very versatile, but remember that it is not very efficient by nature, because expressions are evaluated at runtime, and compiled equivalent should be preferred, when possible.

But if performances matter, the best thing to do is to apply the “bands” extended filename on the first application of the processing chain.

Another solution that avoid copying most of the raster in a new tif is to build a GDAL vrt :slight_smile:

Cédric

ok, then, if the extended file name form is valid for ExtractROI, and for the case of many bands to be selected, the best syntax would be:

otbcli_ExtractROI -in QB_1_ortho.tif?bands=1,2 -out example2.tif 

I think this should be somewhere in the manual. Extracting bands is a common operation.

If you want extract bands directly after an OTB application, there is also extended filenames

otbli_SomeGreatApplication -in ... -out "toto.tif?&bands=2:4,5"

1 Like