Are you a Java Developer working with Image files?

Read and write images in Java with JDeli

Comparing TIFF Compression Algorithms

1 min read

Different compression algorithms you can use within TIFF files

In this article, we will be exploring the different compression algorithms you can use within TIFF files. We will investigate their effect on different metrics such as file size, quality of output, and speed. We will be using our image library JDeli to generate the sample images.

For the baseline of our comparisons, we will use the following uncompressed image. It has a file size of 39.3MB. It takes just under 5 seconds to encode.

JPEG

First introduced in the 90s, JPEG has remained a popular compression format for images due to its decent tradeoff between quality and file size. JPEG is lossy meaning you cannot recover the original pixel data from the compressed image.

 

.

Straight off the bat, we see a dramatic reduction in file size: 1.2MB! Even with this tiny file size, the quality of the image is only slightly worse than the original. Viewing at its default resolution, it is hard to tell the difference, however upon zooming in you will notice a less sharp image with slightly more noise and artefacts. Using JPEG compression, the encoding takes around 5 seconds, it is almost as quick as the original.

 

LZW

Lempel–Ziv–Welch (named after its creators) was introduced in 1984, and is used today by Unix’s compress program. It is also the compression algorithm used in GIF images.

Using LZW compression, we observe a file size of 18MB. Since LZW is lossless, there is no reduction in the quality of the image. Like JPEG, encoding with LZW takes around 5 seconds.

An interesting quirk about LZW is that is has the potential to make file sizes bigger. An image with lots of noise will not see a reduced file size if compressing it with LZW. Consider the following image:

The original has a file size of 4.7MB. However when compressed using LZW it has a file size of 5.1MB.

 

DEFLATE

DEFLATE was also designed in the 90s and is popular in PNG images and also the ZIP archive format.

Using DEFLATE, the file size is reduced to 14.4MB. Like LZW, DEFLATE is lossless, so the quality of the compressed image remains the same as the original. The downside of DEFLATE however, is that it takes much longer to encode at a time of 18 seconds!

 

Conclusion

In conclusion, there is no ultimate compression algorithm that solves all problems. JPEG is best if you want a tiny file size with a small reduction in quality however LZW and DEFLATE are necessary if you want to preserve the original image. LZW encodes slightly larger than DEFLATE but is much faster so the answer will depend on your use case.



Find out how to read and write images files in Java with JDeli:

Read: BufferedImage image = JDeli.read(streamOrFile);

Write: JDeli.write(myBufferedImage, OutputFormat.HEIC, outputStreamOrFile)

Learn more >>

What is JBIG2?

JBIG2 is a lossless and lossy compression standard for bi-level images like scanned documents, offering high compression ratios by identifying and encoding similar shapes...
chika
47 sec read