HN Theater @HNTheaterMonth

The best talks and videos of Hacker News.

Hacker News Comments on
The Unreasonable Effectiveness of JPEG: A Signal Processing Approach

Reducible · Youtube · 106 HN points · 0 HN comments
HN Theater has aggregated all Hacker News stories and comments that mention Reducible's video "The Unreasonable Effectiveness of JPEG: A Signal Processing Approach".
Youtube Summary
Visit https://brilliant.org/Reducible/ to get started learning STEM for free, and the first 200 people will get 20% off their annual premium subscription.

Chapters:
00:00 Introducing JPEG and RGB Representation
2:15 Lossy Compression
3:41 What information can we get rid of?
4:36 Introducing YCbCr
6:10 Chroma subsampling/downsampling
8:10 Images represented as signals
9:52 Introducing the Discrete Cosine Transform (DCT)
11:32 Sampling cosine waves
12:43 Playing around with the DCT
17:38 Mathematically defining the DCT
21:02 The Inverse DCT
22:45 The 2D DCT
23:49 Visualizing the 2D DCT
24:35 Introducing Energy Compaction
26:05 Brilliant Sponsorship
27:23 Building an image from the 2D DCT
28:20 Quantization
30:23 Run-length/Huffman Encoding within JPEG
32:56 How JPEG fits into the big picture of data compression

The JPEG algorithm is rather complex and in this video, we break down the core parts of the algorithm, specifically color spaces, YCbCr, chroma subsampling, the discrete cosine transform, quantization, and lossless encoding. The majority of the focus is on the mathematical and signal processing insights that lead to advancements in image compression and the big themes in compression as a whole that we can take away from it.

Animations created jointly by Nipun Ramakrishnan and Jesús Rascón.

References/Additional Resources:
https://www.red.com/red-101/video-chroma-subsampling - great resource on different types of chroma subsampling

http://weitz.de/dct/ - play around with the DCT

https://www.cse.iitd.ac.in/~pkalra/col783-2017/DCT-History.pdf - paper referenced in video

http://www.ee.ic.ac.uk/hp/staff/dmb/courses/DSPDF/00300_Transforms.pdf - a more rigorous signal processing approach to the DCT

https://www.impulseadventure.com/photo/jpeg-huffman-coding.html - great landing point for learning more about how huffman codes work in the context of JPEG

https://www.youtube.com/watch?v=CPT4FSkFUgs&list=PLpsTn9TA_Q8VMDyOPrDKmSJYt1DLgDZU4&ab_channel=DanielHarding - a great playlist I recommend that dives deep into actually implementing a JPEG decoder

This video wouldn't be possible without the open source library manim created by 3blue1brown and maintained by Manim Community.
The Manim Community Developers. (2021). Manim – Mathematical Animation Framework (Version v0.11.0) [Computer software]. https://www.manim.community/

Here is link to the repository that contains the code used to generate the animations in this video: https://github.com/nipunramk/Reducible

All music in the video is from Aakash Gandhi
HN Theater Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this video.
May 08, 2022 · 104 points, 20 comments · submitted by zdw
bob1029
JPEG has been growing on me lately. In addition to all of the clever information theory magic, it is also practically the fastest way to compress an image by miles.

I've got implementations on top of libjpegturbo that can encode with latency low enough to support interactive frame rates at modern resolutions. We are talking 1920x1080@4:4:4 in under 10 milliseconds.

dubiousconst281
You can get libx264 to encode 1080p in under 10ms if you spend enough time tuning it, altough I never compared the quality to JPEG.
bick_nyers
The fact that it is multi-threaded (where .jpeg and .png are not) is also a huge deal.
josefx
Motion JPEG is widely used as a simple video streaming format.
dr_zoidberg
Yes, but it stems from the fact that some phone manufacturers decided to reuse the hardware IP they already had in place for JPEG compression instead of paying for another chip that could do MPEG. It works, but it's not compression.

Then for some weird reason it gained traction as a "good quality video codec" (probably because there's no motion vectors, hence the associated artifacts simply can't happen with it).

Const-me
It’s pretty fast, but I’m not sure it’s the fastest.

If you want throughput, hardware-based h.264 gonna be faster than JPEG while delivering better quality. It’s possible to configure the encoder so it only emits keyframes (I-frames), which makes the video stream a sequence of independent compressed frames. However don’t forget about parameter sets, i.e. SPS/PPS blobs – the decoder gonna need them for each frame.

If you want latency, consider BC1 https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3... or BC7 https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc... They are lossy codecs usually used for textures in 3D scenes, the decoders are implemented in hardware in all modern PC GPUs. The algorithms are way simpler than JPEG, also easily parallelizable. Compression ratio is much worse though, for RGB24 images it’s 33% for BC7 and 17% for BC1, JPEG compression is way more efficient.

someweirdperson
There's some weird very low volume background music (?) distracting from the actual content. Or maybe a compression artifact.
ddek
That's a notably beautiful irony.
underlines
I thought for half an hour that my neighbor listened to piano music.
Trex_Egg
Nice video explaining the quirkiness of the compression in the media formats.
yboris
Obligatory note about JPEG's successor: JPEG XL (.jxl) -- better in every way ;)

https://jpegxl.info/

ZeroGravitas
I'm not sure if it would make you YouTube famous, but I'd be interested in a video series where it emphasised how crappy, expedient, short-sighted and idiotic choices in the development of technologies were.

I feel the focus on the beauty and amazement is somewhat misleading. It's like a magic trick, they're trying to fool you into thinking this is some superman feat.

I want the story of the JPEG told from the "let's just throw some information away because it's good enough to get the current job done even if it looks crap" perspective.

Like reading about how your favourite singer or comedian grew up doing impersonations of their favourite singer or comedian, I feel it gives a truer glimpse into how these things work in reality and a better understanding for people who want to learn.

varjag
Yes. An opinionated podcast with hot takes on other people's work would certainly be a refreshing thing.
aidenn0
I'm only about 80% sure that this comment is sarcastic...
adhesive_wombat
That would be a very interesting series.

Engineering is all about comprise and sacrifice to get a product working within the constraints (price, weight, volume, time to market, project risk, regulatory compliance, reliability, etc), so these stories would exist for everything.

Except Juicero, that thing was engineered to death: the only thing they (well...the VCs) skimped on was the market research and common sense.

dylan604
>I want the story of the JPEG told from the "let's just throw some information away because it's good enough to get the current job done even if it looks crap" perspective.

The thing built like that would either be crap and nobody uses it so no cool story, or it will be so damn genius with middle out that gets a Weissman score of 9.8 or some such.

mahdi7d1
I need this.
Certhas
Except that JPEG built on decades of academic research. It's the exact opposite of a dirty hack that just happens to work well enough to stick. The magic is doing the foundational research, iteratively, painstakingly, over decades, without the constraints of getting a concrete job done:

https://en.wikipedia.org/wiki/JPEG#Background

> The original JPEG specification published in 1992 implements processes from various earlier research papers and patents cited by the CCITT (now ITU-T) and Joint Photographic Experts Group.[1] The main basis for JPEG's lossy compression algorithm is the discrete cosine transform (DCT),[1][8] which was first proposed by Nasir Ahmed as an image compression technique in 1972.[9][8] Ahmed developed a practical DCT algorithm with T. Natarajan of Kansas State University and K. R. Rao of the University of Texas in 1973.[9] Their 1974 paper[15] is cited in the JPEG specification, along with several later research papers that did further work on DCT, including a 1977 paper by Wen-Hsiung Chen, C.H. Smith and S.C. Fralick that described a fast DCT algorithm,[1][16] as well as a 1978 paper by N.J. Narasinha and S.C. Fralick, and a 1984 paper by B.G. Lee.[1] The specification also cites a 1984 paper by Wen-Hsiung Chen and W.K. Pratt as an influence on its quantization algorithm,[1][17] and David A. Huffman's 1952 paper for its Huffman coding algorithm.[1]

The JPEG2000 standards major move forward was using wavelets instead of cosines, building on a different strand of research also going back decades...

HarHarVeryFunny
Regardless of how long it took to derive, the JPEG standard is still pretty straight forward and obvious. Perhaps more so in hindsight?

1) Convert image to YUV color space so that brightness (Y) component can be compressed separately from color (UV) components to which humans are less sensitive.

2) Transform each component (YUV) to frequency domain, then throw away image fine detail, i.e. high frequency components, according to desired level of compression. This obviously is the key idea.

3) Encode remaining frequency components to as small a size a possible

Once the general idea for this approach was conceived, it seems a rather minor step to try DCT vs the more obvious FFT for the frequency encoding. DCT gives slightly better compression. The approach isn't dependent on Huffman encoding for step 3) either - any encoding scheme would work, so experimentation would also have worked there to see what gives best compression on some set of test images.

WithinReason
Yes, the process of coming up with JPEG was extremely thorough. I recall from a uni lecture that originally multiple working groups were pursuing multiple research directions. Then they selected the 2 most promising and focused on those, and eventually the current JPEG codec emerged as winner. They meticulously hand-tuned the quantisation tables too. The process lasted about 6 years (1986-1992). No wonder it's still the most widespread codec. JPEG stands for Joint Photographic Experts Group for a reason!
Jan 21, 2022 · 1 points, 0 comments · submitted by tartoran
Jan 19, 2022 · 1 points, 0 comments · submitted by vg_head
HN Theater is an independent project and is not operated by Y Combinator or any of the video hosting platforms linked to on this site.
~ yaj@
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.