wiki:UserDocs/JPEG2000Utils

JPEG2000 utilities

The utilities in this page require GDAL 2.0 or later.

validate_jp2.py

This scripts analyzes the structure of a JPEG2000 and reports potential violations of application standards: errors JP2 boxes, erros JPEG2000 code stream, errors in GMLJP2, violations of Inspire Technical Guidelines on Orthoimagery.

Installation steps

GDAL binaries with Python bindings must be installed.

(Windows) Let's begin with Python if not already done. Select one of the following packages depending on the wished architecture :
Windows x86 MSI installer or
Windows x86-x64 MSI installer

If not already available, the Python 'lxml' module, used for XML validation, must also be installed (from the console):
python -m pip install lxml (Windows) or
pip install lxml (Linux)

(Windows) Then install GDAL core and the GDAL Python bindings :
32-bit architecture :
Generic installer for the GDAL core components
Installer for the GDAL python bindings (requires to install the GDAL core)
64-bit architecture :
Generic installer for the GDAL core components
Installer for the GDAL python bindings (requires to install the GDAL core)

The following scripts must be downloaded in a directory :
http://svn.osgeo.org/gdal/trunk/autotest/pymod/gdaltest.py : contains routines to download and unzip packages
http://svn.osgeo.org/gdal/trunk/autotest/pymod/gdaltest_python2.py : for Python 2 or
http://svn.osgeo.org/gdal/trunk/autotest/pymod/gdaltest_python3.py : for Python 3
http://svn.osgeo.org/gdal/trunk/autotest/pymod/xmlvalidate.py : used for XML validation of GMLJP2 boxes
http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/validate_jp2.py : main script

On Windows, launch the SDKShell and go to the directory where the scripts have been downloaded.

A few tests rely on validate GMLJP2 boxes, which as XML content. Therefore the OGC schemas must be downloaded with :
python xmlvalidate.py -download_ogc_schemas

Optional step: if you intend to validate a Orthoimagery XML document, you must also download the Inspire schemas with:
python xmlvalidate.py -download_inspire_schemas

The validate_jp2.py script is now ready to be used.

How to use ?

The script takes a JPEG2000 filename as argument and options :

  • -inspire_tg: asks to run checks related to the Inspire Technical Guidelines on Orthoimagery
  • -oidoc name_of_a_oidoc.xml: XML document conforming with Inspire Orthoimagery GML application schema.
  • -ogc_schemas_location: Path to directory with OGC schemas. Needed for GMLJP2 validation. If the OGC schemas have been downloaded as indicated above, validate_jp2.py will automatically find them.
  • -expected_gmljp2: hint to indicate that a GMLJP2 box should be present

If the script doesn't output any message, it means that all tests have successfully completed and the return code of the script will be 0 (for success).

On Windows, launch the SDKShell and go to the directory where the scripts have been downloaded.

Examples (files available in http://svn.osgeo.org/gdal/trunk/autotest/gdrivers/data/test_validate_jp2/):

  • python validate_jp2.py byte.jp2: basic validation
  • python validate_jp2.py -inspire_tg byte.jp2: basic validation + Inspire TG validation
  • python validate_jp2.py -inspire_tg -oidoc byte_oi.xml byte.jp2: basic validation + Inspire TG validation + Check consistency with provided Orthoimagery description file

Validate a Orthoimagery XML document

python xmlvalidate.py byte_oi.xml: if the script doesn't output any message, it means that the XML document is valid

dump_jp2.py

This scripts displays the structure of a JPEG2000 file and enables to extract some information from it.

Installation steps

The installation steps of validate_jp2.py that cover Python, GDAL and GDAL Python bindings installation are sufficient for dump_jp2.py

Iin addition, the following script must be also downloaded in a directory :
http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/dump_jp2.py

How to use ?

The script takes a JPEG2000 filename as argument and options :

  • -dump_gmljp2 filename.xml: writes the content of the GMLJP2 box, if it exists, in the specified file
  • -dump_crsdictionary filename.xml: Writes the content of the GML CRS dictionary box, if it exists, in the specified file
  • -extract_all_xml_boxes: Extract all XML boxes in separate files, and prefix each filename with the supplied prefix. gmljp2://xml/ link will be replaced by links to on-disk files.

On Windows, launch the SDKShell and go to the directory where the scripts have been downloaded.

Examples:

  • python dump_jp2.py byte.jp2: displays the structure of byte.jp2 in a XML format
  • python dump_jp2.py -dump_gmljp2 byte_gmljp2.xml byte.jp2: extract the GMLJP2 box of byte.jp2 into byte_gmljp2.xml
  • python xmlvalidate.py byte_gmljp2.xml: if the script doesn't output any message, it means that the XML document is valid

build_jp2_from_xml.py

This scripts builds a JPEG2000 file from an XML description of its structure. This script is not intended for widespread usage, but more for developers to be able to generate non-conformant files for example.

Installation steps

The installation steps of dump_jp2.py that cover Python, GDAL and GDAL Python bindings installation are sufficient for build_jp2_from_xml.py

In addition, the following script must be also downloaded in a directory :
http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/build_jp2_from_xml.py

How to use ?

The scripts takes 2 arguments: the first one is the name of a XML file (typically the output of dump_jp2 with manual modifications) and the second one is thae name of the output JPEG2000 file

On Windows, launch the SDKShell and go to the directory where the scripts have been downloaded.

Example (files available in http://svn.osgeo.org/gdal/trunk/autotest/gdrivers/data/test_validate_jp2/):

* python build_jp2_from_xml.py byte_corrupted.xml byte_corrupted.jp2: Builds byte_corrupted.jp2 frmo byte_corrupted.xml. Note that you must also have byte.jp2 next to byte_corrupted.xml since the later references the former

Non-GDAL JPEG2000 aware tools

Last modified 5 years ago Last modified on Dec 17, 2015, 1:12:07 PM