Page 1 of 2 12 LastLast
Results 1 to 16 of 28

Thread: Want to understand how JPEG works a bit more?

  1. #1
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Want to understand how JPEG works a bit more?

    Check out this brilliant video



    (Edit by peterb: the animus posted this as he thought the subtleties of compression would be of interest to the photographic community. With his agreement I have moved it to a wider audience. The video is well worth watching (at least twice ) and as always, the HEXUS community has explained it further in the thread)
    Last edited by peterb; 26-05-2015 at 08:11 AM. Reason: Explanation
    throw new ArgumentException (String, String, Exception)

  2. Received thanks from:

    aidanjt (24-05-2015),chrestomanci (27-05-2015),Jonatron (24-05-2015),MaddAussie (26-05-2015),mikerr (24-05-2015),peterb (25-05-2015),Rob_B (24-05-2015),santa claus (26-05-2015)

  3. #2
    Almost Ex-HEXUS Staff Jonatron's Avatar
    Join Date
    Sep 2009
    Location
    London
    Posts
    705
    Thanks
    48
    Thanked
    272 times in 167 posts

    Re: Want to understand how JPEG works a bit more?

    I have been reading about JPEG compression recently, and only half understood it. I totally get it now!

  4. #3
    Photographer Bobster's Avatar
    Join Date
    Apr 2004
    Location
    Sunny Dorset
    Posts
    3,427
    Thanks
    25
    Thanked
    376 times in 304 posts
    • Bobster's system
      • Motherboard:
      • Gigabyte AX370 GAMING K7
      • CPU:
      • Ryzen 5 5600X
      • Memory:
      • G.Skill FlareX 32GB DDR4 3200
      • Storage:
      • 42TB
      • Graphics card(s):
      • MSI 6700XT
      • PSU:
      • Corsair RM850X
      • Case:
      • SilverStone TJ05
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • LG LG 27UD88-W, LG 27 ColourPrime, HP LP2475w
      • Internet:
      • 16Mb

    Re: Want to understand how JPEG works a bit more?

    0:40 seconds... ZZZZZZZZz

    they way i always understood JPEG compression was. JPEG looks at a colour and then it's neighbours, if the colour is like it, then it is taken to be the same. So the more compression the wider the spread of neighbours.

  5. Received thanks from:

    Jonj1611 (24-05-2015)

  6. #4
    Senior Member Tumble's Avatar
    Join Date
    Jul 2003
    Location
    Right in the Pickle Barrel
    Posts
    7,217
    Thanks
    271
    Thanked
    315 times in 217 posts

    Re: Want to understand how JPEG works a bit more?

    Quote Originally Posted by Bobster View Post
    0:40 seconds... ZZZZZZZZz

    they way i always understood JPEG compression was. JPEG looks at a colour and then it's neighbours, if the colour is like it, then it is taken to be the same. So the more compression the wider the spread of neighbours.

    That's error diffusion you're describing there, which is more to do with gradation that compression. There's more than just that going on when you start looking at compression etc.

    Quote Originally Posted by The Quentos
    "My udder is growing. Quick pass me the parsely sauce." Said Oliver.

  7. #5
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Want to understand how JPEG works a bit more?

    Quote Originally Posted by Bobster View Post
    they way i always understood JPEG compression was. JPEG looks at a colour and then it's neighbours, if the colour is like it, then it is taken to be the same. So the more compression the wider the spread of neighbours.
    I can't understand why ignorance is something to be proud of?

    If you'd bothered to watch the video, you would realise what more you need to learn, as your understanding is very wrong.
    throw new ArgumentException (String, String, Exception)

  8. #6
    ALT0153™ Rob_B's Avatar
    Join Date
    Jul 2006
    Posts
    6,736
    Thanks
    467
    Thanked
    1,055 times in 687 posts

    Re: Want to understand how JPEG works a bit more?

    I was lost when he was going on about the waves then it started to make sense when he numbers were brought out. Interesting video, might have to browse a few more of them.

  9. #7
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Want to understand how JPEG works a bit more?

    There is a bit of learning curve on stuff like this Rob, glad you made it through, the thing to really take away is the idea that an image can be represented by a bunch of waves, that have the same shape, but at increasing frequencies. Then the fun bit of this kind of 'lossful' compression is that you can be smart about which bit of the image you loose.

    If you've any questions about bits you aren't sure on, feel free to ask as I'm sure I wasn't the only person on Hexus to study this stuff back at uni.
    throw new ArgumentException (String, String, Exception)

  10. #8
    ALT0153™ Rob_B's Avatar
    Join Date
    Jul 2006
    Posts
    6,736
    Thanks
    467
    Thanked
    1,055 times in 687 posts

    Re: Want to understand how JPEG works a bit more?

    I'm really not getting the waves thing, once he showed the grid image representation of the waves I found it easier to understand that by adding a certain amount of each of those you can get an approximate representation of the image. Makes sense I guess.

  11. #9
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Want to understand how JPEG works a bit more?

    Okay so let's look at this image I've nabbed from Wikipedia

    Let's look at that top left. Notice it's all white.

    Next lets look in the one below the top left, and the one to the right.

    We've got this 'gradient' of a sine wave.

    We look further out on the X and Y axis, by the 3rd box, we see the 'frequency' has increased, that is, the gradient is more frequent, it occurs fully now, rather than just partially. Only looking at the top row and first column, we see it now become a twice deal. The fun thing is, when you sum them together, you get a different curve.

    This is really useful, because the cosine function is known, so doesn't have to be encoded, you just need the frequency of it, which we can assume by using the 8x8 matrix, so we just need the 'weighting' for that curve.

    Sum the curves together and you get a good approximation. This is a really useful feature! We know that some curve frequencies are more important than others, so we can compress some more than others. This is why photos of natural things look quite good in jpeg, but text looks more awful.

    By using one or more 'functions' (maths uses bad names for everything, the function in this case is the pattern that is a cosine wave) we can represent more complex patterns. We can see this by borring a gif from wikipedia again, this time, for a fourier transform, notice how using a 'sinewave' pattern we can again make a different shape, just simply adding together different frequencies.



    The fun thing is, we've got a new 'function' simply by summing waves of different frequencies of a simple know function.
    throw new ArgumentException (String, String, Exception)

  12. #10
    Photographer Bobster's Avatar
    Join Date
    Apr 2004
    Location
    Sunny Dorset
    Posts
    3,427
    Thanks
    25
    Thanked
    376 times in 304 posts
    • Bobster's system
      • Motherboard:
      • Gigabyte AX370 GAMING K7
      • CPU:
      • Ryzen 5 5600X
      • Memory:
      • G.Skill FlareX 32GB DDR4 3200
      • Storage:
      • 42TB
      • Graphics card(s):
      • MSI 6700XT
      • PSU:
      • Corsair RM850X
      • Case:
      • SilverStone TJ05
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • LG LG 27UD88-W, LG 27 ColourPrime, HP LP2475w
      • Internet:
      • 16Mb

    Re: Want to understand how JPEG works a bit more?

    Quote Originally Posted by TheAnimus View Post
    I can't understand why ignorance is something to be proud of?

    If you'd bothered to watch the video, you would realise what more you need to learn, as your understanding is very wrong.
    what do i need to learn? my images look great on screen, they look great in print using the settings i use vs file size..

  13. #11
    The late but legendary peterb - Onward and Upward peterb's Avatar
    Join Date
    Aug 2005
    Location
    Looking down & checking on swearing
    Posts
    19,378
    Thanks
    2,892
    Thanked
    3,403 times in 2,693 posts

    Re: Want to understand how JPEG works a bit more?

    Two things struck me, one was that a JPEG file is relatively fragile - if the quantisation table is damaged, the image is lost, and that different applications can use there own quantisation tables, so while another application can recover the image, the overall effect might vary because of a different table.
    (\__/)
    (='.'=)
    (")_(")

    Been helped or just 'Like' a post? Use the Thanks button!
    My broadband speed - 750 Meganibbles/minute

  14. #12
    Senior Member
    Join Date
    Apr 2011
    Location
    Glasgow
    Posts
    330
    Thanks
    12
    Thanked
    39 times in 30 posts
    • Goobley's system
      • Motherboard:
      • Asus H81I-Plus
      • CPU:
      • i3 4130
      • Memory:
      • 8GB Corsair Vengeance LP Blue
      • Storage:
      • 1TB Caviar Blue
      • Graphics card(s):
      • MSI R9 270 Gaming
      • PSU:
      • EVGA 500B
      • Case:
      • Cooler Master Elite 120
      • Operating System:
      • Linux Arch/Mint/Windows 7 Ult. 64bit/OS X
      • Monitor(s):
      • 23" iiyama IPS
      • Internet:
      • Meh

    Re: Want to understand how JPEG works a bit more?

    As a physicist with an emphasis on computer related simulation etc. I have to say that Fourier series are wonderful things. Still hate working the blighters out by hand though!

    Fourier's theorem states that any periodic wave can be built of an infinite series of sine and cosine waves, and if you take the JPEG's 8x8 cell to be 1 period then you can easily make any of the patters (of course, like the video says, you have to look in 2D, but mathematically it's not harder per se, just a bit more irritating to crunch by hand).

    Of course, going for compression, we don't want to use infinitely many waves, as this would require a bit too much space. However, we see that the Fourier series converges very quickly towards a good approximation of what we're looking for (especially given how "insensitive" the eye is to little variations of colour). Here's a couple of pictures from some of my older lecture notes:



    TheAnimus: That gif you have of the Fourier series is awesome!
    Last edited by Goobley; 25-05-2015 at 05:29 PM. Reason: I swear I can link images...

  15. #13
    Oh Crumbs.... Biscuit's Avatar
    Join Date
    Feb 2007
    Location
    N. Yorkshire
    Posts
    11,193
    Thanks
    1,394
    Thanked
    1,091 times in 833 posts
    • Biscuit's system
      • Motherboard:
      • MSI B450M Mortar
      • CPU:
      • AMD 2700X (Be Quiet! Dark Rock 3)
      • Memory:
      • 16GB Patriot Viper 2 @ 3466MHz
      • Storage:
      • 500GB WD Black
      • Graphics card(s):
      • Sapphire R9 290X Vapor-X
      • PSU:
      • Seasonic Focus Gold 750W
      • Case:
      • Lian Li PC-V359
      • Operating System:
      • Windows 10 x64
      • Internet:
      • BT Infinity 80/20

    Re: Want to understand how JPEG works a bit more?

    God this feels like im revising for my compression exam at uni again ^_^

  16. #14
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Want to understand how JPEG works a bit more?

    Quote Originally Posted by Bobster View Post
    what do i need to learn? my images look great on screen, they look great in print using the settings i use vs file size..
    You can lead a horse to water, but you can't make them think. If you don't want to bother understanding something, you can never be in a position to say if it was worth learning or not. There are many things I've researched which have no practical application, no 'benefit' but the journey was still a worthwhile endeavour. You can't know how something may or may not benefit you, until you know that something.

    Even if after learning it, it's not applicable to you doesn't mean it's a good idea to go around spouting a falsehood whilst claiming that the education for correcting it is boring. I think it's wrong to judge people for being ignorant. But wilful ignorance, well that is damned stupid.
    throw new ArgumentException (String, String, Exception)

  17. #15
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Want to understand how JPEG works a bit more?

    Quote Originally Posted by peterb View Post
    Two things struck me, one was that a JPEG file is relatively fragile - if the quantisation table is damaged, the image is lost, and that different applications can use there own quantisation tables, so while another application can recover the image, the overall effect might vary because of a different table.
    Yup it's not meant to be a robust format, I sort of agree with that, redundancy data, such as error correction or detection should be the concern of the storage/transmisison system. TCP/IP has built in retrying for corrupted packets, most storage drives have some recovery information, flash devices such as SSDs often have complex parity data as it's not uncommon for a bit to be corrupted.

    Goobley, I stole that gif from Wikipedia on Fourier Transform, it's great isn't it. For anyone else the reason we love it is it clearly shows how the 'result' the red curve, is composed of the blue waves at increasing frequency (more ups and downs), and decreasing amplitude (the ups are less up, and the downs less down).

    Also Goobley, why do you have to work some out by hand? I don't think I ever did that outside of an exam, I did implement my own FFT before in assembly for a PIC16 series, this was so we could make a friends bookshelves light up in time with the music, quite a nice little birthday gift even if you had to be rather stoned for the effect to be good! I remember telling myself, could be worse, could be working it out by hand, suddenly PIC16 assembly appeared nice.
    throw new ArgumentException (String, String, Exception)

  18. #16
    Senior Member
    Join Date
    Apr 2011
    Location
    Glasgow
    Posts
    330
    Thanks
    12
    Thanked
    39 times in 30 posts
    • Goobley's system
      • Motherboard:
      • Asus H81I-Plus
      • CPU:
      • i3 4130
      • Memory:
      • 8GB Corsair Vengeance LP Blue
      • Storage:
      • 1TB Caviar Blue
      • Graphics card(s):
      • MSI R9 270 Gaming
      • PSU:
      • EVGA 500B
      • Case:
      • Cooler Master Elite 120
      • Operating System:
      • Linux Arch/Mint/Windows 7 Ult. 64bit/OS X
      • Monitor(s):
      • 23" iiyama IPS
      • Internet:
      • Meh

    Re: Want to understand how JPEG works a bit more?

    Quote Originally Posted by TheAnimus View Post
    Also Goobley, why do you have to work some out by hand? I don't think I ever did that outside of an exam, I did implement my own FFT before in assembly for a PIC16 series, this was so we could make a friends bookshelves light up in time with the music, quite a nice little birthday gift even if you had to be rather stoned for the effect to be good! I remember telling myself, could be worse, could be working it out by hand, suddenly PIC16 assembly appeared nice.
    Still in Uni with these damnable exams, but I also do some work with CAS systems and don't always fully trust some of the exact answers they claim to produce (since I've seen the state of the codebases holding some of them up). Although to be fair I should probably just use Matlab outside of having to compute it myself...

    WRT the PIC assembly, you must have a lot more staying power than I. I tend to look at my code in LLVM assembly, see it's inefficient, say to myself: "I could really improve these things..." then realise it feels like too much effort. (I love autovectorisers, the fewer SIMD intrinsics I have to use the better). Having never had to program in assembly the amount of work involved seems like a pain, especially handling something like a DFT matrix...

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •