4

I have a .CUB map from the USGS, the Mars MOLA image, which is about 46000x23000 pixels and 2GB. I am trying to convert it from .CUB to .TIF but I want to keep it 16 bit.

I ran:

gdalinfo -stats Mars_MGS_MOLA_DEM_mosaic_global_463m.cub

Output:

STATISTICS_MAXIMUM=21241
STATISTICS_MEAN=-720.52571146212
STATISTICS_MINIMUM=-8201
STATISTICS_STDDEV=2976.6805556461

Then I ran:

gdal_translate -scale -8201 21241 1 65536 -a_nodata 0 Mars_MGS_MOLA_DEM_mosaic_global_463m.cub Mars_Bump_16bit.tif

The output image, the four volcanoes on Mars, are not white, they are flat and gray, it's like the tops of the volcanoes were outside the range and were truncated.

If I run:

gdal_translate -scale -8201 21241 1 255 -ot byte -a_nodata 0 Mars_MGS_MOLA_DEM_mosaic_global_463m.cub Mars_Bump_8bit.tif

It generates an image where the volcanoes are NOT truncated.

What am I doing wrong for 16bit to 16bit?

tinlyx
  • 11,057
  • 18
  • 71
  • 119
Blake
  • 43
  • 2
  • How do you show the image? Your viewer may apply some statistical LUT stretch. – user30184 May 08 '17 at 04:24
  • I am using Blender which supports 16 bit so I am pretty sure the actual image has truncated data instead of it just not being displayed correctly. – Blake May 08 '17 at 05:20
  • You are rescaling twice. Once from Int16 to UInt16, then for display. Why not just convert from CUB to Int16 and leave the range as it is? – user2856 May 08 '17 at 05:40
  • How would I do that exactly, I just tried like 6 variations of the command and they all resulted in something incorrect, like an image with only black and white, a solid black image, and same as before, grayscale but far white is truncated. – Blake May 08 '17 at 05:47
  • What do you get from gdalinfo -stats on the tif files? – AndreJ May 08 '17 at 06:07
  • STATISTICS_MAXIMUM=32767 STATISTICS_MEAN=16617.509250038 STATISTICS_MINIMUM=16 STATISTICS_STDDEV=6509.7411214304 – Blake May 08 '17 at 06:12
  • Setting it to UINT16 did the trick and I tested it in Blender and Blender can handle it. Thanks so much! Want to post an answer so I can choose it? – Blake May 08 '17 at 06:28

1 Answers1

3

If you run gdalinfo -stats on the resulting file , the data is Int16 by default, cut of at 32767.

If you translate with -ot UINT16, you get data between 1 and 65535.

Alternatively, if Blender does not understand UINT16, you have to scale between -32768 and 32767.

AndreJ
  • 76,698
  • 5
  • 86
  • 162