3

Setting

For the purpose of a machine learning algorithm I'm tying to automatically scale images of arbitrary bitdepth to unit interval, i.e. I want to map pixels from [0,2x] to [0,1] simply by dividing all pixels by 2x. I want to do this without knowing anything about the pixelvalue distribution or statistics inside the image. The only thing that I know is the metadata. To open images I use gdal in python via

data = gdal.Open(path)

The images are given in .tif or .img format.

Problem

Typically 12bit images will be saved in a 16bit format, where pixel values above 4095 won't occure. Nevertheless the meta tag bitdepth will be 16bit.

Question

Is there any valid way to check whether an image is a true 16bit image or a 12bit image inside a 16bit image, without calculating the statistics? Is there any meta tag that serves this information?

3

There is a meta tag but it isn't in the default domain:

data = gdal.Open(path)
band = data.GetRasterBand(1) 
band.GetMetadata('IMAGE_STRUCTURE')
# {'NBITS': '12'}

For the full list of metadata domains use

band.GetMetadataDomainList()
# ['IMAGE_STRUCTURE', '']
1

At least when the GeoTIFF image is created with GDAL you can check the NBITS value with gdalinfo.

Create a test image

gdal_translate -of gtiff -ot uint16 -co nbits=12 base.tif base12.tif

Have a look at the metadata

gdalinfo base12.tif
Driver: GTiff/GeoTIFF
Files: base12.tif
Size is 10000, 10000
Coordinate System is `'
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,10000.0)
Upper Right (10000.0,    0.0)
Lower Right (10000.0,10000.0)
Center      ( 5000.0, 5000.0)
Band 1 Block=10000x1 Type=UInt16, ColorInterp=Red
  Image Structure Metadata:
    NBITS=12
Band 2 Block=10000x1 Type=UInt16, ColorInterp=Green
  Image Structure Metadata:
    NBITS=12
Band 3 Block=10000x1 Type=UInt16, ColorInterp=Blue
  Image Structure Metadata:
    NBITS=12
  • Thank you very much for your answer. Unfortunately I don't have the control about the data creation, but I see your point. Somehow the information needs to be added manually somewhere to the meta tags i.e. the workflow of early data processing needs to be adapted. – pafi Jul 1 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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