How do you make a 1 litre jug smaller, without losing any of it's capacity? Sorry if that answer's a little "smart alec", but that's the reality of it. There are two kinds of compression in computing, they are loosely defined as "lossy" and "lossless". Lossy compression relies on the fact that the eye will not notice anything amiss, if colour or shape is slightly off. So the most common types is to either compress the colour palette, or "block up" the shapes. In the first case, the photograph is analysed for the number of distinct colours. If out of a palatte of 16.7 Million colours (24 bits per pixel), less than 65,536 colours are used, then they can map the colours to a 16 bpp scheme. Notice here that there is so far no loss of quality - only the binary representation has changed. On the other hand, if there are say, 100,000 colours used (too many for 16 bit, too few for 24 bit) then they can estimate, that two colours are close enough to be represented by the same colour. That's lossy compression. You've lost some of the quality of the photo. The other method is used by jpeg - it grabs 8 x 8 pixel blocks and inspects the colours for likeness. If they are alike, then it considers all that block of the same colour. In most photographs, you would not notice this. However, in certain cases you will - like when you are expecting sharpness, when you have photographs with gradients (such as sunsets) or when there are lots of small curves in your photo (Since blocks with make your curve a little jagged). Most of all, you will notice for small photographs, because the 8 x 8 pixel block is unchangeable. Personally, I wouldn't go near jpeg with a ten foot barge pole, unless I had to transmit a photograph and quality was of little concern. Lossless compression is based on standard computer data compression. It relies on the fact that some byte patterns occur frequently in data. For example, if I knew that the string "alphabet" occured frequently in my file, I could instruct the compressor replace "alphabet" with "abc" and instruct the decompressor to replace "abc" with "alphabet" (well, actually, it's realistically a lot more complex than that, but that's a layman's explaination) I am then saving 5 bytes for ever occurance of alphabet. As you can infer, the data that goes into the compressor is identical to the data that comes out of the decompressor, so the compression method is called "lossless". No detail is lost. This compression type is used in TIFF files with LZW compression turned on, or by running winzip or similar program over any file. So, how does all that translate to real life? Well, basically, if you size down the file, you lose quality. The only way you can avoid that is in some instances, you can shift your photo from 24 bit colour to 16 bit colour with no perceivable loss in quality. The other option is to use data compression if you're intending to store, rather than post on a website or send.
January 06, 2002
|