JPEG Compression

sophielwang.com

274 points by vinhnx 4 days ago


chromakode - 4 hours ago

The DCT is a cool primitive. By extracting the low frequency coefficients, you can get a compact blurry representation of an image. This is used by preload thumbnail algorithms like blurhash and thumbhash. It's also used by some image watermarking techniques to target changes to a detail level that will be less affected by scaling or re-encoding.

I made a notebook a few years back which lets you play with / filter the DCT coefficients of an image: https://observablehq.com/d/167d8f3368a6d602

Paulo75 - 13 minutes ago

The part about green getting 58.7% weight in the luminance calculation is one of those details that seems arbitrary until you realize it's literally modeled on the density of cone cells in the human retina. The whole algorithm is basically a map of what human eyes can't see.

dipflow - 3 hours ago

Whenever I see those 'blocky' artifacts on a low-quality image, I used to just think of it as 'bad tech.' After reading this, it's cool to realize you're actually seeing the 8x8 DCT grid itself. You're literally seeing the math break down because there wasn't enough bit-budget to describe those high-frequency sine waves. It’s like looking at the brushstrokes on a digital painting.

danwills - 5 hours ago

Having played a bit with Discrete FFT (with FFTW on 2D images in a Shake plugin we made at work ages ago) makes the DCT coefficients make so much more sense! I really wonder whether the frequency-decomposition could happen at multiple scale levels though? Sounds slightly like wavelets and maybe that's how jpeg2000 works?.. Yeah I looked it up, uses DWT so it kinda sounds like it! Shame it hasn't taken off so far!? Or maybe there's an even better way?

bambax - 5 hours ago

So the idea behind JPEG is the same as behind MP3: we filter out what we don't perceive.

I wonder if other species would look at our images or listen to our sounds and register with horror all the gaping holes everywhere.

petercooper - 3 hours ago

I've been working on a pure Ruby JPEG encoder and a bug led me to an effect I wanted. The output looked just like the "crunchy" JPEGs my 2000-era Kodak digital camera used to put out, but it turns out the encoder wasn't following the zig-zag pattern properly but just going in raster order. I'm now on a quest to figure out if some early digital cameras had similar encoding bugs because their JPEG output was often horrendous compared to what you'd expect for the filesize.

mdavid626 - 36 minutes ago

JPEG still rules the world. Many new alternatives were developed, none of them really that much better than JPEG.

vanderZwan - 3 hours ago

This is a really great article, and I really appreciate how it explains the different parts of how JPEG works with so much clarity and interactive visualizations.

However, I do have to give one bit of critique: it also makes my laptop fans spin like crazy even when nothing is happening at all.

Now, this is not intended as a critique of the author. I'm assuming that she used some framework to get the results out quickly, and that there is a bug in how that framework handles events and reactivity. But it would still be nice if whatever causes this issue could be fixed. It would be sad if the website had the same issue on mobile and caused my phone battery to drain quickly when 90% of the time is spent reading text and watching graphics that don't change.

meindnoch - 4 hours ago

What would happen if the Cr and Cb channels used different chroma subsampling patterns? E.g. Cr would use the 4:2:0 pattern, and Cb would use the 4:1:1 pattern.

Alen_P - 2 hours ago

Really enjoyed this. It's easy to forget how much engineering went into JPEG. The explanation of compression and quality tradeoffs was clear without oversimplifying. Impressive how well the format still holds up today. Curious how you think it compares to newer formats like AVIF or WebP in everyday use.

vmilner - 2 hours ago

The weirdest thing to me is that the quantisation matrix isn’t symmetrical in the top left to bottom right diagonal.

tmilard - 4 hours ago

Thanks for the sharing : I now understood more how sampling of image works. And going from RGB to lunimesence+chroma works. interesting and usefull

NooneAtAll3 - 5 hours ago

> Application error: a client-side exception has occurred (see the browser console for more information).

seems like website doesn't work without webgl enabled... why?

jbverschoor - 5 hours ago

Application error: a client-side exception has occurred (see the browser console for more information).

qy-mj - 2 hours ago

Wow, that's amazing! How did you do that? Where do you learn it?

7777777phil - 6 hours ago

Already posted here earlier: https://news.ycombinator.com/item?id=47376119

tomalaci - 5 hours ago

I usually have a script/alias cmd to automatically convert images to webp. The webp format has pretty much replaced jpg/jpeg (lacks transparency/alpha support) and png (no compression) formats for me.

There is also AVIF format which is newer and better but it needs to still mature a bit with better support/compatability.

If you are hosting images it is nice to use avif and fallback to webp.