Thread: .jpg vs. .png
View Single Post
  #6 (permalink)  
Old 07-09-2009, 03:40 PM
BusaWhipped BusaWhipped is online now
Hayabusa Immortal


 
Join Date: May 2005
Location: St. Louis, Missouri
Group: Super Moderators
Posts: 9,078
Default Re: .jpg vs. .png

Compression uses predictability to replace longer strings of bits with shorter ones. Using text to illustrate a simple example:
"queen". we know by rule "q" is always followed by "u" so we do not need to store it. so if we store "qeen" we've reduced the storage by 20% (4 bites instead of 5) and have not lost any information since we will always add a "u" whenever we read a "q" from the file.

Low frequency images can also be compressed very well without loss. Take a picture of chess board with 10 pixel x 10 pixel squares for example. The first line of the white block can be represented as 10(White) which we can symbolize as "A". The first line of the black block can be represented as 10(Black) which we can symbolize as "B". The first line in the image of the chess board can be represented as 4(A;B) [4 repetitions of 10 wite pixes follwed by 10 black pixels]. To get the first row of blocks woud be 10 copies of the first line. 10(4(A;B)) which we can symbolize as "C". The second row of the board is 10(4(B;A)) which we can symbolize as "C". We've reduced the size of the chess board image from 6,400 bytes to a formula
A=10(White);B=10(Black);C=10(4(A;B));D=10(4(B;A)); C;D;C;D;C;D;C;D

This formula does not grow much as the size of the image grows. If the chess board image was increased in size where each of the blocks is 1,000 pixels x 1,000 pixels, the image would grow to 64,000,000 bytes, while our stored formula would only grow by 8 bytes:
A=1000(White);B=1000(Black);C=1000(4(A;B));D=1000( 4(B;A));C;D;C;D;C;D;C;D

It is possible to compress high frequency images (like most photographs) somewhat without any loss, but not much. To make high frequency images more predicable to allow for greater compression, pixels need to be thrown away before creating the fsymbolized version which is stored. Anything lost before symbolization cannot be recovered later. Since the images can't be predicted like the chess board example, the complexity in the compression engines is how to determine how to symbolize the image so that the least number of pixels need to be lost to achieve a desired compression ratio. You need to throw fewer pixels away for a 4:1 compression ration than for a 8:1 ratio.

I don't know if that answered any questions or not, but it was good to revive some of the old theory I haven't used for years.

______________________________________

Last edited by BusaWhipped; 07-09-2009 at 03:48 PM.
Reply With Quote