Question About JPEG Compression

Started Jan 28, 2013 | Questions thread
Doug Pardee
Veteran MemberPosts: 7,453Gear list
Like?
Re: Question About JPEG Compression
In reply to tclune, Jan 28, 2013

A few embellishments...

tclune wrote:

First and foremost, JPEG is only 8 bits per channel. Most cameras are 12 to 14 bits per channel, athough some of those bits may be "in the noise," especially if you are shooting above the base ISO.

I think maybe the most significant thing here is that JPEG conversion usually throws away the top stop or 1-1/2 stops, as well as the "in the noise" shadows. So there's one or two bits taken off the bright end, and probably two or three off the dark end. The rest is mostly made up for by using a gamma curve to reduce the number of discrete values used at the bright end.

The total loss of detail in the extreme highlights may be the biggest ​visible ​loss in JPEG conversions. Some DSLR models offer features to try to reclaim some of that highlight detail for JPEG output by compressing highlights into a soft roll-off rather than hard-clipping them to white.

Second, the usual JPEG encoding converts the R G B data to Y Cr Cb (Y is grayscale and Cr and Cb are two channels that encode the color). Most commonly, every other value of the Cr and Cb channels are thrown away (this is called 4:2:2 encoding).

That encoding is generally used on cameras with Bayer sensors, where the red and blue filters only appear at every other sensor element. Very little data is lost in this case.

the resulting data is low-pass filtered (the so-called lossy step of JPEG) so that a lot of the frequency components will end up going to 0.

I think a better description is that the levels are tweaked a bit to make them compress better. For example, a given frequency coefficient might be divided by 10 (and rounded), so that instead of 0 to 255 it only goes from 0 to 26. Very low levels — 1 through 4 in this example — do get adjusted to 0 in the rounding. Modern DSLRs generally divide down by 3, maybe 5, at most.

Of course, when the JPEG is displayed the values get multiplied back up.

In practice, higher-frequency changes are tweaked considerably more aggressively than gradual changes are. For example, neighboring pixels with "green" levels of 123 and 125 might both end up at 124, but if the overall green-ness of the 8x8 block was 125, it'll almost certainly end up at 125 and not 124 or 126 (for quality cameras). With the divisor selections commonly used in today's enthusiast and pro cameras, the effect of the tweaking is very similar to noise reduction, a bit heavier on chroma noise than on luminance noise.

[Notice that in-camera JPEG conversion tends to clip off the noisiest shadows, and then effectively applies a bit of noise reduction through the JPEG compression process. Those are two reasons that Raw files often look a lot noisier than in-camera JPEGs from the same camera do.]

you may be compressing the file as 4:4:4 JPEG, in which the encoding has one Cr and one Cb value for every Y value. But, since the original JPEG image was 4:2:2 (or even 4:1:1 in some cases), all your image processing software is doing is repeating the Cr and Cb values unnecessarily

Indeed, that's very likely. Adobe generally uses 4:4:4 for all commonly-used quality settings (7 through 12). The size increase at 4:4:4 is so large that Adobe chose to make their compression ​worse​ at quality level 7 than at 6, in order to keep from getting a big jump in file size between those two levels. Adobe level 7 is not a good choice.

Once you've started processing the image, it's quite possible that the resulting Cr and Cb values differ between neighboring pixels. So the 4:4:4 is only wasteful duplication when storing an unmodified JPEG, which there probably isn't much reason to do.

-- hide signature --

The open-source LightZone Project: http://lightzoneproject.org/

 Doug Pardee's gear list:Doug Pardee's gear list
Olympus Stylus 1030 SW Canon EOS 350D Canon EF-S 17-85mm f/4-5.6 IS USM Adobe Photoshop Elements 10 Snapseed +20 more
Reply   Reply with quote   Complain
Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark post MMy threads
Color scheme? Blue / Yellow