[Digikam-users] re JPEG lossiness, PNG

Jean-François Rabasse jean-francois.rabasse at wanadoo.fr
Sat Jan 14 16:15:33 GMT 2012


Hello all,

Some comments about that files formats discussion and a recurrent
issue, "JPEG or not JPEG ? ".

It's often said that JPEG is a lossy format. Well, no, not exactly.
The JPEG standard features compression algorithms, as other images
formats do, GIF, PNG et al. And a compression algorithm is just a way to
reorganise the same data in a more clever way, in order to save space.

What is particular to JPEG is that the standard provides also means to
increase compression efficiency if the user accepts slight
simplifications to data, making the compression algorithm give better
results regarding the final size. Consequent data loss is neither a
weakness of the standard nor a fatality, it's a feature, and an optional
feature, when final small size is important.

The major idea in data compression with slight losses is to consider
slightly different pixels as identical, thus increasing dramatically
compression techniques based on similar data re-encoding (this concerns
Run Length Encoding, Huffman groups tables and others). Of course,
doing this leads to loose the initial full information,
the transformation "almost similar pixels" into "same pixels" is not
reversible. But it's up to the user to choose, or not, to do this,
according to a final satisfying visual quality.

JPEG can compress in a lossless way, until the algorithm bumps against
some limits. GIF does so, PNG does so. But JPEG can boost compression
efficiency if the user accept some losses.
That's what Marie-Noëlle Augendre said, on this thread :
"I guess that to produce something smaller, you'll have to loose
something."
Definitely right, there's no magic at all, and Santa Claus doesn't
exist:-)

JPEG has been initially elaborated by and for photographers. And a
photography is never intended to be measured with instruments, but to be
looked at by human eyes. Thus, the JPEG philosophy is : if you don't see
the difference, do it and save file size and disk space.

And there's no definitive algorithm to determine that "satisfying visual
quality", but the user's eye. That's why JPEG writing programs provide
the option to select final quality.

If one selects the best, 100% quality, there won't be data loss but the
final file size won't be that small, comparable to the size of the same
image saved in PNG format.

If one selects, says 90% quality, there will be some data loss but the
final file will be significantly smaller. It's a user choice, not a
JPEG format intrinsic fatality.

Paul Verizzo wrote on this thread :
"I also save all files with 100% quality level, or whatever the "no
compression" setting is for whatever program you are using."
Right. I do the same thing. Just to point that the "no compression"
setting in programs is to be understood as "Use standard compression
lossless techniques but keep all my image data intact, don't boost over
the limit". That's what do PNG compression algorithms.

Problems may arise, as was mentioned by Andrew Goodbody :
"Yes, you will lose more information every time you re-save a jpg file."
That's true because most JPEG writing programs have a default preset value
of 90% or 95% for quality. (Some, as The GIMP, evaluate an optimal quality
according to the current picture.) And in that case, of course, several
re-writing will have a cumulative effect, 90% of 90% of 90% etc.

(Btw this default setting of 90%, choosen on a standard image use basis,
may probably be the reason of the "lossy" JPEG reputation.)

But if you configure your program to use 100% quality, you can re-write
tens of times, without loss. (But with larger files, obviously, as said
above, Santa Claus doesn't exist.)

I fully agree with Paul when he says : "Again, disk space is so cheap."
And my personal opinion is that JPEG used in 100% quality mode, i.e.
no data loss, is a good disk storage format, equivalent to PNG.
Anyway it's the same image data.

Space considerations become relevant when one uses the web, because
files sizes means disk space on the web hosting and transmission time
and bandwidth use when a visitor looks at the images pages. And in that
context, it's useful to ask the good question "What do I want to do with
my images on my web album(s) ? " In most cases, photos displayed on web
pages will have reasonable dimensions, 600 to 700 pixels width is a
common size, well suited to a standard HTML page.

Such dimensions allow good looking images, but too small to pretend
begin "print quality". So, probably, we should not focus strictly on
image quality and data loss or not, for such usage. A good practise
could be :

1. Keep original images in original size, and without data loss, TIFF,
or PNG, or JPEG at 100% quality.

2. Build specific "web variants" of your images, at significant lower
size and compressed efficiently for faster upload, smaller hosting
space, and faster download for visitors. (400 to 600 Kbytes images is
fine, 5 to 7 Mbytes images can be a nightmare for people that have a
slow ADSL connection.)
The compression, or image quality, could be tuned by hand and eye,
via testing with different quality factors, 95%, 90%, 85%, etc. as long
as the result looks acceptable.

Also, instead of uploading to web albums original big photos files, building
specific web versions allows to downsize a bit more by stripping all non
image informations (all metadata sections) and allows also building
progressive JPEG, and this is appreciated by users with a slow connection,
image loading/display is smoother and the visual effect more pleasant.

My conclusion would be : Don't throw JPEG to the trashcan:-) It's a
powerful standard, thought and designed for photography, and can be used
in different ways according to what you want to do; keep original image
data in your archives or show your images on the web. Two different
problems, so two different uses.

Best,
Jean-François


More information about the Digikam-users mailing list