I have used this batch script

for /r %%g in (*.jp2) do gdal_translate -co COMPRESS=LZW -co 
NUM_THREADS=ALL_CPUS %%g %%~dpng.tif

to recursively convert all my .jp2 files in .tif files. However, the output .tif file doesn't have exact pixel values as the original .jp2 image (see in the picture). Change of the pixel values on two examples

On the left side is an example on a 10 meter resolution raster, and on the right the same problem is present in the 20 meter raster.

How can i correct this issue?

I need the tif files to have the exact same values as the original.

  • 1
    What driver do you use to decode jp2? – dr_times Oct 30 '17 at 12:16
  • Check the supported drivers with gdalinfo --formats, The first JP2 driver on the list is the one that is used by default. You can select the next drivers on the list by skipping drivers with --config GDAL_SKIP=driver1,driver2,..., – user30184 Oct 30 '17 at 16:05
  • Then this one is the default 'JP2ECW -raster,vector- (rov): ERDAS JPEG2000 (SDK 5.3)', and the the next ones are 'JP2MrSID -raster- (rov): MrSID JPEG2000', 'JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on OpenJPEG library'. As soon as i test the results of these options I will send the feedback. – davor korman Oct 30 '17 at 16:27
  • 1
    Check also from the QGIS side that there is no Layer-Properties-Style that there is no Contrast enhancement applied and that the other settings are similar for the both layers. For exaple the Contrast enhancement can give different results if the view windows are not exactly the same. For reliable results you can calculate the difference of images with raster calculator. BTW. do you know if the JPEG2000 file has lossy or lossless compression? – user30184 Oct 30 '17 at 17:24
  • Indeed, it was the QGIS causing the problems for me. The thing with the contrast enhancments in my situation though (I am dealing with Sentinel imagery), is that if I set it to none, as a result I get the black screen. I have calculated the difference wit the raster calculator, and as a result i get a black raster with all zeroes which means that the rasters are the same, thus the conversion to tif was without errors. The sentinel imagery handbook says the images can have either none, lossy or lossles compression. Btw do you know if there is a way to show the true values of the pixels in QGIS? – davor korman Oct 31 '17 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.