1.3-Compression-Notes-By-EMK
1.3-Compression-Notes-By-EMK
Objective:
Show understanding of the need for and examples of the use of compression
Show understanding of lossy and lossless compression and justify the use of a method in a
given situation
Show understanding of how a text file, bitmap image, vector graphic and sound file can be
compressed. Including the use of run-length encoding (RLE)
Compression Techniques
Larger files require larger storage capacity and lower transmission or download rates.
Compression techniques are used to reduce file size.
Two categories of compression.
The
Lossless Compression Lossless compression where file size is reduced but no
information is lost and when necessary, process can be reversed to re-create original
file.
This is important for files where loss of any data would be disastrous (text file )
Note: RLE is only effective where there is a long run of repeated units/bits.
Example: Using RLE on Text Data:
Consider text string ‘aaaaabbbbccddddd’.
Assuming each character requires 1 byte, then this string needs 16 bytes. If we
assume ASCII code is being used, then string can be coded as follows:
Assuming each number in second row requires 1 byte of memory, RLE code will
need 8 bytes. This is half the original file size.
Example: Using RLE with images
Black and white images Figure shows letter F in a grid where each square requires 1
byte of storage. White square has value 1 and black square a value of 0.
8 × 8 grid would need 64 bytes; compressed RLE format has 30 values, and
therefore needs only 30 bytes to store image.
iii. Example:
Consider a screen containing plain black text on a solid white background.
There will be many long runs of white pixels in the blank space, and many short runs of
black pixels within the text. B representing a black pixel and W representing white.
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWW
WWWWWWWWWWWWBWWWWWWWWWWWWWW
With a run-length encoding (RLE) data compression algorithm applied to above line, it
can be rendered as follows:
12W1B12W3B24W1B14W
This can be interpreted as a sequence of twelve Ws, one B, twelve Ws, three Bs, etc.
Run-length code represents original 67 characters in only 18.
Lossy Compression
Lossy compression where the file size is reduced with some loss of
information and the original file can never be recovered.
Lossy compression can be used in circumstances where a sound file or an
image file can have some of the detailed coding removed or modified when it is likely
that the human ear or eye will hardly notice any difference.
One example would be to reduce the colour depth for the coding of a bitmap.
In many applications a combination of lossless and lossy methods may be used.
Photographic (bit-map) images :
When a photographic file is compressed, both the file size and quality of
image are reduced. A common file format for images is JPEG, which uses lossy file
compression.
Once the image is subjected to the JPEG compression algorithm, a new file is formed
and the original file can no longer be constructed. A JPEG will reduce the raw bit-map
image by a factor of between 5 and 15, depending on the quality of the original.
Vector graphics can undergo file compression. Scalable vector graphics (.svg) are defined in
text files which allows them to be compressed.
MP3 files use what is known as a lossy format, since part of original file is lost
following compression algorithm. This means that original file cannot be put back
together again.
TYK: When storing music tracks in a computer, MP3 format is used. This reduces file size by
about 90%. Explain how music quality is apparently retained.
This is done using file compression algorithms that use perceptual music shaping.
Perceptual music shaping removes certain sounds. For example
frequencies that are outside the human hearing range
if two sounds are played at the same time, only louder one can be heard by ear, so softer
sound is eliminated.
This means that certain parts of music can be removed without affecting quality too much.
MPEG-4 (MP4) files are slightly different to MP3 files. This format allows storage of
multimedia files rather than just sound. Music, videos, photos and animation can all be
stored in the MP4 format. Videos could be streamed over internet using MP4 format
without losing any real noticeable quality.