Vous êtes sur la page 1sur 10

LOSS LESS IMAGE COMPRESSION USING

SEQUENTIAL APPROACH

Shilpi Bose Jaya Sil Anindya Bhattacharya


Computer Science & Engineering Department, University of Calcutta,
92, A.P.C. Road, Kolkata – 700 009, India
jayasil@hotmail.com

ABSTRACT
A sequential image compression technique has been proposed in this paper for obtaining loss
less image at the receiving side. Apart from the benefit of sequential processing the time
complexity of the algorithm is significantly small compare to the q uadratic approaches. The
compressed code is stored judiciously to facilitate the decompression process for retrieving the
original image. The compression algorithm has been applied successfully on bitmap images,
results good compression ratio.

1. INTRODUCTION
Digital image compression techniques [1,2] address the problem of reducing the amount of
redundant data present in a digital image, which is basically transforming a 2 -dimensional pixel
array, represents the image into a statistically uncorrelated [3 ] data set. The compressed image
is decompressed [4] at the receiving side to reconstruct the original image or an approximation
of it. There are two basic compression techniques lossy and loss less [5]. Lossy compression
technique results in loss of real or quantitative visual information [6]. This technique is not
suitable for many applications like medical image processing, while loss less image
compression results retrieval of original image after decompression [7].

The proposed sequential image compr ession algorithm precedes to resulting loss less
image compression. The image is partitioned into a number of segments [8] depending on the
image size while each segment is processed one after another purely on sequential basis. In
quadratic approach [8] e ach quad or segment is recursively processed until it satisfies the
stopping criteria of the algorithm. This makes quad tree algorithm or other recursive approach
unimpressive in terms of time compare to our sequential approach where each pixel is scanned
only once. In the previous sequential compression algorithms such as run length encoding
(RLE) [9] the decision taken to scan the pixels of the segments either row wise or column wise
is purely ad hoc in nature. This results inefficient compression when sc anning decision
(row/column) and inter pixel similarity in a segment contradicts with each other. Our approach
takes the decision (either row or column wise scan) separately for each segment by selecting a
small area (SA) of the segment determined by an a ppropriate heuristic function [10] designed
after analyzing a handful number of images. Analysis of various types of images reveals that the
pixel pattern of the SA reflects the overall pixel pattern of the whole segment. In general, the
square root of width and square root of height of a segment determine the size of the SA. For
example, in Fig. 1 the segment is 16*16 and therefore, the SA is 4*4 in size. The start and end
coordinates of the SA is determined by aligning the central pixel location of the se gment with
the same of the SA, as shown in Fig. 1. Using RLE method, the SA is compressed by
separately scanning the pixels row and column wise, while the best result is then invoked for
compressing the whole segment. The compression codes are stored judic iously to facilitate the
decompression process, that retrieves the originaly image at the receiving side.
1,1 1,N

4*4
M? N

small area
M,1 M,N of a segment 16*16

Figure 1. Segment generation procedure

The paper has been classified into four sections. The proposed sequential algorithm for
image compression and decompression has been presented in section 2. Several
testing images are presented and the merits and demerits of the algorithm have been
also discussed in section 3. Finally conclusions are summarized in section 4.

2 SEQUENTIAL IMAGE COMPRESSION ALGORITHMS

The input digital image considered for c ompression is a M? N matrix with height M and width N
while the number of pixels in this image is MN that determines the size of the image, as shown
in Fig. 2.
1,1 1,N

M? N

M,1 M,N

Figure 2. Image as a 2 -D matrix

2.1 Image Partitioning

Depending on the size of the image it is partitioned into several segments as shown in Fig. 3.
For the sake of computational simplicity the image is partitioned into a number of segments,
which is power of 2.

M/2? N/2
M/2? N/2
Figure 3. Partitioning of image

Analyzing images of d ifferent sizes, the heuristic function, given below has been employed for
determining the number of segments.

?? If the number of pixel is less than or equal to 1024, the whole image is treated as
a single segment (see, Fig. 4).

M? N M? N

Figure 4. No segmentation

?? If the number of pixel is greater than 1024 but less than or equal to 4000 then
divide it into four segments as shown in Fig. 5.

M? N M/2? N/2 M/2? N/2

ts

Figure 5. Each segment of size M/2xN/2

?? If the number of pixel is greater than 4000 but less than 6000 then divide it into
eight segments as shown in Fig. 6.

M? N

Figure 6. Each segm ent of size M /2? N /4

?? If the number of pixel is greater than 6000 then d ivide it into sixteen segments as
shown in Fig. 7.

M? N
Figure 7. Each segment of size M/4? N/4

After segmentation each segment of the image is sequentially processed from top to bottom
and left to right direction, as shown in Fig. 8.

1 2 3
4

5 6 7
8

Figure 8. Scanning of image segments

2.2 Order of Scanning

Whether a segment is to be scann ed row or column wise has been decided by analyzing the SA
of the segment, almost middle of the segmented area. The square root of height and width of
the segment determine the dimension of the SA. The pixels of the SA are scanned row and
column wise separately and for each of the cases the pixels are compressed using RLE
method. Two compression ratios thus obtained are compared and obviously, the one with
higher compression ratio has been invoked for compressing the whole segment.

2.3 Intermediate Storage of Pixel

In the proposed compression and decompression algorithm 24 bit colored bitmap image
has been considered. Each pixel of the image consisting of four components where the
first part determines the intensity of color blue, next part determines colo r green and the
last but one part determines red color while the last part is reserved. Each part is of one
byte in length. The storage structure of a pixel is shown in Fig. 9.

blue gre en red reserved

1 byte 1 byte 1 byte 1 byte

Figure 9. Pixel storage structure

In the BMP image file, pixels are stored in consecutive locations in row wise fashion
following the header of the file as shown in Fig. 10.

header (54 bytes) pixel 1 pixel 2 pixel 3 pixel pixel n


4
1Byte each

blue green red reserved

Figure 10. Storage structure of a BMP file

All pixels of the BMP file are read sequentially and red, green, blue components of each pixel
are stored separately into three different intermediate storages, as shown in Fig. 11.

blue green red reserved

1 byte 1 byte 1 byte 1 byte

storage for storage for green storage for


blue pixels pixels red pixels Not us
not used

Figure 11. Intermediate storage of pixels of a segment

2.4 Compression Technique

First the image is partitioned into number of segments depending on its size, as discussed in
2.1. Pixel at any location of a particular segment could be read directly from the intermediate
storage locations by evaluating the transformation function given in expression (1). This
transformation requires one multiplication and one addition operation to refer the pixels from the
intermediate storage instead of accessing from the BMP file, thus saving considerable amount
of time.

x= (i-1) * w + (j-1) … … … … … (1)

where (i,j) represents the coordinate of the pixel in the image file (BMP file) and w represents
the width of the image. Therefore, the pixel at (i,j) location of the BMP file corresponding to the
pixel stored at location x of the intermediate storages.

Pixels stored in the intermediate storages are compressed either row or column wise based on
the decision taken in section 2.2. The proposed algorithm generates compressed code
separately for blue, green and red components of the pixels of each segment using RLE
method. Each pixel with respect to its blue, green and red component is compared with its
neighboring pixel for similarity or difference. If it is similar then incr ement a counter and proceed
for the next pixel location until dissimilarity observed. When dissimilarity is detected the count
value indicates the number of similar pixels in contiguous locations. If the count value is below
255 then two consecutive locati ons are reserved in a buffer, one for storing the number of
similarity and another for the pixel. In case it is greater than 255 then three locations are
reserved, one for indicating that the number of similarity is greater than 255. It is worth that we
have use unsigned integer variable for counting number of similarity.

The compressed codes are stored into temporary storage location, named compressed code
storage (CCS). The proposed algorithm along with the compressed codes stores several
important numbers in the CCS as indicators, which do not appear frequently in the BMP images
to facilitate the implementation of the decompression method. The indicators are defined
below.

1) The algorithm stores an indicator 50/150 at the first location of the CCS (Fig .12) to indicate
that the pixels are compressed in row wise/column wise fashion.
2) An indicator 222 (Fig.12) is stored in the CCS at the end of each compressed code of
blue, green and red pixel. This number is used as a separator between the compressed
blue, green and red pixels.
3) The indicator 111/109 (Fig.12) is stored in the CCS to represent the fact that the number
at the next location is a count value i.e. number of times similar pixel appeared in
consecutive locations. Two different numbers (111 and 109 ) are used for the same
purpose in order to tackle the implementation issues. When count value is greater than
255, it is stored as unsigned long integer and hence 111 is used as indicator while less
than 255 is stored as unsigned character, represented by 109.

The value of the indicator(s) may be same with the pixel at any location of the image
file which creates confusion while retrieving the pixels during decompression process.
This phenomenon has been avoided while generating the compressed code, si mply by
decreasing or increasing the above mentioned pixel value. Suppose when a pixel 50
appears it is incremented to 51, 222 is decremented to 221 and so on. For generating
the compressed code say, blue pixel of value 58 appear in 567 consecutive locati ons
followed by 160 consecutive locations with 0 followed by 5 in single location etc., then
the compressed code for blue values of the segment in question will contain numbers
111, 567, 58, 109, 160, 0, 5… .. Compressed code for blue, green and red pixels of
each segment are written in the CCS (Fig.12). Thus, other segments are sequentially
compressed and copied down in a file.
separator separator

50/150 blue 222 green 222 red

decision color color color

111 567 58 109 160 0 5 -----------------

count indicator number of similar valued pixel


pixel value

Figure 12. Storage structure of the compressed code storage (CCS)

In decompression process the compressed data file produced by the compression


procedure is used to produce a bitmap file that is equivalent to that of the original
bitmap file. First, the header structure of the bitmap file (inputted for compres sion) is
simply written to the decompressed file. Width and height of the bitmap file is available
from the header information, which is used to calculate the number of pixels of the input
image. The input image was segmented depending on the image size i .e. no. of pixels
and now using the same approach number of segments that the bitmap was divided into
is known. Finally, the reverse procedure of compression is applied to decompress the
image, which is very much similar to the original one.

2.5 Compression Algorithm

D ata S tructure

breadth: integer variable represents width of the input image.


depth: integer variable represents height of the input image.
inner-offset: integer variable mentions dimension of the array where pixel of the selected
portion is stored.
Algorithm:
Input: the BMP file (*.bmp) to be compressed.
Output: the data file consisting compressed data.
Procedure Compression
Step 1: open the input BMP (*.bmp) file in read binary mode and an output data file in write
mode.
Step 2: read the header from the BMP file.
Step 3: store the header in the output data file.
Step 4: assign the width and height of the input image into breadth and depth respectively.
Step 5: call scale-factor. scale-factor function determines the width and height of each
segment. Taking the width and height of the whole image as input. Partitioning of the image into
number of segments depends on the size (number of pixels) of the BMP file.
Step 6: square root of breadth or depth of a segment, is assigned to the
inner-offset and determines the dimension (width / height) of the SA.
Step 7: for each segment (created by the scale-factor) do the following:
a) call decision-compression. decision-compression function decides whether a
segment is scanned row wise or column wise, described in section 2.2.
b) if return mode is '0' i.e. row major then call row-compressed.
if the return mode is '1' i.e. column major then call column-compressed.
row-compressed/ column-compressed function takes two endpoints of a particular
segment for compression. In the original BMP file the pixels are stored in consecutive
locations starting from 55 th bytes, from where the pixels are read and blue, green, red
components of the pixels are stored into the corresponding intermediate storage locations,
discussed in 2.3. After finishing the storing operation the algorithm calls the function
segment-compress for generating the compressed code of the whole segment while
scanning the pixels row/column wise based on the decision taken on the SA.
Step 8: end.

3. TEST IMAGES
Sequential compression method that is developed and implemented in the paper has been
tested for the following set of images.
Test image 1:

Before compression After decompression


Test image 2:

Before Compression After Decompression

Test image 3:

Before Compression After decompression

Test Image File Size File Size after Percentage of Visual

No. Before Compression Compression information

Compression loss

1 40.0KB 21.7KB 54.25 No

2 39.5KB 30.1KB 23.8 No

2 35.2KB 29.6KB 14.9 No

The test images show that image data compression has been achieved by the proposed
algorithms though percentage of compression is varied from case to case. Percentage of
compression totally depends on the type of the input image expressing the fact that
inter-pixel redundancy is more percentage of compression is high otherwise low.
4. CONCLUSION

The paper dem onstrates that the proposed algorithm s can do data com pression w ithout
adding any significant overhead (for exam ple avoiding recursion in quad tree approach) in
term s of com puting cost or algorithm com plexity, w hich is O (N ) and depends on the num ber
of pixels in the B M P file, say N . W hen com bining this sim plicity w ith other features such as
no loss in term s of colors, shades and shapes the im age com pression algorithm can be
considered to have considerable im provem ents.Though the algorithm s have been tested only
for the B M P files, com pression w ith other im age files [11] is also possible after slight
m odification on retrieval and storage techniques. Im age inform ation need to be changed
based on header structure and storage structure of pixels w hile applying the algorithm s on
other im age files.

REFERENC ES
nd
[1] David Salomon, “Data Compression The Complete Reference”2 Edition, Springer. 2000.
[2] Gonzales, R.C. and Woods, R.E., Digital Image Processing, Addision -Wesley, Menlo Park,
1992.
[3] A.P Berman and L.G Shapiro, “A flexible image database system for content -based
retrieval,”Computer Vision and image Understanding, Vol. 7 5, 1999.
[4] Bentley, J.L. et al., “A Locally Adaptive Data Compression Algorithm,”Communication of the
ACM 29(4): 320-330, April, 1986.
[5] Ekstrand, Nicklas, “Losslesss Compression of Gray Image via Context Tree Weighting,”in
Storer, James A. (ed.), DCC’96: Data Compression Conference, Los Alamitos, CA, IEEE
Computer Society Press, pp. 132 -139, April, 1996.
[6] Anderson, K.L., et al., “Binary -Image-Manipulation Algorithm in the Image View Facility,”IBM
Journal of Research and Development 31(1): 16 -31, January, 1987.
[7] Barnsley, M.F., and Sloan, A.D., “A Better Way to Compress Images,”Byte Magazine
pp:215-222 January, 1988.
[8] Anedda, C.and L., et al.,“P -Compressed Quadtrees for Image Storing,”The Computer
Journal, 31(4):353-357, 1988.
[9] Gharavi, H.,“Conditional Run -Length and Variable -Length Coding of Digital Pictures,”IEEE
transaction on Communication, COM-35(6):671-677, June, 1988.
[10] Lenat D.B., “Heuristics : The nature of heuristics,”Artificial Intelligence, Vol. 19, No. 2,Oct.
1982.
[11] MPEG Requirements Group, “MPEG -7 requirements document,”ISO/IEC, July, 1998

Vous aimerez peut-être aussi