Get maximum value inside a single band using GPT

Dear SNAP team,

Is it possible to extract the maximum value of a single band (e.g. a scalar, not an array) using GPT? I want to do this so that I can cross-normalise RGB channels prior to producing a GeoTIFF.

There is the StatisticsOp. But it is not well documented.
Best documentation is can be found here: A StatisticsOp graph - GPF Graphs - STEP Forum (esa.int)

If you you use python you can use a script for getting the max value.

``````sourceProduct = ProductIO.readProduct(sys.argv[1])
b2 = sourceProduct.getBand('B2')
accurate= False # or True but takes longer
stx = b2.getStx(accurate, ProgressMonitor.NULL)
max = stx.getMaximum()
``````
1 Like

Thanks! Would love to use Python (and snappy), but not an option in this specific case. Will persist with StatisticsOp.

@marpet Success, but with one caveat - how do I then use the calculated parameters within a graph? StatisticsOp seems confined to writing out to shapefile and ascii, and no amount of band merging I attempt will import any parameters from the StatisticsOp node into a future BandMaths node.

If I write out a dimap (using a write node) with just the contents of the StatisticsOp process, then there is a dummy band and none of the relevant scalar parameters. Thanks for the help.

Thatâ€™s the problem with the operator. You canâ€™t use it as input for another operator.
I thought you would have some intermediate before creating the RGB where you could read the ASCII file.
There is already a ticket in our issue manager to make such values accessible directly in Band Maths.
https://senbox.atlassian.net/browse/SNAP-1467

A quick follow up question on this, as perhaps there is an in built way around my problem. When using convert-datatype to shift from float32 to uint8 there are various options for re-scaling. I am assuming the options presented by GPT are correct (they differ from the help).

Lets say I want to convert using Linear (slope and intercept). If I feed convert-datatype a single source band, the behaviour is obvious. However, if I feed it three bands, nominally for R/G/B, how is the normalisation performed? Is it per channel, or are the slope and intercept calculated using all three ingested bands, and so preserving the relative colour intensities?

I suspect the former, per channel, behaviourâ€¦but I hope for the latter!

Yes, the calculation is done per channel.
Iâ€™m sorry to destroy your hopes.

1 Like