Introduction
Saving images in the jpeg format in .NET is pretty straightforward. However, people
were astounded at the high compression ratios the framework used as default. This
resulted in pretty small image files, but what about the quality of these? The framework
does allow setting the quality factor of the saved images (though not as simply
as it should be, see here),
but the relationship of the quality factor with the compression factors and the
resulting errors in the images is totally different than in most other frameworks
or applications.
A small experiment
I have thus set up a small experiment in which 3 different color calibrated lossless
compressed images were loaded and compressed with the jpg codec in .NET 2.0 using
different quality factors. The resulting compression ratios and average dE* errors
versus the original image are set out in the next graphic.
|
Fig. 1: Compression ratios and average dE* errors versus the original image.
|
|
Fig. 2: Closer look at the low compression ratios and average dE* errors versus
the original image.
|
Discussion
We only used a very small set of images, but a few things are already quite clear.
The highest quality setting (Q = 100) has a compression ratio of around 6-8,
which is about the same as what most digital cameras deliver at their best or highest
JPG quality setting. At these settings dE errors are already 0.5 to 1.2 dE*. Things
go downhill very quickly indeed from that setting, and at Q = 80 we are already
at compression ratios of 35-50, with dE errors around 1-2 dE* units. So it seems
that although the image errors start at rather high values, they do not degrade
very quickly until compression ratios of about 150, where they go up sharply to
10 dE* or more units (Q < 25). As expected, the PNG lossless compression is about
2-4, but with 0 dE error of course!
Conclusion
The default compression of the .NET framework is not badly set, delivering very
good compression for reasonable image errors. However, higher quality factors seem
to improve the image quality only slightly, at the expense of much bigger file sizes.
For applications where color information is crucial, quality factors of at least
90-95 should be used, or better still, lossless compression.