JPEG: Image Compression Algorithm (2017)
pi.math.cornell.edu
pi.math.cornell.edu
https://image.slidesharecdn.com/jpeg-dct-131006054709-phpapp...
As far as the theory goes, the transform using the DCT is lossless apart from rounding errors. The quantization step just rounds more roughly. Which is where the lossy compression happens.
Basically you’re not removing the high frequencies because they carry little information, you remove the information they carry.
If you just remove the high frequency you end up with a blurred, smooth picture that doesn’t look like the original. But if you quantize the strength you get a pretty similar looking picture, apart from the degenerate case of sharp edges in a drawing.
Well it looks like a blurred, smoothed picture. This can be exploited during decoding if you want a smaller size than the original. For example if you only decode the 2x2 lower-frequency components of a 2000x1000 image, you get a nice downsampled 500x250 image "for free".
For example when making thumbnails this can be very useful, as for larger images you can often use just 2x2 or 1x1, dramatically cutting down the work needed for the final resample.
Oh and you can figure out what camera/software took a photo by looking at the value of n for each frequency. Everyone does it slightly differently to achieve different compression ratios.
The quantization part is where the magic happens, but it’s not about choosing between those patterns. It’s about “snapping” the coefficients to fixed steps.
Basically, the human visual cortex is bad at noticing subtle differences at higher frequencies (the bottom right area of your linked image). You can’t easily tell if the coefficient for that bottom right pattern is, say 100 or 103. So JPEG stores those coefficients with lower precision, which requires fewer bytes after the entropy coding step.
https://github.com/ghallak/jpeg-python/blob/master/decoder.p...
Some of the helper functions in this separate file:
A very minor corruption in the file and poof you can retrieve nothing.
Many years ago there was a single program[1] that could, in a very small subset of cases, "fix" corrupted JPEG files (manually/inteactively), now (AFAIK) there is almost only [2] and [3] and this (service) [4] that actually produce (in some cases) good results.
In my (admitted) ignorance on the matter, I would have expected that with progresses like increased computer power, AI, deep fakes or whatever the problem by now was - if not solved - at least solved in a number of subset of cases.
[1] https://directory.s2services.com/jpg-bmp.htm
[2] https://www.jpegmedic.com/tools/jpegmedic/ https://www.jpegmedic.com/tools/
It is actually quite common to find partial/corrupted images.
Typically an image will have a grey band/area or it will be "shifted" in some parts, some examples are here:
https://www.jpegmedic.com/tools/jpegmedic/
Even checking if a file or an extent on disk is actually an image is not as easy as it seems (JFYI):
https://www.forensicfocus.com/forums/mobile-forensics/jpeg-c...
To solve this, the format itself needs to incorporate error correction. There are various ways to do that with different trade-offs, but all of them will hurt your compression ratio, because the only way to correct errors is to have some kind of redundancy, and removing redundancy is precisely what compression is about.
I believe that cloud storage and autosync fixed the issue of currupted images for most normal users.
I've used it for experimental UI projects and had no problem chewing through 1080p bitmap encodes with latency for each somewhere around 5 milliseconds.
https://cloudinary.com/blog/how_jpeg_xl_compares_to_other_im...
https://cloudinary.com/blog/time_for_next_gen_codecs_to_deth...