[gdal-dev] Reading a JP2 file - obj_decode() failed

Jonathan Moules jonathan-lists at lightpear.com
Sun Aug 9 04:47:33 PDT 2020


Hi Even,
Thanks for getting back to me. I'm a little rusty with GDAL; it has 
probably been 5+ years since I last used it.

I can confirm my QGIS install version (OSGEO4W) does have the JP2ECW 
driver (`gdalinfo --formats`).

I'm using the Python GDAL build from 
https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal - doesn't say it 
includes JP2ECW. I only have access to that GDAL build via Python but 
haven't managed to figure out what the Python API equivalent of 
"gdalinfo --formats" is (assuming there is one).

I don't seem to be able to force JP2OpenJPEG on the OSGeo4W one.
gdalinfo --config GDAL_SKIP JP2ECW FILENAME.jp2   = uses the MrSID driver
gdalinfo --config GDAL_SKIP JP2ECW --config GDAL_SKIP JP2MrSID 
FILENAME.jp2   = Goes back to JP2ECW
(Doesn't support the -if flag).

But I found `gdal.Info("FILENAME.jp2")` on the Python version, and that 
does use the JP2 OpenJPEG driver. No tile information on there:

     Driver: JP2OpenJPEG/JPEG-2000 driver based on OpenJPEG library
     ...
     Image Structure Metadata:
       INTERLEAVE=PIXEL
     ...
     Band 1 Block=1024x1024 Type=Byte, ColorInterp=Red
       Overviews: 66000x124000, 33000x62000, 16500x31000, 8250x15500, 
4125x7750, 2063x3875, 1032x1938, 516x969, 258x485, 129x243, 65x122
       Overviews: arbitrary
       Image Structure Metadata:
         COMPRESSION=JPEG2000
     ...

I can't help but notice the block size and overview levels are reporting 
different info compared to the JP2ECW output (ECW one has different 
rounding <= 2062*3875):

     Band 1 Block=256x256 Type=Byte, ColorInterp=Red
       Description = Red
       Overviews: 66000x124000, 33000x62000, 16500x31000, 8250x15500, 
4125x7750, 2062
     x3875, 1031x1937, 515x968, 257x484

and JP2MrSID for comparison:
     Band 1 Block=1024x128 Type=Byte, ColorInterp=Red
   Min=168.000 Max=255.000
   Minimum=168.000, Maximum=255.000, Mean=243.359, StdDev=16.164
   Overviews: 66000x124000, 33000x62000, 16500x31000, 8250x15500, 
4125x7750, 2063
x3875, 1032x1938, 516x969, 258x485, 129x243, 65x122, 33x61
   Metadata:
     STATISTICS_APPROXIMATE=YES
     STATISTICS_MAXIMUM=255
     STATISTICS_MEAN=243.35889029004
     STATISTICS_MINIMUM=168
     STATISTICS_STDDEV=16.164314681862
     STATISTICS_VALID_PERCENT=100

All three report different Overview levels too. Odd but no idea if it is 
pertinent to this problem.

Cheers,
Jonathan

p.s. I was looking for Python API docs but it seems there aren't any. 
This page:
https://pypi.org/project/GDAL/#usage - has a link to 
http://www.gdal.org/gdal_tutorial.html, but that's a 404. I think it 
wants to be: https://gdal.org/tutorials/index.html



On 2020-08-09 11:14, Even Rouault wrote:
>
> Jonathan,
>
> The GDAL build that comes with rasterio must have only JP2OpenJPEG 
> enabled (the error with opj_decode() comes from that driver), whereas 
> the GDAL build in QGIS has also JP2ECW, which is used in priority.
>
> The file is large. It would be interesting to know if it is tiled. If 
> you do "gdalinfo --format FILENAME.jp2 --config GDAL_SKIP JP2ECW", and 
> look at the beginning of the output, you should see lines like
>
> OPENJPEG: nTileW = XXXX
>
> OPENJPEG: nTileH = XXXX
>
> which values are reported ?
>
> If it is tiled (values <= 2048 let's say), this should normally work. 
> Openjpeg will have more difficulties with single-tile JPEG2000 files, 
> although latest versions (2.3.1) have seen improvements in that regard
>
> Even
>
> -- 
>
> Spatialys - Geospatial professional services
>
> http://www.spatialys.com
>



More information about the gdal-dev mailing list