2

I tried gdal translate to png:

gdal_translate image.bsq image.jpg -of JPEG -outsize 10% 10% -scale

enter image description here

and jpeg:

gdal_translate image.bsq image.png -of PNG -outsize 10% 10% -scale

enter image description here

jpeg looks better and file size is smaller. In general should I expect poor result with png?

Using the -r cubic and bilinear are almost the same to my eyes:

enter image description here

  • 1
    For having a better control I would give explicit values for -scale. You can read the min/max values of the original with gdalinfo -hist. The viewer may also play a role it it tries to be clever and do automatic stretch for this quite dark image. Anyway PNG is a lossless format and saves the data exactly bit by bit as it comes after scaling. – user30184 May 24 '18 at 8:15
3

PNG should just about always produce a better result than JPG, because PNG is not lossy while JPG is - an important point for anything you're going to do any analysis or computation on. I suspect there's something going on with the interpolation method used as GDAL scales your raster. As the documentation says, the default resampling method (i.e., the -r flag you can specify) is nearest neighbor, which is best for classified or nominal data, but known to make poor products on photograph-like images, or statistical vector surfaces like DEMs. Try re-doing it to PNG, with -r bilinear or -r cubic.

  • Question updated to mention -r. – KcFnMi May 24 '18 at 7:52
  • What are you using to draw the rasters? In my experience, QGIS chooses funny defaults sometimes for pixel enhancement, and by default it doesn't use the first and last 2% of the pixel histogram, so sometimes images with lots of variation just draw as virtually solid black, until you do something like a contrast stretch in the layer properties dialog. – Paulo Raposo May 27 '18 at 1:36
  • I'm not using QGIS. Please can u explain the question? I don't know how to answer. – KcFnMi May 27 '18 at 22:46
  • No prob. In any software, when you're looking at an analytical image like a classified raster or a DEM, what you actually see on your screen is not the pixel values, it's some translation from the pixel values to some RGB value. There are different ways to make that translation, and to purposefully bias certain parts of the original image's pixel values (i.e., histogram). Generally speaking, these translations are "enhancement." Much like filters on photos. I'm guessing that maybe your all-black image is actually correct, but poorly "enhanced." – Paulo Raposo May 28 '18 at 6:58

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.