Lossless Image Compression and Decompression Using Huffman Coding
Total Page:16
File Type:pdf, Size:1020Kb
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 02 Issue: 01 | Apr-2015 www.irjet.net p-ISSN: 2395-0072 LOSSLESS IMAGE COMPRESSION AND DECOMPRESSION USING HUFFMAN CODING Anitha. S, Assistant Professor, GAC for women, Tiruchendur,TamilNadu,India. Abstract - This paper propose a novel Image the training set (neighbors), reduce some redundancies. compression based on the Huffman encoding and Context based compression algorithms are used predictive technique [2][3]. decoding technique. Image files contain some redundant and inappropriate information. Image compression 2. HISTORY addresses the problem of reducing the amount of data required to represent an image. Huffman encoding and Morse code, invented in 1838 for use in telegraphy, is an decoding is very easy to implement and it reduce the early example of data compression based on using shorter codeword’s for letters such as "e" and "t" that are more complexity of memory. Major goal of this paper is to common in English. Modern work on data compression provide practical ways of exploring Huffman coding began in the late 1940s with the development of information technique using MATLAB . theory. In 1949 Claude Shannon and Robert Fano devised a systematic way to assign codeword’s based on probabilities Keywords - Image compression, Huffman encoding, Huffman of blocks. An optimal method for doing this was then found decoding, Symbol, Source reduction… by David Huffman in 1951.In 1980’s a joint committee , known as joint photographic experts group (JPEG) 1. INTRODUCTION developed first international compression standard for continuous tone images. JPEG algorithm included several A commonly image contain redundant information i.e. modes of operations. Steps in JPEG because of neighboring pixels which are correlated and Contain redundant information. The main objective of image 1. Color image converted from RGB to YCbCr compression [1][9] is redundancy and irrelevancy 2. The resolution of chromo components is reduced by a reduction. It needs to represent an image by removing factor of 2 or 3. This reflects that the eye is less sensitive to redundancies as much as possible, while keeping the fine color details than to brightness details resolution and visual quality of compressed image as close to the original image. Decompression is the inverse 3. Image is converted into 8X8 matrix processes of compression i.e. get back the original image from compressed image. Compression ratio is defined as the 4. DCT, Quantization is applied and finally compressed ratio of information units an original image and compressed 5. Decoding is reversible process except quantization is Compression is performed by three kinds of redundancies. irreversible. (1) coding redundancy 3 . CODING REDUNDANCY: (2) Spatial or temporal or inter pixel redundancy Rk is distinct random variable, for k=1,2,…L with related probability (3) Psycho visual Redundancy Pr(rk)=nk/n Compression further divided into predictive and transform coding. Transformed coding means, the large amount of where k=1,2,…L, Kth gray level in an image is represented by information are transferred into very small number of ‘nk’and ‘n’ is used to specifiy total number of pixels in the blocks. One of the best examples of transformed coding image. (rk) is the total number of bits used to symbolize technique is wavelet transform. Predictive means based on © 2015, IRJET.NET- All Rights Reserved Page 240 International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 02 Issue: 01 | Apr-2015 www.irjet.net p-ISSN: 2395-0072 each pixel in the still image then the average number of bits required to represent each pixel [4] is L Lavg= ∑ l(rk)pr(rk) K=1 The average length of the code words is calculated by summing the number of bits used to represent the gray level and the probability that the gray level which placed in an Fig 1:sample(a) Fig 2: sample(b) image. Table 1:Coding redundancy Rk Pr(rk) Code1 L1(rk) Code2 L2(rk R1 0.1875 00 2 011 3 R2 0.5 01 2 1 1 R3 0.1250 10 2 010 3 Histogram of Fig 1 & 2 R4 0.1875 11 2 00 2 These observations highlight the fact that variable – length coding is not designed to take advantage of the structural Lavg=2 for code1;Lavg=1.81 for code 2. relationship s between the aligned matches in Fig2.Although the pixel to pixel correlations are more important in the Fig Coding redundancy is always present when the gray levels 1. Because the values of the pixels in either image can be of an image are coded using a binary code. In that table 1, predicted by their neighbors, the information carried by both a fixed and variable length encoding of a four level individual pixels is relatively small. visual contribution of a image is shown. Column two represents the gray level single pixel to an image is redundant; it could be predicted distribution. The 2-bit binary encoding (code1 ) is shown in by their neighbors. column 3. It has an average length of 2 bits. The average number of bits required by code2 (in column 5) is 5. PSYCHO VISUAL REDUNDANCY: Lavg=∑4 l (k)p (r ) 2 r k In general, an observer searches for distinguishing features =3(0.1875)+1(0.5)+3(0.125)+2(0.1875)=1.8125 such as edges or textual regions and mentally combines compression ratio is them into recognizable groupings. The brain then correlates these groupings with prior knowledge in order to complete Cr =2/1.8125=1.103 the image interpretation process. Thus eye does not respond with equal sensitivity to all visual information. Certain 4. INTER PIXEL REDUNDANCY: information simply has less relative importance than other information in normal visual processing. This information is In order to reduce inter pixel redundancy, the 2-D pixel said to be psycho visually redundant. Unlike coding and array normally used for human viewing and interpretation inter pixel redundancy psycho visual redundancy is must be transformed into a more efficient format. For associated with real or quantifiable visual information. Its example, the difference between adjacent pixels can be used elimination is desirable because the information itself is not to represent an image. It is called mapping. A simple essential for normal visual processing. Since the elimination mapping procedure is lossless predictive coding , eliminates of psycho visually redundant data results in a loss of the inter pixel redundancies of closely spaced pixels by quantitative information, it is called quantization. extracting and coding only the new information in each pixel. The new information of a pixel is defined as the difference between the actual and predicted value of that pixel. © 2015, IRJET.NET- All Rights Reserved Page 241 International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 02 Issue: 01 | Apr-2015 www.irjet.net p-ISSN: 2395-0072 compressed and the decompressed image is calculated by using the formula e(x,y)=f’(x,y)-f(x,y) so the total error between the two images is M-1 n-1 ∑ ∑ [f’(x,y)-f(x,y)] x=0 Y=0 and the rms(root mean square)error is used to calculate the error energy between the compressed and the original image and f’(x,y) is the square root of the squared error Fig 4:original Fig 5 :16 gray level Fig 6 : 16 gray averaged over the M*N array , or levels/random noise rmse=[1/MN∑M-1∑n-1[f’(x,y)-f(x,y)]2]1/2 ] Consider the image in In fig 4. shows a monochrome image with 256 gray levels. Fig 5 : is the same image after the x=0 Y=0 uniform quantization to four bits or 16 possible levels. Fig 6 is called improved gray-scale quantization. It recognizes the 8. HUFFMAN CODES: eye’s inherent sensitivity to edges and breaks them up by adding to each pixel a pseudorandom number, which is Huffman Codes[5] contain small number of possible generated from the low-order bits of neighboring pixels, symbols.All the source symbols are coded one at a time. before quantizing the result. In fig 6 removes a great deal of psycho visual redundancy with little impact on perceived STEPS : image quality. 1.Symbols are placed on the probability values in a 6. COMPRESSION RATIO: decreasing manner. Compression ratio calculated by the formula 2. Where there is many number of nodes : Cr=n1/n2 * The new node can be form by merging the two smallest nodes. Where n1 is used to represent the total number of bits in an original image and n2 is used to specify the total number of * Values ‘1’ or ‘0’ is assigned to each pair of values. bits in the encoded image. Compression consists of encoding and decoding techniques. Encoding is used to create a 3. From the root we can read the symbols based on their unique symbols which are used to specify the original image. location. The output of encoder is compressed image. The input of Table 2 : Huffman Source Reduction decoder is compressed image and the decoder stage is used to get the original image with out getting any error. Orginal Source Source REduction Cr=bytes(f1)/bytes(f2); Symbol Probability 1 2 Where f1 is total number of bytes in the original image and A2 0.5 0.5 0.5 f2 is the total number of bytes in the encoding image. A4 0.1875 0.3125 0.5 7 . ROOT MEAN SQUARE ERROR : A1 0.1875 0.1875 To analysis a compressed image, it must be fed into a decoder .f’(x,y) is the decompressed image .