What is the difference between lossy and lossless compression?
We often divide image compression into two categories – lossy and lossless compression.
Lossy compression reduces file size by permanently eliminating certain information. Specifically, it eliminates redundant information, even though the user may not notice it. For example, JPEG is a format that uses lossy compression.
However, lossless compression retains raster values during compression. At the same time, it still ma ages to reduce file size. For example, LZ77 is a lossless compression file type.
Let’s compare both image compression methods and their potential uses in GIS.
When should you use lossy and lossless compression?
In GIS, lossy compression data is good for background images because it has faster loading speeds with lower compression ratios. You should not choose lossy compression if you want to perform further analysis on the data.
Lossy compression algorithms often result in greater reductions of file size. It’s often the case that the human eye cannot distinguish between lossless and lossy compression. Lossy image compression offers the best compression ratios with good enough approximations.
On the other hand, lossless compression reduces file size but retains redundant information after compression. For example, LZ77 is a type of lossless compression.
Lossless compression is good if there will be new analysis on the data. This is because it doesn’t alter any of the original values. This means that it’s good for discrete data or any raster image that is already lossy compressed.
JPEG Compression Example
JPEG stands for Joint Photographic Experts Group, which is the group that created the standard. It has an extension of .JPG and .JPEG and is the most common image format used by digital cameras and on the World Wide Web.
It’s a lossy compression type for digital images. Lossy image compression reduces file size and eliminates redundant information. The user decides how much loss to introduce with a trade-off in storage size and quality.
For example, the compression quality is a range from 1 to 100. A lower value compresses the raster image, but also reduces the quality.
JPEG 2000 (JP2) is the newest version of JPEG. It slightly improves image compression performance over JPEG using two different wavelet transforms. Users can choose low to high levels of compression.
LZ77 Compression Example
LZ77 compression is a lossless image compression meaning it maintains raster values during compression.
Abraham Lempel and Jacob Ziv introduced this format in 1977 and we still use it today. Combining the first letter from both last names (LZ) and the year it was invented (1977), this is how the acronym (LZ77) was created.
It uses the same commission algorithm as PNG (Portable network graphic). Also, it’s the default raster GIS compression that ArcGIS uses.
The theory behind LZ77 image compression is that repeat values in a raster image are stored according to their position and length. Instead of storing single values for each cell, LZ77 simply stores where the value was found and how long the string of values are.
MrSID vs ECW
JPEG 2000 can achieve a compression ratio of 20:1 which is similar to MrSID and ECW format.
We commonly use LizardTech’s proprietary MrSID (Multiresolution Seamless Image Database) for orthoimages and basemaps. MrSID images have an extension of SID and are accompanied with a world file with the file extension SDW.
MrSIDs have impressive compression ratios. Color images can be compressed at a ratio of over 20:1. LizardTech’s GeoExpress is the software package capable of reading and writing MrSID format.
ECW (Enhanced Commission Wavelet) is a compressed image format typically for aerial and satellite imagery. This GIS file type is known for its high-compression ratios while still maintaining quality contrast in images.
ECW format was developed by ER Mapper, but it’s now owned by Hexagon Geospatial.
Lossless compression retains values and manages to lower file size.
However, lossy compression reduces file size by eliminating redundant information.
While LZ77 is an example of a lossless compression, JPEG is an example of a lossy compression.
Depending on your intended uses, you have to choose lossy or lossless compression appropriately.