1

I ran gdal - nearblack on a Landsatlook image with geographic reference as follows:

nearblack -o c:\test\test_nearblack.TIF -of GTiff c:\test\LC08_L1TP_179044_20181228_20181228_01_RT.tif

The input file size is 4 Mb, output is a whopping 173 Mb. Is this expected behaviour? If so, why?

Note that the results is technically all correct, all boundary pixels are neatly set to 0,0,0. It's just that the large resulting large files are less convenient to work with.

I'm using GDAL 2.1.2.

  • 2
    You are creating an uncompressed tiff and if the original was compressed then yes, this is expected. Check the compression of the original with gdalinfo to be sure, but if you have a need to use nearblack your original is probably jpeg compressed. For keeping the exact 0,0,0 values you can only use lossless compression like deflate or LZW. – user30184 Jan 28 at 13:20
2

The magic of compression!
The input file is compressed efficiently (to reduce the volume of data transferred), while the output from GDAL is not compressed at all (due to the default behavior of the software). If you were to efficiently compress the test_nearblack.TIF, you should hopefully get a small file size again, if needed. For efficiently compressing the data, I'd suggest that you look into the concept of Cloud-optimized GeoTIFF / COG - link to turn a raster into a COG, which makes your data smaller, faster, and just plain nicer.

  • The COG recipe may not suit as is because if COMPRESS=JPEG is used then not-exactly-black pixels appear again. – user30184 Jan 28 at 13:50
  • While your point is correct, you should add how to do that: e.g. nearblack -co COMPRESS=DEFLATE -co PREDICTOR=2 – RoVo Jan 28 at 14:08
  • Thanks all for feedback. According to gdalinfo, the source image is indeed compressed 'YCbCr JPEG', whereas the output is not compressed at all. I may look into the compression methdods later, but it's not urgent for now. – HDR Jan 28 at 14:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.