codecs
Not logged in

Back to RasterLite2 doc index



Introduction

RasterLite2 supports many alternative image codecs, each one presenting its own specific characteristics. A good comprehension of the basic features offered by each codec will surely help you in using RasterLite2 at its best.
The following simply is a very quick presentation mainly focused on practical aspects; if you are anyway interested in getting more rigorous and scientific informations you can easily found many exhaustive explanations by searching the Web.

Codec families

  1. the simplest codec you can imagine is NONE: all pixels are directly stored exactly as they are without applying any compression.
    This approach will obviously require an higher storage amount than any other method, but will surely ensure two positive results:
    • fast and very effective processing, due to the absolute absence of any extra overhead imposed by compressing algorithms.
    • absence of any possible artifact; all pixels will be always preserved exactly as they are.
  2. a more sophisticated approach is the one supported by all compressors of the lossless type:
    • any lossless compressor is theoretically required to apply a perfectly reversible transformation.
      i.e. after performing a full compress/decompress cycle the original input values must be exactly restored without any information loss or alteration.
    • some interesting reduction of the required storage amount is always ensured.
      Typically you can expect an ideal compression ratio of about 1:2 (i.e. half of the original uncompressed size), however you have to take this value with a pinch of salt.
      The actual compression ratio will always depend both on the internal statistical distribution of pixel values and on the adopted algorithm; be ready to face a wide range of variability.
    • different compression algorithm have different performances, both in terms of compression ratio and in terms of processing time.
      as a general rule any compression algorithm ensuring a stronger compression will require a longer time to be computed.
  3. and finally we have several compressors of the lossy type:
    • any lossy compression will always imply some kind of irreversible information loss.
      After performing a full compress/decompress cycle you'll never get the original pixels, you'll get instead a more or less severely degraded image.
    • lossy compressors are smartly designed accordingly to the average capabilities of the human eye.
      The degraded image returned by a good quality lossy compressor will apparently look exactly the same of the original one to an human observer.
      Anyway a most rigorous computational approach will certainly detect that many pixels have irreversibly changed their values.
    • all compressors of the lossy type support variable (and freely selectable) compression ratios:
      • very strong compression ratios will always introduce a severe image degradation.
      • bland compression ratios will introduce only a moderate image degradation.
    • all lossy compressors are always expected to ensure very strong compression ratios; surely better than the ones expected by lossless compressors.
    • also in the case of lossy compressors different algorithms have different performances. Some codecs are incredibly fast, others are really slow.


Lossless codecs

the DEFLATE codec

Jack of all trades, master of none,
Certainly better than a master of one.

This codec is based on the same algorithm used by the very popular zip and gzip compression utilities. The RasterLite2 own implementation always applies a Delta Filter so to ensure an optimal compression ratio:

the DEFLATE_NO codec

Exactly the same as DEFLATE except in that it never applies a Delta Filter.


the PNG codec

This codec is based on the popular PNG image format and is fully based on DEFLATE supported by several filters explicitly intended for images.

the LZMA codec

This codec is based on the same algorithm used by the very popular 7-zip compression utility. The RasterLite2 own implementation always applies a Delta Filter so to ensure an optimal compression ratio (exactly the same adopted by DEFLATE).


the LZMA_NO codec

Exactly the same as LZMA except in that it never applies a Delta Filter.


the FAX4 codec

This codec is based on an ultra-specialized compressor originally designed for FAX machines and only supporting 1-bit MONOCHROME pixels.

the LL_WEBP codec

This codec is based on the lossless flavor of the WebP compressor.

the LL_JP2 codec

This codec is based on the lossless flavor of the Jpeg2000 compressor as implemented by the OpenJpeg open source library.

Caveat: the OpenJpeg library has a very long development history (about 10 year long), but only in very recent times has finally become practically usable.
Earlier versions were bug ridden, terribly slow and not at all usable. Using the very recent versions 2.0 or 2.1 is a strict requisite.

Caveat: Jpeg2000 lossless isn't exactly lossless !!!

I've set up a basically simple testbed:
  1. I've created several RasterLite2 Coverages into the same DB-file, each one based on a different lossless codec.
    Except for this all Coverages were created by applying the same identical settings.
  2. then I've populated all these Coverages by inserting exactly the same dataset in all them.
  3. finally I've used a very simple C program performing the following actions:
    • reading and decoding all tiles from the Coverage adopting the NONE compression.
    • reading and decoding all tiles from another Coverage adopting one of the available lossless compressions.
    • compare one by one all corresponding pixels from the NONE tile and from the lossless compressed tile reporting any discrepancy found.
    • perform yet again the same loop on every Coverage adopting some lossless compression.
Actual findings:
  • DEFLATE, PNG and LZMA are effectively lossless, i.e. there is no discrepancy at all when comparing corresponding pixels from the NONE Coverage.
    This is not at all surprising, and simply is a practical confirmation of standard expectations.
  • WEBP too is effectively lossless. This was a not so obvious result and surely is a welcome objective confirmation.
  • unhappily the Jpeg2000 / OpenJpeg compression reveals to be almost lossless but not perfectly lossless.
    There are very few pixels changing their value by exactly 1 unit (sometimes in excess, other times in defect). So the decompressed image isn't exactly the same of the original one, and this forbids to consider this codec as perfectly lossless.
    I personally ignore if this one is a bug in the OpenJpeg implementation or is a defect in the Jpeg2000 design; anyway it surely is a potentially dangerous issue.
Conclusion: never use the Jpeg2000 lossless codec if one of your strict requirements is to be absolutely sure to get back exactly the original input data.




Lossy codecs

the JPEG codec

This codec is based on the very popular JPEG image format.

the WEBP codec

This codec is based on the lossy flavor of the WebP compressor.

the JP2 codec

This codec is based on the lossy flavor of the Jpeg2000 compressor.

Conclusions

lossless codecs

lossy codecs



Back to RasterLite2 doc index