+ All Categories
Home > Documents > Data Compression For Images. Data compression or source coding is the process of encoding...

Data Compression For Images. Data compression or source coding is the process of encoding...

Date post: 26-Dec-2015
Category:
Upload: abner-conley
View: 222 times
Download: 1 times
Share this document with a friend
26
Data Compression For Images
Transcript
Page 1: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

Data CompressionFor Images

Page 2: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units) than an unencoded representation would use through use of specific encoding schemes.

• One popular instance of compression with which many computer users are familiar is the ZIP file format, which, as well as providing compression, acts as an archiver, storing many files in a single output file.

Page 3: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• As is the case with any form of communication, compressed data communication only works when both the sender and receiver of the information understand the encoding scheme. For example, this text makes sense only if the receiver understands that it is intended to be interpreted as characters representing the English language. Similarly, compressed data can only be understood if the decoding method is known by the receiver.

Page 4: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

Why Data Compression?Graphical images in bitmap format take a lot of

memory– e.g. For 3 Byte image the size (1024 x 768)pixels

x 24 bits-per-pixel = 18,874,368 bits, or 2.4Mbytes.

• But 120 Gbyte disks are now readily available!!• So why do we need to compress?• How long did that graphics-intensive web page

take to download over your 56kbps modem?

Page 5: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• How many images could your digital camera hold?

– Picture messaging?• CD (650Mb) can only hold less than 10

seconds of uncompressed video (and DVD only a few minutes)

• We need to make graphical image data as small as

possible for many applications

Page 6: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

Types of Compression

• Pixel packing• RLE (Run-length Encoding)• Dictionary-based methods• JPEG compression• Fractal Image Compression

Page 7: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

Some factors to look out for:

• Lossy or lossless compression?• What sort of data is a method good at

compressing?• What is its compression ratio?

Page 8: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

1. Pixel Packing• Not a standard “data compression technique” but

nevertheless a way of not wasting space in pixel data • e.g.

– suppose pixels can take grey values from 0-15– each pixel requires half a byte– but computers prefer to deal with bytes– two pixels per byte doesn’t waste space

• Pixel packing is simply ensuring no bits are wasted in the pixel data

• (Lossless if assumption true)

Page 9: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

2. Run-length encoding (RLE)

• is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. This is most useful on data that contains many such runs: for example, simple graphic images such as icons and line drawings.

Page 10: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• For 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. Let us take a hypothetical single scan line, with B representing a black pixel and W representing white:–WWWWWWWWWWWWBWWWWWWW

WWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW

Page 11: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• If we apply the run-length encoding (RLE) data compression algorithm to the above hypothetical scan line, we get the following: 12WB12W3B24WB14W

• Interpret this as twelve W's, one B, twelve W's, three B's, etc.

Another example is this:• AAAAAAAAAAAAAAA would encode as 15A• AAAAAAbbbXXXXXt would encode as 6A3b5X1t

So this compression method is good for compressing large expanses of the same color.

Page 12: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

RLE compression ratio

Consider a small 10 × 11 pixel block taken from image:

• Of the 110 pixels in this 10 × 11 pixels sample taken from the image, there are 59 different colors altogether!

Page 13: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• RLE compression ratios not good in general, because there are rarely repeat runs of pixels.

Full image: 371 × 247 bitmap , (274911 = 371 × 247 × 3) bytes = 275Kb raw dataWhile it is 91K RLE encoded Compression ratio approx 3:1 in this case

Page 14: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

RLE compression ratio

• Another example, with a diagram this timeFull image: 350 × 264 bitmap277Kb raw data(277200 = 350 × 264 × 3) bytes46.5K RLE encodedCompression ratio approx 6:1 in this case

Page 15: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

3. Dictionary Methods• A dictionary, also sometimes known as a

substitution coder, is any of a number of lossless data compression algorithms which operate by searching for matches between the text to be compressed and a set of strings contained in a data structure (called the 'dictionary') maintained by the encoder. When the encoder finds such a match, it substitutes a reference to the string's position in the data structure.

Page 16: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• A common way to compress data (pixels, characters, whatever!) is to use a dictionary

• The dictionary contains strings of bytes– e.g. particular pixel patterns– not limited to patterns of one color, as with RLE

• Data is encoded by replacing each data string that has an entry in the dictionary with its index number in the dictionary.

• Shorter to write an index number than a whole string!• Dictionary may be particular to the image, or may be“standard” for particular image types

Page 17: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

3.1 Patterns of Pixels

• Poor results with RLE as runs of pixels with same color are very short

• But there are repeating patterns with two colors that could be included in a dictionary

• Hence, could replace each byte pattern with a pointer to it (or its index number in the dictionary)

Page 18: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

3.2 Huffman and CCITT Compression

• Developed for fax machines and document scanners• Uses a predefined dictionary of commonly occurringbyte patterns from B&W documents containing largeamounts of text in a variety of languages and typicalexamples of line art• Commonly occurring patterns are given low (short)indices (codes) in the dictionary• Data is encoded by replacing each image string thatoccurs in the dictionary with its index number• Dictionary is not part of the compressed file.

Page 19: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

3.3 The Lempel-Ziv-Welch Algorithm• The Lempel-Ziv-Welch method is another such

dictionary algorithm, in which the dictionary is constructed as the encoding (compression) progresses.– (actually Ziv was the first author on the original papers!)

• LZW starts with a dictionary of byte strings:– Entries 0-255 refer to those individual bytes– Entries 256 onwards will be defined as the algorithm

progresses• Each time a new code is generated it means a new

string of bytes has been found.• New strings are generated by appending a byte (c) to

the end of an existing string (w).– see algorithm on next slide

Page 20: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

The LZW Algorithmset w = “ ”;while (not EOF)read a character c;if w+c exists in the dictionaryw = w+c;else {output the code for w;add w+c to the dictionary;w = c;}endwhile

Page 21: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

When Is LZW Useful?

• Good for encoding pixel data with a limited palette,and/or repetitive data

– line drawings– diagrams– plain text on a plain background

• Not good for photographic images– large color range and complex features results in few

repeating patterns to include in a dictionary

Page 22: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

JPEG• Joint Photographic Experts Group• Designed to compress photographs

– color or grayscales– good at compressing “real” scenes– not good for line drawings, diagrams, lettering, cartoons

• Designed for human viewing, exploits our inability tosee a full range of colors

– Lossy algorithm– Not good for computer analysis of data

• e.g. computer analysis for medical imaging• Edge finding

Page 23: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

4. JPEG Compression

• For full-color images, the best-known losslesscompression about 2:1• For reasonable quality, compression ratios of

10:1 or 20:1 quite feasible for JPEGs– Clive’s picture compressed with a ratio of 15:1• For poor quality images (thumbnails?), 100:1possible• Re-encoding loses more information

Page 24: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

5. Fractal Compression

• Fractal compression is a lossy compression method used to compress images using fractals. The method is best suited for photographs of natural scenes (trees, mountains, ferns, clouds). The fractal compression technique relies on the fact that in certain images, parts of the image resemble other parts of the same image.

Page 25: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• Fractal compression appeared to be a promising technology in the late 1980s, when in some circumstances it appeared to compress much better than JPEG, its main competitor at that time.

• However, fractal compression never achieved widespread use. Fractal compression is much, much slower to compress and much slower to decompress than JPEG. Furthermore, its patents were not widely licensed. Also, the improved compression ratio is an illusion.

Page 26: Data Compression For Images. Data compression or source coding is the process of encoding information using fewer bits (or other information-bearing units)

• Fractal compression only has a large advantage over JPEG at low image quality levels, which is usually undesirable. The claim that fractal compressed images, when enlarged beyond their original size, looked better than similarly enlarged JPEG images seems also to have been an irrelevant distinction.


Recommended