Exported JPG2000 has always 8-bit depth (even if 16-bit is specified.

cradacrada Global Mapper UserPosts: 8
Hi, I'm trying to export a 16-bit GeoTiff aerial photograph into a 16-bit JPG2000
This doesn't work from the standard export dialog. Therefore I tried scripting but it doesn't work either. I'm using Global Mapper 18 and my script is as follows (excluding projection definition)

IMPORT FILENAME="C:\users\camilo\My Documents\GIS\Fotografias Aereas\SAF\GEOTEC\Not in PDF\o17563.tif" \
RASTER_TYPE="IMAGE" \
PROJ_NAME="UTM_ZONE-19_WGS84" \
AUTO_CONTRAST="NO"
EXPORT_RASTER FILENAME="C:\users\camilo\My Documents\GIS\Fotografias Aereas\SAF\GEOTEC\jpg2000\o17563_2a1_script.jp2" \
TYPE=JPEG2000 \
BAND_BIT_DEPTH=16 \
PALETTE=KEEP_SOURCE \
NUM_BANDS=1 \
TARGET_COMPRESSION=2

I tried without specifying AUTO_CONTRAST, also with PALETTE=MULTIBAND and neither option works. I always get an 8-bit JPG2000 file.

This is the relevant metadata of the input GeoTiff file

PROJ_DESC=UTM Zone -19 / WGS84 / meters
PROJ_DATUM=WGS84
PROJ_UNITS=meters
EPSG_CODE=EPSG:32719
NUM COLUMNS=11011
NUM ROWS=10390
NUM BANDS=1
BIT DEPTH=16
SAMPLE TYPE=Unsigned 16-bit Integer
PHOTOMETRIC=Greyscale (Min is Black)
BIT_DEPTH=16
SAMPLE_FORMAT=Unsigned Integer
ROWS_PER_STRIP=1
COMPRESSION=None

Thanks
Tagged:

Answers

  • Ice Age MarkIce Age Mark Global Mapper User Posts: 318Trusted User
    Hello,

    The metadata from the original image has 16 bits, but only 1 band (of 8 bits).  Most likely the 'other' 8 bits is an 'alpha band' or transparency channel.  Since you don't have BG_TRANSPARENT=YES in your script, GM is only exporting the image channel part, which is 8 bits.  If you check "Make background pixels transparent" or use "BG_TRANSPARENT=YES" in your script, you should get a 16 bit export.

    Hopefully, that is the explanation and will help out.

    Good luck,

    Mark 

  • cradacrada Global Mapper User Posts: 8
    Thanks Mark for the answer, but unfortunately it doesn't work. I get a JPG200 file described in the metadata as

    BIT DEPTH=16 [+8-bit Alpha]

    But if I export it back to 16-bit GeoTiff I get a 16-bit file with values only in the 8-bit range (0-255), therefore as before the 16-bit information is being lost in the export to JPG2000.

    Regarding what you say I don't understand why you say the original file has an 8-bit band. It has one band but it is a16-bits band (values in the range 0-65535).

  • Ice Age MarkIce Age Mark Global Mapper User Posts: 318Trusted User
    Howdy,

    That was a (mistaken) assumption on my part, having encountered a similar situation in the past.  Sorry it didn't help.

    One other thought.  Your script command line RASTER_TYPE="IMAGE" may be a problem.  In my scripts with imports it's TYPE="GEOTIFF".  "IMAGE" is not a valid parameter, so GM may not be importing the file as you expect (Though it should default to AUTO and pick GEOTIFF.  Do you get an error for this line?).  Also, if you didn't already, check the metadata of your file right after it's imported into GM manually to check it's bit depth before export within GM.

    What is the file data?  There is also a 'load flags' import parameter for geotiff's depending on whether it's elevation or image data.  Can you post it, or a small sample?

    Mark
  • cradacrada Global Mapper User Posts: 8
    Thanks again for your help. TYPE=GEOTIFF doesn't help either.
    And the file loaded after the script run if fine (16-bits).
    You can get the file I'm trying to convert here:
    https://www.dropbox.com/s/0wzc72ngez6y5z7/o17563.tif?dl=0
    Thanks!
  • cradacrada Global Mapper User Posts: 8
    Hi Mark,
    Sorry my last answer was a bit in a rush.
    Note that I'm NOT using TYPE=IMAGE I'm using RASTER_TYPE="IMAGE" for the TYPE I was just leaving it to AUTO but using GEOTIFF doesn't makes any difference.
    I don't get any errors.

    The metadata (relevant parts) of the imported file left in the workspace after the scripts runs is

    FILENAME=C:\users\camilo\My Documents\GIS\Fotografias Aereas\SAF\GEOTEC\Not in PDF\o17563.tif
    NUM BANDS=1
    BIT DEPTH=16
    SAMPLE TYPE=Unsigned 16-bit Integer
    PHOTOMETRIC=Greyscale (Min is Black)
    BIT_DEPTH=16
    SAMPLE_FORMAT=Unsigned Integer
    ROWS_PER_STRIP=1
    COMPRESSION=None

    So the IMPORT seems to be fine, but it is the export that have the problem of producing a 8-bit JPG2000 instead a 16-bit one.
    Note that this happens even if I use the export dialog.

    It would be interesting if you download the file from the link in my previous post and see if the same happens to you. Maybe the issue was solved in later version of GM.

    Thanks!
  • Ice Age MarkIce Age Mark Global Mapper User Posts: 318Trusted User
    Hello again,

    Interesting issue.  I downloaded your image and can confirm the same behavior.  However, at 1:1 compression the exported JPG2000 image is 100% identical visually.  So for practical purposes, unless you're doing some mathematical analysis of the image, you can ignore the bit depth difference and proceed.

    This stuff is really at the fringe of my knowledge, and I'm likely wrong about some things, but this is what I think I know.  The Geotiff header defines the colorspace as grayscale, so it only has 256 possible values.  Since the original Geotiff has 65535 possible values, it must get re-mapped into 256 groups of values to display in grayscale.  I confirmed this is happening to the original Geotiff on import by finding, for example, three different pixels with RGB(169,169,169) that each had a different (but appropriate for that 'bin') value.  This effectively changes it into an 8 bit image, and that is what the JPG2000 export is finding.  Even though you're choosing 16 bits for export, it's only finding 8 bits 'worth' of data and exporting that.  When you re-import the JPG2000 that's all there is, and the metadata shows it.

    Are you losing data?  Mathematically, yes - visually, no.  (Hence my earlier statement)  The human eye cannot distinguish more than 256 shades of gray.  An image with 65535 shades instead of 256 would look identical.  So, visual image quality is not affected by the remapping from 16 to 8 bit grayscale by the JPG2000 export, but you're gaining on file size, and whatever other advantages that format might offer.

    If you're like me, it still bugs you that data is lost, but it really doesn't matter unless you are analyzing the image in some way, or are doing some kind of image processing.  That kind of stuff would have to be done prior to exporting it as a grayscale Geotiff.

    I hope I'm mostly right and this helps.

    Mark

    p.s - Nice image (1.7m resolution!) for that region.  I once considered moving to Tierra del Fuego.  My icon picture is from down that way.  I also use the Patagonian Ice Caps as 'analogy images' for my region during the Pleistocene.  It sure looks beautiful there on Google photos, when the sun comes out, that is!
  • cradacrada Global Mapper User Posts: 8
    It seems to be a bug. A colleague tried in Global Mapper 20 and it works.
  • Ice Age MarkIce Age Mark Global Mapper User Posts: 318Trusted User
    Glad to know it got fixed, and that it's broken in my version (17.2).  I guess the remapping in GM is just for display.  Good to know that too.
Sign In or Register to comment.