OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.77k stars 2.5k forks source link

JPEG 12-bit compression for NITF Files #10441

Closed chuck1987 closed 3 weeks ago

chuck1987 commented 1 month ago

What is the bug?

Unable to translate to a NITF file with 12-bit JPEG compression.

Steps to reproduce the issue

jpeg12bit_issue

Versions and provenance

Windows 10 GDAL 3.9.1

Additional context

PS C:\OSGeo4W\bin> .\gdalinfo.exe .\11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005_____AAE_0AAAAEAQABC9.NTF Driver: NITF/National Imagery Transmission Format Files: .\11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005_____AAE_0AAAAEAQABC9.NTF Size is 17408, 25600 GCP Projection = GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 GCP[ 0]: Id=UpperLeft, Info= (0.5,0.5) -> (97.4636111111111,39.4805555555556,0) GCP[ 1]: Id=UpperRight, Info= (17407.5,0.5) -> (97.5769444444444,39.4883333333333,0) GCP[ 2]: Id=LowerRight, Info= (17407.5,25599.5) -> (97.5769444444444,39.3480555555556,0) GCP[ 3]: Id=LowerLeft, Info= (0.5,25599.5) -> (97.4644444444445,39.3405555555556,0) Metadata: ICHIP_ANAMORPH_CORR=0 ICHIP_FI_COL=35840 ICHIP_FI_COL_11=0.5 ICHIP_FI_COL_12=17407.5 ICHIP_FI_COL_21=0.5 ICHIP_FI_COL_22=17407.5 ICHIP_FI_ROW=29696 ICHIP_FI_ROW_11=4096.5 ICHIP_FI_ROW_12=4096.5 ICHIP_FI_ROW_21=29695.5 ICHIP_FI_ROW_22=29695.5 ICHIP_OP_COL_11=0.5 ICHIP_OP_COL_12=17407.5 ICHIP_OP_COL_21=0.5 ICHIP_OP_COL_22=17407.5 ICHIP_OP_ROW_11=0.5 ICHIP_OP_ROW_12=0.5 ICHIP_OP_ROW_21=25599.5 ICHIP_OP_ROW_22=25599.5 ICHIP_SCALE_FACTOR=1 ICHIP_SCANBLK_NUM=0 NITF_ABPP=11 NITF_CCS_COLUMN=0 NITF_CCS_ROW=0 NITF_CLEVEL=06 NITF_ENCRYP=0 NITF_FBKGC=126,126,126 NITF_FDT=20160803183704 NITF_FHDR=NITF02.10 NITF_FSCATP= NITF_FSCAUT= NITF_FSCLAS=U NITF_FSCLSY=US NITF_FSCLTX= NITF_FSCODE= NITF_FSCOP=00000 NITF_FSCPYS=00000 NITF_FSCRSN= NITF_FSCTLH=0 NITF_FSCTLN= NITF_FSDCDT= NITF_FSDCTP= NITF_FSDCXM= NITF_FSDG= NITF_FSDGDT= NITF_FSREL= NITF_FSSRDT= NITF_FTITLE=11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005 AAE 0AAAAEAQABC9 NITF_IALVL=0 NITF_IC=C8 NITF_ICAT=VIS NITF_ICORDS=G NITF_IDATIM=20150111050953 NITF_IDLVL=1 NITF_IGEOLO=392850N0972749E392918N0973437E392053N0973437E392026N0972752E NITF_IID1=P13646A000 NITF_IID2=11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005 AAE 0AAAAEAQABC9 NITF_ILOC_COLUMN=0 NITF_ILOC_ROW=0 NITF_IMAG=1.0 NITF_IMAGE_COMMENTS=The imagery and metadata data on this media is the property of DigitalGlobe and is licensed for use only. All use must be in accordance with th e terms of the license that accompanies the media. If the license is purchased under contract NMA 301 99 D003, use is in accordance with the license therein

NITF_IMODE=B NITF_IREP=MONO NITF_ISCATP= NITF_ISCAUT= NITF_ISCLAS=U NITF_ISCLSY=US NITF_ISCLTX= NITF_ISCODE= NITF_ISCRSN= NITF_ISCTLH=0 NITF_ISCTLN= NITF_ISDCDT= NITF_ISDCTP= NITF_ISDCXM= NITF_ISDG= NITF_ISDGDT= NITF_ISORCE=DigitalGlobe NITF_ISREL= NITF_ISSRDT= NITF_IXSOFL=001 NITF_ONAME= NITF_OPHONE= NITF_OSTAID=NDL-W NITF_PJUST=R NITF_PVTYPE=INT NITF_STYPE=BF01 NITF_TGTID= Image Structure Metadata: COMPRESSION=JPEG2000 COMPRESSION_REVERSIBILITY=LOSSY Subdatasets: SUBDATASET_1_NAME=NITF_IM:0:.\11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005_AAE_0AAAAEAQABC9.NTF SUBDATASET_1_DESC=Image 1 of .\11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005_____AAE_0AAAAEAQABC9.NTF SUBDATASET_2_NAME=NITF_IM:1:.\11JAN15WV010400015JAN11050953-P1BS-500827961040_01P005AAE_0AAAAEAQABC9.NTF SUBDATASET_2_DESC=Image 2 of .\11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005_____AAE_0AAAAEAQABC9.NTF RPC Metadata: ERR_BIAS=13.12 ERR_RAND=0.26 LINE_OFF=14463 LINE_SCALE=14464 SAMP_OFF=17589 SAMP_SCALE=17590 LONG_OFF=97.57850000000001 LONG_SCALE=0.1169 LAT_OFF=39.4312 LAT_SCALE=0.0907 HEIGHT_OFF=3961 HEIGHT_SCALE=824 LINE_NUM_COEFF=-0.005422666 0.09938187 -1.143976 -0.04397284 -0.0002439341 4.409867e-05 -0.0001986872 -0.0003423449 0.005090192 -9.303347e-06 -5.441852e-08 -4.219682e-07 -1.914381e-06 -1.152542e-07 7.029517e-06 -1.880859e-05 1.251434e-06 7.947154e-08 3.679618e-08 6.53191e-08 LINE_DEN_COEFF=1 0.0002960222 -0.0003726511 -0.0004706293 -3.347691e-06 4.085567e-07 5.245948999999999e-07 4.673001e-06 3.075842e-06 -1.402771e-06 -7.768435e-07 -3.239675e-08 -9.94948e-06 -1.452598e -08 7.880578e-07 4.002604e-05 1.709959e-07 3.924148e-08 4.632308e-06 0 SAMP_NUM_COEFF=0.005937479 1.019573 -0.0006649771 0.01545805 -0.002330679 0.000746182 -0.0002227314 -0.004814611 -2.672065e-05 2.071569e-06 -4.08515e-07 -6.664038e-07 -4.160226e-05 -1.069338e-05 5.3 25616e-05 4.046575e-05 -7.618402e-08 -6.359322e-06 5.30073e-06 -1.762105e-07 SAMP_DEN_COEFF=1 -0.001157671 0.002383626 -0.0008527916 -2.757647e-05 2.581042e-06 4.37324e-06 4.359518e-06 3.105737e-05 -1.161083e-05 -1.711049e-07 -1.194237e-07 5.343187e-08 -3.007718e-08 4.14557e -07 -5.277856e-08 -5.126068e-08 0 1.566096e-07 1.76113e-08 MIN_LONG=97.4616 MAX_LONG=97.69540000000001 MIN_LAT=39.3405 MAX_LAT=39.5219 Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0,25600.0) Upper Right (17408.0, 0.0) Lower Right (17408.0,25600.0) Center ( 8704.0,12800.0) Band 1 Block=256x256 Type=UInt16, ColorInterp=Gray Overviews: 8704x12800, 4352x6400, 2176x3200, 1088x1600, 544x800, 272x400, 136x200 Metadata: NITF_ISUBCAT=651 Image Structure Metadata: NBITS=11

rouault commented 1 month ago

@chuck1987 What are the minimum and maximum values reported by the -mm option:

gdalinfo.exe -mm .\11JAN15WV010400015JAN11050953-P1BS-500827961040_01_P005_________AAE_0AAAAEAQABC9.NTF
chuck1987 commented 1 month ago

@rouault

Band 1 Block=256x256 Type=UInt16, ColorInterp=Gray Computed Min/Max=0.000,1268.000 Overviews: 8704x12800, 4352x6400, 2176x3200, 1088x1600, 544x800, 272x400, 136x200 Metadata: NITF_ISUBCAT=651 Image Structure Metadata: NBITS=11

rouault commented 1 month ago

Weird, the min/max reported is fine. I can't make sense why you get the "One or more pixels clipped to fit 12bit domain for jpeg output." warning. I'd need access to the input file to investigate further

chuck1987 commented 1 month ago

@rouault That was the first thing I found strange, I even went as far as converting the NITF to a Byte data-type and then trying this, but I get the same warning and error. I assumed by looking at the source, that even if the maximum was greater then 12bit, then we would just clamp the value and it should still work? I was able to get the JPEG 12-bit conversion to work for more basic Single Band Byte NITFs. Any NITF I have with 11-bit JPEG2000 compression however, will not work. The file is to large to add through github, what would be the most convenient way for you to get the file?

rouault commented 1 month ago

The file is to large to add through github, what would be the most convenient way for you to get the file?

dropbox or equivalent file sharing services

chuck1987 commented 1 month ago

The file can be downloaded from here.

https://hawk.compusult.net/gdal_jpeg12_issue.zip