Amy Pearson Amy is a Java developer and member of the support team. Her main technical interests are JavaFX and Cloud. Out of hours she enjoys gaming and Virtual reality.

Are you a Java Developer working with Image files?

Read and write images in Java with JDeli

Comparing WebP compression algorithms

1 min read

WEBP icon

In this article we will be comparing the different compression methods available to use for WebP images. To do this, we will be using our Java image library, JDeli. We will be comparing file size, quality of output, and speed.

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

What types of compression does WebP support?

Unlike most other image formats, WebP has both a lossless and lossy compression format. Which is best for you all depends…

What is Lossy compression?

Lossy compression is known as the irreversible compression due to the fact some data is removed.  The process uses the VP8 prediction code commonly used for videos which includes the algorithm DCT (Discrete cosine transform) to then be able to remove redundant data. This does mean quality loss can sometimes be expected but is usually not visible, also something to bear in mind you cannot return to the original quality once you have applied this compression. The advantage is that this compression can reduce the file size much more effectively.

Using lossy compression reduced the file size to 6KB and took just under 2 seconds, and the quality was set to a default of 75.

What is Lossless compression?

This compression unlike lossy, preservers the original data so when decoded can return the file to its original form. To achieve this, multiple transformations are made including several color transforms along with a spatial transform and then finished off by applying a form of entropy coding known as LZ77 huffman coding. This does then mean that the reduction in file size won’t be as significant but that is not always the most important aspect when compressing.

Using lossless compression reduced the file size to 67KB and also took just under 2 seconds.

Conclusion

As we can see the lossy far out ranks the lossless compression due to the much smaller file size for similar quality. If file size is your main focus lossy would be your first choice but if you want to be able to return to the original image than the hit of an extra 61KB wouldn’t matter as much especially when they both take the around the same time to complete.



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 >>

Amy Pearson Amy is a Java developer and member of the support team. Her main technical interests are JavaFX and Cloud. Out of hours she enjoys gaming and Virtual reality.

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