Anda di halaman 1dari 19

University of

Technology
Computer Science

Department.

Image compression
M.Sc. Seminar
By: Ameera Jawad & Muna Ghazi A.

Supervised: A.P.Dr Matheel


2011-2012
Image compression involves reducing the size of image data
files, while retaining necessary information .The reduced file is
called the compressed file and is used to reconstruct the image
,resulting in the decompressed image. The original image, before
any compression is performed, is called the uncompressed image
file. The ratio of original uncompressed image file and the
compressed file is referred to as the compression ratio. It is often
written as SIZEU:SIZEC. The compression ratio is denoted by:

Compressed File C
Uncompressed File U
Compression Ratio = =

EXAMPLE :The original image is 256x256 pixels , 8 bits per


pixel . this file is 65,536 bytes. After compression the image file is
6,854 bytes. The compression ratio is:

SIZELU/SIZEC= 65536/6554 = 9.999 = 10. This can also be written


as 10:1.

The reduction in file size is necessary to meet the bandwidth


requirements for many transmission systems, the storage
requirements in computer database.

Compression System Model:


The compression system model consists of two parts: the
compressor and decompressor.
Input image
compressed file
I(r,c) preprocessing encoding

Compression
Decoded Image I(r,c)
compressed file
decoding postprocessing

DeCompression
Figure (1)Compression System Model.

The compressor consists of :-

a preprocessing stage : preprocessing is performed to


prepare the image for the encoding process, and consists of
any number of operations that are application specific.
Data reduction, Here, the image data can be reduced by
gray-leve1 and/or spatial quantization, or they can
undergo any desire image enhancement (for example,
noise removal) process.
The mapping process, which maps the original image
data into another mathematical space where it is easier to
compress the data.
encoding stage .

The quantization stage (as part of the encoding process),


which takes the potentially continuous data from the
mapping stage and puts it in discrete form.
Final stage of encoding involves coding the resulting data,
which maps the discrete data from the quantizer onto a
code in an optimal manner. A compression algorithm may
consist of all the stages, or it may consist of only one or
two of the stage.

Input Image Data Mapping


I(r,c)
Reduction
Preprocessing
Quantization coding Compressed
file

Encoding
Figure(2) The Compressor

Decompressor consists of :-

decoding process is divided into two stages.


the decoding stage, takes the compressed file and reverses
the original coding by mapping the codes to the original,
quantized values.
Next, these values are processed by a stage that performs
an inverse mapping to reverse the original mapping
process. Finally.
A postprocessing stage : After the compressed file has been
decoded, postprocessing can be performed to eliminate some
of the potentially undesirable artifacts brought about by the
compression process. The Image postprocessed to enhance
the look of the final image. Often, many practical compression
algorithms are a combination of a number of different
individual compression techniques.

Compressed Decoding Inverse Mapping


file

Decoding

Postprocessing Decoded Image I(r,c)


Figure(3) the decompressor

There are two types of image compression methods :


Lossless Compression Methods and Lossy Compression
Methods.

1. Lossless Compression Methods:

Lossless compression methods are necessary in some imaging


applications. For example, with medical images, the law required
that any archived medical images are stored without any data
loss. In general, the lossless techniques alone provide marginal) (
compression of complex image data, often in the range of
only a 10% reduction in file size. However, lossless compression
techniques may for both preprocessing and postprocessing in
image compression algorithms. Additionally, for simple images
lossless techniques can provide substantial()compression.
Entropy measure provide us with metric to evaluate coder
performance .we can measure the average number of bits per
pixel (length) in a coder by the following :

L1
Lave = I i Pi
i=0
Where I i = length in bits of the code for ith gray level
P
i= histogram (probability of ith gray level)

This can then compared to the entropy ,which provides the


theoretical minimum for average number of bits per pixel that
could be used to encode the image

1.1 Huffman Coding


The Huffman code developed by D. Huffman in1952, is a
minimum length code.
This means that given the statistical distribution of the gray levels
(the histogram),
the Huffman algorithm will generate a code that is as close as
possible to the minimum bound' the entropy'. For example,
Huffman coding alone will typically reduce the file by 10 to 50%,
but this ratio can be improved to 2:1 or 3:1 by preprocessing for
irrelevant information removal.

The Huffman algorithm can be described in five steps:


l. Find the gray-level probabilities for the image by finding the
histogram.
2. order the input probabilities (histogram magnitudes) from
smallest to largest.
3.Combine the smallest two by addition.
4. Go To step 2, until only two probabilities are left.
5. By working backward along the tree, generate code by
alternating assignment of
0 and 1.
Example 1(Huffman Coding Example)
we have an image with 2 bit/pixel ,giving four possible gray
levels. the image is 10 rows by 10 columns .

Step 5 ( haffman code):-


Note that two of the gray levels now have 3 bits assigned to
represent them, but
one gray level only has 1 bit assigned to represent it. The gray
level represented
by 1,g3, is the most likely to occur(40% of the time) and thus has
the least information in the information theoretic sense.
Note(symbols with less information require fewer bits to represent
them. From the example we can see that the Huffman code is
highly dependent on the histogram, so any preprocessing to the
histogram may help the compression ratio. Let us examine the
entropy in bits per pixel and average bit length for the Huffman
coded image file .

P
( i)
3
entropy= Pi log 2
i=0

=[(0.2) log 2 (0.2) + (0.3) log2 (0.3) +(0.1) log 2

(0.1)+(0.4) log 2 (0.4)

=1.846 bits/pixel
(note : log 2 (x) can be found by taking log10 (x) and multiplying by

3.322)
L1
Lave = I i Pi
i=0

=3(0.2)+2(0.3)+3(0.1)+1(0.4)

=1.9 bits/pixels (average length with Huffman code)

1.2 Run-Length Coding

Run-length coding (RLC) is an image compression method that


works by counting the number of adjacent pixels with the same
gray-level value. This count, called the run length, is then coded
and stored. Here we will explore several methods of run-length
coding-basic methods that are used primarily for binary (two-
valued) images and extended versions for gray-scale images.
Basic RLC is used primarily for binary images but can work with
complex images that have been preprocessed by thresholding to
reduce the number of gray levels to two.

basic RLC There are various ways to implement basic RLC, and
the first step is to define the required parameters. We can
either use horizontal RLC, counting along the rows, or vertical
RLC, counting along the columns. In basic horizontal RLC the
number of bits used for the coding depends on the number of
pixels in a row. If the row has 2 n pixels, then the required
number of bits is n, so that a run that is the length of the entire
row can be coded.
A 256 x 256 image requires 8 bits, since 28 = 256.

A 512 x 512 image requires 9 bits, since 29 = 512.

The next step is to define a convention for the first RLC number
in a row-does it

represent a run of 0's or 1's? Defining the convention for the first
RLC number to represent 0's, we can look at the following
example.

Example:

The image is an 8 x 8 binary image, which requires 3 bits for each


run-length coded word. In the actual image file are stored 1's and
0's, although upon display the 1's become 255 (white) and the 0's
are 0 (black). To apply RLC to this image, using horizontal RLC:
image Compression.

The RLC numbers are: First row: 8

Second row:0,4,4
Third row: 1, 2, 5

Fourth row;1,5,2

Fifth row: 1, 3,2,l,l

Sixth row 2,1,2,2,1

Seventh row: 0, 4, 1,1,2

Eighth row: 8

Note that in the second and seventh rows, the first RLC number is
0, since we are using the convention that the first number
corresponds to the number of zeros in a run.

RLC(G,L) : Another way to extend basic RLC to gray level


images is to include gray level of particular run as part of the
code. here instead of single value for a run, two parameter are
used to characterize the run. the pair (G,L) correspond to the
gray-level l value G and the run-length L. This technique is only
effective with images containing a small number of gray levels
.

Example:

Given the following 88 ,4-bit image:-


First row: 10,8

Second row: 10,5 12,3

Third row: 10,5 12,3

Fourth row: 0,3 10,3 0,3

Fifth row: 5,3 0,5

Sixth row: 5,3 10,2 9,2 10,1

Seventh row: 5,3 4,3 0,2

Eighth row: 0,8

These numbers are then stored in the RLC compressed file as:

10,8, 10,5, 12,3,L0,5,L2,3,0,3, 10,3,0,3,


5,3,0,5,5,3,70,2,9,2,10,1,5,3,4,3,0,2,0,8

The decompression process requires the number of pixels in a


row, and the type
of coding used.

2. LOSSY COMPRESSION METHODS :

In order to achieve high compression ratios with complex images,


lossy compression methods are required. images can be
compressed 10 to 20 times with virtually no visible information
loss, and 30 to 50 with minimal degradation. Image enhancement
and restoration techniques can be combined with lossy
compression schemes to improve appearance of the
decompressed image.

-Lossy compression is performed in both the spatial and transform


domains. We will explore method that utilize each of these
domains.
In the spatial domain we will discuss :

1- gray-level run-length coding (GLRLC) .

2- block truncation coding (BTC).

in the transform domain we will discuss :

1- JPEG algorithm

2.1 Gray-Level Run-Length Coding :

The RLC can also be used for lossy image compression by


reducing the number of gray levels and then applying standard
RLC techniques. A more sophisticated RLC algorithm for encoding
gray-level images is called the dynamic window-based RLC. This
algorithm relaxes the critertion of the runs being the same value
and allows for the runs to fall within a gray-level range, called the
dynamic window range.

This range is dynamic because it starts out larger than the actual
gray-level window range, and maximum and minimum values are
narrowed down to the actual range as each pixel value is
encountered. This process continues until a pixel is found out of
the actual range. The image is encoded with two values,one for
the run length and one to approximate the gray-level value of the
run, This approximation can simply be the average of all the gray-
level values in the run.

EXAMPLE:
This particular algorithm also uses some pre-processing to allow
for the run-length mapping to be coded so that a run can be any
length and is not constrained by the length of a row.

2.2 BIock Truncation Coding :


The basic form of BTC divides the image into 4 x 4 blocks and
codes each block using a two-level quantizer. The two levels are
selected so that the mean and variance of the gray levels within
the block are preserved. Each pixel value within the block is then
compared with a threshold, typically the mean, and then is
assigned to one of the two levels, If it is above the mean, it is
assigned the high-level code (1); if it is below the mean, it is
assigned the low-level code (0). After this is done, the 4 x 4 block
is encoded with 4 bytes: Since the original 4 x 4 subimage has 16
bytes and the resulting code has 4 bytes (two for the high and low
values, and two for the bit string), this provides a 16:4 or 4:1
compression.
fig (4)

Although the results of this algorithm are image dependent, it


tends to produce images with blocky effects as shown in the
Figure1.2. These artifacts can be smoothed by applying
enhancement techniques such as median and average (lowpass)
filters.
Fig (5) BIock Truncation Coding

2.3 Transform Coding :


Transform coding is a form of
block coding done in the
transform domain. The image is divided into blocks, or
subimages, and the transform is `calculated for each block. Any
of the previously defined transforms can be used, frequency (e.g.
Fourier (or sequency (e.g. Walsh), but it has been determined that
the discrete cosine transform (DCT) is optimal for most images.
After the transform has been calculated, the transform
coefficients are quantized and coded.

Joint Photographic Experts Group.

1- Divide the image into 8x8 subimages;

For each subimage do:


2- Shift the gray-levels in the range [-128, 127] (the pixel values
are level- shifted so that they are centered at zero )

- DCT requires range be centered around 0.

Example:

A typical 8-bit image has a range of gray levels from 0 to 255,


Level-shifting this range to be centered at zero involves
subtracting 128 from each pixel value, so the resulting range is
from 128 to 127.

3- Apply DCT

4-the DCT coefficients are quantized by dividing by the values in a


quantization table.

5- After the coeficients are quantized, they are coded using a


Huffman code

Fig (6) Flow-chart diagram of JPEG

Anda mungkin juga menyukai