0

I have a GeoTIFF file where the pixels are stored as unsigned 16 bit integers. I am using C# Gdal bindings to read the GeoTIFF file, using the Band.ReadRaster method, in order to produce an array of normalized values between 0 and 1.

I use ComputeRasterMinMax to compute the min and max value of all the data points in the band. For other GeoTiff files where pixels are stored as floats/doubles, it works out that the min and max are the absolute min and max elevation in meters. However, it is not clear to me if this is true when the pixels are stored as unsigned integers.

For instance, a sample file gives me 4000 as the min and 27000 as the max. If these are absolute elevations, then would I need to normalize each pixel via the method:

normalized pixel value = (pixel value - 4000) / 23000.

Is that correct, or should I normalize the pixels using ushort.MinValue and ushort.MaxValue, i.e.:

normalized pixel value = (pixel value - ushort.MinValue) / (ushort.MaxValue - ushort.MinValue)

which of course can be simplified given ushort.MinValue = 0.

1
  • I think there's a typo shouldn't it be normalized pixel value = (pixel value - 4000) / 27000 (the text says 27000 but the calc is 2300)? Either way I would think the normalization equation should be more like (pixel value - raster_min) / (raster_max - raster_min). This would reduce the minimum to 0 and the maximum to 1 by reducing by the minimum then dividing by the difference between min and max which is a percentage as a decimal calculation. For the sake of speed I would set a new variable raster_diff = raster_max - raster_min then normalized = (pixel value - raster_min) / raster_diff. Nov 28, 2019 at 5:17

1 Answer 1

3

Both methods you describe will lead to data that lies between 0 and 1. The first method, using the actual min/max found by ComputeRasterMinMax will place min value pixels at 0, max values at 1, and everything else linearly divided in the range. The second method will just linearize the range 0 to ushort.MaxValue, placing your pixels on that scale. Which you use depends on what you mean by "normalize".

I don't understand what you mean by this statement:

For other GeoTiff files where pixels are stored as floats/doubles, it works out that the min and max are the absolute min and max elevation in meters.

ComputeRasterMinMax will read the raster and return the actual min and max values that occur in the data, not the min/max possible values of the datatype. (Whether it reads the whole raster or just samples it depends on the setting of the approximate arg.) This holds regardless of datatype, float or fixed, long or short.

Also, the units are a function of the CRS of your data. While this is often meters, it can be miles, feet, or something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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