A Lossless Image Compression Algorithm Using Variable Block Size Segmentation
A Lossless Image Compression Algorithm Using Variable Block Size Segmentation
A Lossless Image Compression Algorithm Using Variable Block Size Segmentation
OCTOBER 1995
Abstract-The redundancy in digital image representation can in combination with lossy methods have been used in some
~
be classified into two categories: local and global. In this paper, image applications. For example, the baseline system proposed
we present an analysis of two image characteristics that give rise in ISO-JPEG [18], an international still image standard, rec-
to local and global redundancy in image representation. Based
on this study, we propose a lossless image compression scheme ommends the use of Huffman coding or arithmetic coding
that exploits redundancy both at local and global levels in order to to encode the compressed image obtained after transform
obtain maximum compression efficiency. The proposed algorithm and quantization steps to further exploit redundancy. Lossless
segments the image into variable size blocks and encodes them methods are also used in specialized applications such as med-
depending on the characteristics exhibited by the pixels within ical imaging and satellite photography (such as level 0 or level
the block. The proposed algorithm is implemented in software
and its performance is better than other lossless compression 1A space image data of NASA [20]) where reliability of repro-
schemes such as the Huffman, the arithmetic, the Lempel-Ziv duction of images is a critical factor. For a survey of various
and the JPEG. methods for image compression, the reader is referred to [21].
The redundancy in digital image representation can be
I. INTRODUCTION classified into two categories: local and global. These two
objective of deriving a lossless image compression method is desirable to study the distribution of such characteristics
that works well on most of the images. In general, the perfor- in images in general and pick those characteristics that will
mance of image compression methods are image dependent. result in higher compression efficiency. Then it is possible to
A compression scheme performs well on a given image, design a versatile algorithm (i.e., an algorithm that works for
if the scheme is based on exploiting the specific type of most types of images). Further more, it is important to select
characteristic that is present within the image. Hence, in order the design parameters carefully so that the algorithm works
to derive a compression scheme that performs well on most efficiently (in terms of computational time as well as com-
images, we need to find out the characteristics that are widely pression efficiency). In this section, two image characteristics:
exhibited by images. Estimating the distribution of image smoothness and similarity that appear widely in images are
characteristics and the resulting compression efficiency is a studied in detail in order to understand their effect in image
very difficult task due to the huge amount of computations compression. The two characteristics are discussed below:
involved. However, by observing a simplified image domain I ) Smoothness: A given neighborhood (or block) in an
(images of size 32 x 32 with 256 gray levels) closely, we were image often exhibits coherence or correlation a property that
able to plot and compare the distributions of two common is commonly referred to as smoothness of the data. The
types of image characteristics generally utilized for lossless difference ( d ) between the minimum and maximum gray levels
image compression. This mathematical analysis also provides within a neighborhood is a suitable parameter to measure the
an understanding of the effect of some design parameters such smoothness. For example if d = 0, it means that every pixel
as the block size and search space on compression efficiency. in the block is of same gray level. In this case, the block
The second part of the paper presents an algorithm for can be represented by one pixel and the size of the box.
lossless compression based on some of the direct observations This representation is same as the run-length coding and it
from the mathematical model. The proposed image compres- requires the least amount of space. Even if the difference is
sion scheme exploits both types of redundancy in order to not equal to zero, it will generally be very small within a
get maximum compression for most types of images. The neighborhood. Hence, any given neighborhood can be rep-
performance of the proposed algorithm is studied by software resented by the minimum gray level (min) in the block and
implementation. The proposed algorithm works better than the offsets corresponding to the other pixels in the block with
other lossless compression schemes such as Huffman [4], respect to the min. Such a scheme is referred as base-offset
arithmetic [16], Lempe-Ziv [7], [8], and the JPEG [29]. The scheme (for representing a neighborhood) in this paper. By
knowing the value of d within a block, it is clearly possible
performance factor, Compression Efficiency (CE), used in this
to compute the compression efficiency that can be obtained
paper for performance comparison is defined as follows:
within the block. Since the parameter d directly affects the
original image size - compressed image size compression efficiency, it can be considered as the parameter
x 100. for estimating the efficiency of compression algorithms based
original image size
on the smoothness characteristic.
The outline of this paper is as follows: A detailed ex- 2 ) Similarity: In general, a given pattem might repeat itself
planation of two typical image characteristics that lead to anywhere in the rest of the image. If a pattern repeats itself n
redundancy is presented in Section 11. A mathematical model times in an image, then (n - 1) patterns can be replaced by
that represents the distribution of the image characteristics and pointers to one of the occurrences of the pattern. For example,
quantitative analysis of the model is presented for a sample Lempel-Ziv compression schemes search for linear repeated
image domain. Based on this study, a new algorithm for patterns (or strings) in the data and replaces them with pointers
lossless image compression is proposed in Section I11 and to their previous occurrences [7], [8]. To determine how good
its complexity analysis is presented in Section IV. Section
this characteristic is from image compression point of view,
V concludes the paper.
we need to partition an image into subregions, consider each
11. LOCALAND GLOBALREDUNDANCY subregion as a pattern, and estimate how many times each
IN IMAGES: AN ANALYSIS pattern repeats itself in the entire image. Once the amount of
repetition is known, the compression efficiency that can be
In general, images exhibit characteristics that give rise to
achieved on the image can be estimated. We reformulate this
local and global redundancies in image representation. The
similarity estimation problem as a grid coloring problem in
compression efficiency that can be obtained on an image
Section 11-B and estimate the distribution of this characteristic
depends mainly on the image characteristics. Hence, image
within images.
compression schemes are generally designed to exploit the
presence of such characteristics. Further, implementation as- As a first step in the mathematical analysis, the set of all
pects such as the image partitioning strategy, the block size, the images of a given representation scheme is divided into a
area of search space, etc., influence the compression efficiency distinct number of classes. This classification is based on the
as well as the computational complexity. An algorithm will degree of smoothness and similarity present in each class of
achieve the best possible compression efficiency if 1) it ex- images. The purpose of this classification is:
ploits all the characteristics that contribute to the compression to estimate the number of images that exhibit a specific
and 2) employs efficient implementation strategies. However, Characteristic (smoothness or simdurity) at varying levels.
it is not possible to design an algorithm that will exploit to estimate the maximum compression that is possible to
every characteristic that leads toward compression. Hence, it obtain in each class of images.
1398 IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 4. NO. IO, OCTOBER 1995
i=l j=;
(;) ( a - 2 ) ( d - 1)-
u-.7
two characteristics i) smoothness and ii) similuriry in them.
The above result delivers the summation from N [ K ,21 to distribution of different K x K blocks in an image) is known,
N [ K ,C - 11. Adding N [ K ,01, which is equal to C , and then the compression efficiency that can be obtained on a given
N [ K ,11, which is equal to (C - 1)2" - 2(C - 1) results image can be determined from the following equation.
in the sum of all subsets, yielding N [ K ,d] = C" =
~~~~
Let A: (ao, a l , . . . , a l ) represent a tuple where the compo- Comb [A]represents the number of images that can be formed
nents a; represent the number of K x K blocks belonging to from the K x K blocks selected according to the tuple A.
the partition i , subject to the following conditions: Finally, we can estimate the total number of images that can
be formed from all tuples belonging to the set S as
i E [O, log, (C)l
Comb[S]= Comb[A]
AES
B. Classification Based on Similarity Characteristic nonoverlapping blocks. If K x K is the size of each block,
In this section, a classification of images based on the the image can be subdivided into b uniformly sized blocks,
similarity characteristic is described. Suppose, an image is where b is equal to ( N 2 / K 2 ) Each
. of the blocks can be
divided into blocks of size K x K , then it consists of h blocks, assigned p color patterns, where p = C K 2 .If there are IC
where each block can take on p possible patterns, where b and distinct patterns in the image, then an upper bound for the
p are given by compression efficiency is given by ( b - k / h ) x IO0 since
( b - k ) out of b blocks can be replaced by pointers. Since,
the image consists of b blocks and there are p patterns to
choose from, the number of distinct patterns in the image can
p =CKL. (16) vary from I to b (if b < p ) or from 1 to p (if p < 6). This
Furthermore, let P be the set of all possible color patterns implies, that the entire set of images can be subdivided into
associated with any given block, then we say the cardinality b or p disjoint subsets (Cl, cz, ..., ch, ..., cp) based on
N [ P ] = p. For the sake of argument, let the compression the number of distinctly colored blocks in the image. Each of
efficiency we are aiming at be 60%. This desired goal of these subsets gives rise to a different compression efficiency.
compression is possible only if 40% of the blocks are colored Using the block coloring example discussed earlier, we can
such that every block is distinct from every other pattern and determine the number of images in each of these subsets (Cl,
the remaining 60% of the blocks are colored with duplicated C2, ..., Cb, ..., Cp). Let N[Ck]be the cardinality of the
patterns. The cardinality of the set of images exhibiting such subset C k .
characteristic can be determined by estimating the number
of ways b blocks can be colored, such that exactly 40% of
them are colored with distinct patterns selected from p color
patterns. Suppose one is given a grid consisting of 36 blocks
to paint and a color palette with 12 different colors. How
many ways can one paint this grid using exactly 1, 2, 3 ,
. . ., 12 colors? This task can be performed as follows: let
N[Ck]represent number of ways the grid can be colored using
exactly k colors. To estimate N[C1],we find out the number
of ways one color can be selected from 12 colors. which is
equal to (‘f)and multiply this number with the number of
ways the grid can be colored using one color. This gives us ..
the result N[G1] = (‘1”).
To determine N[C2],first we find
out the number of ways two colors can be selected from 12
colors, which is equal to ( i2)
and multiply this number with
the number of ways the grid can be colored using exactly
two colors. The number of ways the grid can be colored
with exactly two colors can be determined by subtracting the
number of ways the grid can be colored using any one of
the two colors, which is equal to (:)1 from the number ways
the grid can be colored using up to two colors This
gives us the result N[C2]= - (;)I. Following this
procedure, we can determine N[C3],N[C;1], ..., N[12]. All
,
the images in the class N [ C k ]can be compressed to ( k / 3 6 ) %
giving rise to (36 - k/36)0/;, compression efficiency where
I; varies from 1-12. Notice that the maximum value of I; is
equal to the smaller of the two values b and p . Hence, the
possible compression efficiencies run from O / h to ( h - I / b ) %
in steps of l / b increments or from O / b to ( p - l / b ) % in steps
of l / b increments depending on whether b is smaller or p is
smaller. The following theorem provides the classification of
images based on the characteristic similarity with respect to
the compression efficiency parameter. f
Theorem 2: Let iV x N be the image size, and let G be the
maximum number of gray values in any given image 1 E ZAT.
Then the set of images Z , can be classified into a finite
number of disjoint subsets based on the similarity exhibited
by the images, such that there is a maximum upper bound of
compression efficiency associated with each of the subsets.
Pro08 To utilize the characteristic similarity, a
given image is required to be decomposed into a set of
RANGANATHAN et al.: A LOSSLESS IMAGE COMPRESSION ALGORITHM USING VARIABLE BLOCK S U E SEGMENTATION 1401
+ + + N[C,] = pb.
N[C1] N[C2] . . .
C. Analysis
In this section, we provide an analysis based on the math-
ematical model presented in the previous subsections. The
model requires three parameters (C. K , N ) to represent a
set of images. First, the distributions of each of the two
characteristics smoothness and similarity are independently
estimated for the set of images represented by (C = 256,
K = 2, and N = 8).
These results are shown in Fig. l(a). The plots shown
in Fig. l(b) and (cj are obtained by keeping the maximum
number of gray colors (C = 256) and the block size ( K = 2 ) Compression Efficiency
constant and increasing the size of the image ( N ) . The com- (b)
putations are performed using Mathematica software package. le+03 . . . , . . . .
Due to the huge size of numbers involved, it was possible
to compute the distributions of the characteristics for images
of size up to 32 x 32 only. The plots clearly indicate that as
the size of the image is increased, the global characteristic
similarity becomes a versatile characteristic and it contributes
significantly to the compression efficiency. From this first
set of results we conclude that any compression scheme
should exploit a global characteristic in order to achieve good
compression efficiency. In order to increase the compression
rates, it is desirable to look for more than one characteristic.
In particular, a combination of disjoint characteristics (with
no common aspects) such as similarity and smoothness will CompressionEtllciency
result in more efficient compression algorithms. One important (c)
issue in implementing a compression scheme based on a global Fig. 1. (a) Distribution of characteristics in images of size S x 8 with 256
characteristics such as similarity is the degree of global search gray colors. (b) Distribution of characteristics in image size 16 x 16 with
that should be conducted. In Fig. 2(a), we show the effect of 256 gray colors. (c) Distribution of characteristics in images of size 32 x 32
with 256 gray colors.
block size ( K ) on the number of images of size N (=16
in this case) exhibiting similarity characteristic. Obviously,
as the size of the block is increased the number of images
that have a high degree of similarify decreases drastically. scheme such as similarity practically feasible for large N . The
The observed behavior can be explained by the simple fact loss in possible compression on the other hand due to this
that as the block size ( K ) increases the probability of finding restriction will be limited. Finally, the last graph Fig. 2(b)
identical matches in a fixed size image decreases (fewer depicts the results for different sizes of K for exploiting the
combinations can be detected). From this, we can conclude smoothness characteristic. Similar to the previous graph this
that the choice of K should be limited to a few small graph shows that for most of the images significant portion of
values rather than attempting matches for large K . This also compression efficiency can be obtained by selecting a block
implies that the probability of finding pattern matches outside size of 2. Selecting larger sized blocks can improve results.
some small predefined neighborhood decreases. This has the When N = 16 for example, a block size of 4 gives highest
desired benefit of decreasing search time and making a global compression efficiency for most of the images. From this
1402 1EEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 4, NO. 10. OCTOBER 1995
TABLE I
-K=2 LOCALAND GLOBAL
CODING
SCHEMES
USEDIN THE COMPRESSION
ALGORITHM
.... K . 4
Compression Eficiency
(a)
Compression Efficiency
(b)
east). Hence, it is not necessary to represent the base
Fig. 2. Distribution of characteristics in images of size 16 x 16 and block
sizes of K = 2. 4. and 8. (a) Distribution of similarity characteristic. (b) pixel. Instead, the direction of the selected reference
Distribution of smoothness characteristic. pixel is specified by using two bits. The direction of the
reference pixel is updated for every block. The selection
of the reference pixel from the neighboring pixels is
observation, we can conclude that for exploiting smoothness, based on the nearest neighborhood principle presented
variable block segmentation is necessary. For the purpose of in [28]. The header entry for this block consists of the
this paper, any further experiments are not required, but may category to which this block belongs (in which the size
be considered for future work. Instead, we next draw our of the block is implicitly encoded) and it is stored in
attention to applying the results found so far in developing a separate header file. Since three different sizes are
a compression algorithm. considered, three categories (0, 1, and 2 as shown in
Table I) belong to this classification.
111. A LOSSLESS IMAGE COMPRESSION ALGORITHM 2) Block matching: In our scheme, the area of search
USING VARIABLEBLOCKSIZESEGMENTATION space is chosen as four times the size of the block
In our implementation, a given image is segmented into being considered. The codeword for this coding scheme
square sized blocks of sizes eight, four, and two. Each block consists of the differences along z and y directions from
is classified into one of the twenty eight categories depending the pattern under consideration and an identical pattern
on the size of the block as well as characteristic exhibited by if it was found within the search space. Hence, the
the pixels within the block. Three coding schemes are utilized length of the codeword depends on the area of search
to encode these blocks. The coding schemes and the codewords space. For a 2 x 2 block, the length of the codeword
for each of the twenty eight categories are listed in Table I. is eight. Category 5 (shown in Table I) falls under this
1) Run-length coding: If the maximum difference (d) within classification. Again, the header for the block consists
a block is zero, (i.e., all the pixels in the block under of the category to which the block belongs and is
consideration are of the same color), run-length coding stored separately in a header file. In our algorithm, block
is utilized to optimally encode the block. In this case, the matching is implemented only for 2 x 2 blocks to reduce
block can be represented by one pixel (the base) and the the computational complexity involved with the search.
size of the block. In our scheme, each pixel is encoded 3 ) Base-offset coding scheme: Base-offset coding scheme is
as an offset with respect to one of its three neighboring followed if the maximum difference d within the block
pixels (north, east, and north east) or with respect to is sufficiently small but not equal to zero. For 8 x 8 and
the average of two of its neighboring pixels (north and 4 x 4 blocks, the codeword consists of offsets for all
RANGANATHAN et al.: A LOSSLESS IMAGE COMPRESSION ALGORITHM USING VARIABLE BLOCK SIZE SEGMENTATION 1403
pixels in the block and the direction of the base pixel. Segment the image into
The categories 3, 4, and from 6 2 6 (in Table I) belong blocks of size K x K.
For each block repeat
to this classification. The length of the codeword (which
the following steps.
excludes the header information) is equal to n x log,
(Maximum offset) where n is the number of pixels in
the block and two bits to represent the direction of the difference
base pixel. Else encode the blwk
If none of the above schemes are applicable, then the pixels using base-offset scheme
in the block are represented as they are without any encoding
(category 27 in Table I). This scheme is followed only for
2 x 2 blocks. Four bytes are required to represent the block.
The category information is stored separately in the header file.
K=2?
A. Proposed Algorithm
The proposed algorithm for lossless image compression is
no
given in the form of a flow chart in Fig. 3. The algorithm
works as follows: Initially, the given image is partitioned
into uniformly sized blocks of size K x K . In our scheme,
the initial value of K is selected as eight. If all the pixels
Subdivide the block into
four smaller blocks of
size W2 x W2. For each
subblock repeat the
above steps.
Encode the block
using base-offset
I
in the block are of the same gray level, then the block is
encoded using run length encoding scheme. If the degree of
variation in the block is reasonably small, then the block Fig. 3. Flowchart for the proposed compression algorithm.
is coded using base-offset method. If both the above tests
fail, then the block is subdivided into four smaller blocks of
size K / 2 x K/2. Each of the four blocks are again analyzed Iv. AND SPACE COMF'LEXITY ANALYSIS
for the local and global characteristics described above. This
In this section, the time and space complexities (we refer
procedure is continued successively by reducing the size of
the blocks to half of their size at every step till the block size to run-time storage requirement) of the proposed algorithm
( K ) becomes 2 x 2. When the size of the block is 2 x 2, a exploiting the smoothness and similarity characteristics are
analyzed. The results of the analysis are stated in the following
different approach is followed. If all pixels in the block are
theorem.
of same gray level, the run length coding scheme is applied.
Otherwise, the neighborhood area of the block is searched to Theorem 3: Let N x N be the size of an image and K x K
find if an identical block exists. If such an identical block is be the size of the block. An algorithm that implements the
smoothness characteristic for image compression has a time
located, then the block is encoded by a pointer representing its
distance along z and y directions from its previous occurrence. order OTime(N>K ) = N 2 and requires Ospac-(N, K ) = K 2
space. The time and space complexities are the same for
If both above tests fail, then the block is coded using the base-
offset scheme provided the degree of variation is less than a average, best and worst cases. An algorithm that is based on
specified threshold. similarity has the following complexity behavior:
If the degree of variation exceeds the threshold, then the four
pixels in the 2 x 2 block are stored as they are without any
compression. As the image is encoded, a compressed image
file consisting of the codewords for the variable size blocks as
well as a header file are created. The header file keeps track
of the category number for each codeword and updates the
frequency of each codeword while the coding is in progress.
At the end of coding, the header file is compressed separately
using Huffman coding scheme.
For comparison purposes, we considered the LZW scheme
(compress utility on UNIX), the LZ77 scheme (gzip utility on
UNIX), the adaptive Huffman scheme (compact on UNIX), the The average, best, and 'worst case storage requirements are
arithmetic scheme [ 161 and the JPEG. The software for lossless given by
JPEG is obtained from the public domain facility at Stanford
University. The results for a selected set of fourteen images
are shown in Table 11. From this table, it can be observed that N* + K~
the proposed algorithm yields better compression compared to OAvgStorage(N1 K)= 2
all other schemes. The characteristic distribution in all the test
images is also listed in Table 111.
1404 IEEE TRANSACTIONS ON IMAGE PROCESSING. VOL. 4, NO. IO, OCTOBER 1995
E= The Holfman (Unix compact) scheme, A= The arithmetic scheme, LZ = The Lempel-Ziv (Unix Compress) scheme,
The LZ'I'f(Unix GZIP) scheme, Jx = The JPEG scheme with prediction method x, P = The propcaed scheme.
Proof: We first prove the results for the characteristic Hence, the time complexity for average, worst, and best case
smoothness. are as follows:
1) Average Time Case:
(hi/K )
(K2+ l ) i
( N / K ) -~
1
i=l OAvgTime(N: K, =
2
= ( K 2- 1) ($) 2 a=O
- K2 - 1
- N2
K'
= N2 (assuming K << N ) . (21)
i=O
=K2{ (g)4-(g)'}
in which BT,, represents the number of block matching steps
required during compression. For each of the three complexity
cases, BT, is given by
3 ) Best Time Case:
i=O
Finally, the results for the space complexity for the similar-
ity characteristic are straight forward. In the worst case, the
whole image needs to be stored in form of (N/K)' K-blocks,
RANGANATHAN et al.: A LOSSLESS IMAGE COMPRESSION ALGORITHM USING VARIABLE BLOCK SIZE SEGMENTATION 1405
Steve G. RomaNuk received B.S., M.S., and Ph.D. Kameswara Rao Namuduri received the B.Tech.
degrees from the University of South Florida in degree from Osmania University, India, the M.Tech.
1988, 1989, and 1991, respectively. degree from University of Hyderabad, India, and the
He was a Teaching Fellow at the National Uni- Ph.D. degree from the University of South Florida
versity of Singapore from 1992-1994. in 1984, 1986, and 1992, respectively.
He worked as a Research and Development En-
gineer in Center for Development of Telematics,
Bangalore, India from 19861988. Currently, he is
working as a System Analyst developing cellular
fraud detection products at GTE, Tampa. His re-
search interests include cellular telecommunications
and mathematical models from computer vision.