[gdal-dev] Configuring JP2OpenJPEG attributes

Basos Syrris sbasos at yahoo.com
Thu Oct 22 01:14:33 PDT 2015


Dear list members,I would like you to help me with two issues I have while trying to set/get the attributes of the JP2OpenJPEG driver through the GDAL API in Python:
1) When I run the commands:Raster = gdal.Open(tiffile)jpg_driver = gdal.GetDriverByName('JP2OpenJPEG')
jpg_driver.Register()jpg_file = jpg_driver.CreateCopy(outjp2file, Raster, options = ['QUALITY=100', 'REVERSIBLE=YES'])
the attributes are set without problem (tiffile refers to a Geotiff image and outjp2file is the name of the new jp2 file); when I try to retrieve them the only thing I manage to do is to read the main keys:Raster = gdal.Open(outjp2file)
driver = Raster.GetDriver()
metadata = driver.GetMetadata()metadata{'DMD_EXTENSION': 'jp2', 'DMD_CREATIONOPTIONLIST': "<CreationOptionList>   <Option name='CODEC' type='string-select' default='according to file extension. If unknown, default to J2K'>       <Value>JP2</Value>       <Value>J2K</Value>   </Option>   <Option name='GeoJP2' type='boolean' description='Whether to emit a GeoJP2 box' default='YES'/>   <Option name='GMLJP2' type='boolean' description='Whether to emit a GMLJP2 v1 box' default='YES'/>   <Option name='GMLJP2V2_DEF' type='string' description='Definition file to describe how a GMLJP2 v2 box should be generated. If set to YES, a minimal instance will be created'/>   <Option name='QUALITY' type='string' description='Single quality value or comma separated list of increasing quality values for several layers, each in the 0-100 range' default='25'/>   <Option name='REVERSIBLE' type='boolean' description='True if the compression is reversible' default='false'/>   <Option name='RESOLUTIONS' type='int' description='Number of resolutions.' min='1' max='30'/>   <Option name='BLOCKXSIZE' type='int' description='Tile Width' default='1024'/>   <Option name='BLOCKYSIZE' type='int' description='Tile Height' default='1024'/>   <Option name='PROGRESSION' type='string-select' default='LRCP'>       <Value>LRCP</Value>       <Value>RLCP</Value>       <Value>RPCL</Value>       <Value>PCRL</Value>       <Value>CPRL</Value>   </Option>   <Option name='SOP' type='boolean' description='True to insert SOP markers' default='false'/>   <Option name='EPH' type='boolean' description='True to insert EPH markers' default='false'/>   <Option name='YCBCR420' type='boolean' description='if RGB must be resampled to YCbCr 4:2:0' default='false'/>   <Option name='YCC' type='boolean' description='if RGB must be transformed to YCC color space (lossless MCT transform)' default='YES'/>   <Option name='NBITS' type='int' description='Bits (precision) for sub-byte files (1-7), sub-uint16 (9-15), sub-uint32 (17-31)'/>   <Option name='1BIT_ALPHA' type='boolean' description='Whether to encode the alpha channel as a 1-bit channel' default='NO'/>   <Option name='ALPHA' type='boolean' description='Whether to force encoding last channel as alpha channel' default='NO'/>   <Option name='PROFILE' type='string-select' description='Which codestream profile to use' default='AUTO'>       <Value>AUTO</Value>       <Value>UNRESTRICTED</Value>       <Value>PROFILE_1</Value>   </Option>   <Option name='INSPIRE_TG' type='boolean' description='Whether to use features that comply with Inspire Orthoimagery Technical Guidelines' default='NO'/>   <Option name='JPX' type='boolean' description='Whether to advertize JPX features when a GMLJP2 box is written' default='YES'/>   <Option name='GEOBOXES_AFTER_JP2C' type='boolean' description='Whether to place GeoJP2/GMLJP2 boxes after the code-stream' default='NO'/>   <Option name='PRECINCTS' type='string' description='Precincts size as a string of the form {w,h},{w,h},... with power-of-two values'/>   <Option name='TILEPARTS' type='string-select' description='Whether to generate tile-parts and according to which criterion' default='DISABLED'>       <Value>DISABLED</Value>       <Value>RESOLUTIONS</Value>       <Value>LAYERS</Value>       <Value>COMPONENTS</Value>   </Option>   <Option name='CODEBLOCK_WIDTH' type='int' description='Codeblock width' default='64' min='4' max='1024'/>   <Option name='CODEBLOCK_HEIGHT' type='int' description='Codeblock height' default='64' min='4' max='1024'/>   <Option name='CT_COMPONENTS' type='int' min='3' max='4' description='If there is one color table, number of color table components to write. Autodetected if not specified.'/>   <Option name='WRITE_METADATA' type='boolean' description='Whether metadata should be written, in a dedicated JP2 XML box' default='NO'/>   <Option name='MAIN_MD_DOMAIN_ONLY' type='boolean' description='(Only if WRITE_METADATA=YES) Whether only metadata from the main domain should be written' default='NO'/>   <Option name='USE_SRC_CODESTREAM' type='boolean' description='When source dataset is JPEG2000, whether to reuse the codestream of the source dataset unmodified' default='NO'/></CreationOptionList>", 'DMD_HELPTOPIC': 'frmt_jp2openjpeg.html', 'DCAP_VECTOR': 'YES', 'DMD_OPENOPTIONLIST': "<OpenOptionList>   <Option name='1BIT_ALPHA_PROMOTION' type='boolean' description='Whether a 1-bit alpha channel should be promoted to 8-bit' default='YES'/>   <Option name='OPEN_REMOTE_GML' type='boolean' description='Whether to load remote vector layers referenced by a link in a GMLJP2 v2 box' default='NO'/></OpenOptionList>", 'DCAP_OPEN': 'YES', 'DCAP_RASTER': 'YES', 'DCAP_VIRTUALIO': 'YES', 'DMD_MIMETYPE': 'image/jp2', 'DMD_CREATIONDATATYPES': 'Byte Int16 UInt16 Int32 UInt32', 'DMD_EXTENSIONS': 'jp2 j2k', 'DCAP_CREATECOPY': 'YES', 'DMD_LONGNAME': 'JPEG-2000 driver based on OpenJPEG library'}

print driver.GetMetadataItem('QUALITY')None
print driver.GetMetadataItem('QUALITY', 'IMAGE_STRUCTURE')None
print driver.GetMetadataItem('DMD_CREATIONOPTIONLIST')<CreationOptionList>   <Option name='CODEC' type='string-select' default='according to file extension. If unknown, default to J2K'>  ......

How can I retrieve the attributes 'QUALITY' and 'REVERSIBLE'?

2) If instead of using the command:jpg_file = jpg_driver.CreateCopy(outjp2file, Raster, options = ['QUALITY=100', 'REVERSIBLE=YES'])

I use the following:jpg_driver.SetMetadataItem('QUALITY','100','IMAGE_STRUCTURE')jpg_driver.SetMetadataItem('REVERSIBLE','YES','IMAGE_STRUCTURE')jpg_driver.Register()jpg_file = jpg_driver.CreateCopy(outjp2file, Raster)

why these two attributes are set as primary keys and not in the options list?
Thank you in advance.Basos 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20151022/773cf842/attachment-0001.html>


More information about the gdal-dev mailing list