International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016
ISSN 2278-6856
IMAGE COMPRESSION USING GENETIC PROGRAMMING Dr. Ahmed M. Ebid Lecturer, Faculty of Engineering & Technology, Future University, Cairo, Egypt
Abstract The fast growth in digital image applications such as web sites, multimedia and even personal image archives encouraged researchers to develop advanced techniques to compress images. Many compression techniques where introduced whether reversible or not. Most of those techniques were based on statistical analysis of repetition or mathematical transforming to reduce the size of the image. This research is concerning in applying Genetic programing (GP) technique in image compression. In order to achieve that goal, a parametric study was carried out to determine the optimum combination of (GP) parameters to achieve maximum quality and compression ratio. For simplicity the study considered 256 level gray scale image. A special C++ software was developed to carry out all calculations, the compressed images was rendered using Microsoft Excel. Study results was compared with JPEG results as one of the most popular lossy compression techniques. It is concluded that using optimum (GP) parameters leads to acceptable quality (objectively and subjectively) corresponding to compression ratio ranged between 2.5 and 4.5.
acceptably looks like the original (accepted accuracy depends on the purpose). JPEG and JPEG2000 are the most famous lossy image formats. Compression efficiency could be presented by compression ratio CR (which is the ratio between uncompressed and compressed image), while measuring compression quality is a little bit complicated. Compression quality could be evaluated objectively using Mean Square Error (MSE) and the Peak Signal to Noise Ratio (PSNR) as follows:
Keywords: Image compression, Genetic Programing, GP.
1. INTRODUCTION 1.1 Image Compression The rapid increasing in using photos and images in web, social media, commercial applications, personal archives,..etc encourages the developers to figure out new techniques in order to reduce image size without significant reduction in its quality, hence, image compression becomes one of the main topics in digital data processing researches. Image compression techniques could be divided into two main types, Reversible (Lossless) and Irreversible (Lossy). Reversible techniques ,such as variable length, Bit-plan and Huffman coding are based on eliminating redundant information and keep only the necessary information. The reconstructed image is exactly looks like the original (error free reconstruction). GIF, PNG, and TIFF are the most famous lossless image formats. Irreversible techniques, such as Karhunen-Loeve Transform (KLT), Discrete Cosine Transform (DCT) and Discrete Wavelet Transform(DWT) are based on approximating the image using mathematical transformation technique. The reconstructed image is
Volume 5, Issue 5, September – October 2016
Where f(x,y) is the pixel value of the original image, and f’(x,y)is the pixel value of the compressed image, (L) is the dynamic range of allowable pixel intensities, (L = 2 (No. of bits/pixel) -1). Also, compression quality could be evaluated subjectively by human observer judgment (Very Poor, Poor, Good, Very Good or Excellent) or using structural similarity index (SSIM) as follows:
Where l(x,y), c(x,y) and s(x,y) present luminance, contrast and structure components. Relativity importance factors (α, β, γ) are usually equal to (1.0). (SSIM) for two images (x,y) could be presented in terms of their means (μx), (μy) and standard deviations (x), (y) as follows:
Page 7
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016 Where C1, C2 are small constants used to avoid mathematical instability when (μx2+ μy2) or (x2+ y2) are almost zero. In order to achieve maximum compression ratio, successive compression techniques may be used, for example JPEG format uses Huffman coding (lossless) after applying DCT (loosy). 1.2 Genetic Programming Genetic Programming (GP) (also kwon as Gene expression programming (GEP)) is one of the most recent developed knowledge-based techniques and it is the next development to the Genetic Algorithm (GA). (GP) could be classified as multivariable regression technique . The basic concept of (GP) is to find the best fitting formula for a certain given points using (GA) technique. (Koza, 1996). Traditional (GA) based on generating random set of solutions for the considered problem called (population), testing the success (fitness) of each solution in the population, keeping the most fitting solutions (survivors) and delete the rest of population , re-generating new population by mixing parts of survivors (crossover) and/or randomly change some parts of the generated new solutions (mutation), repeating previous steps till achieving acceptable fitting error. For (GP), the population is a set of randomly generated mathematical formulas. Usually, mathematical formula could be presented in many ways, but in order to facilitate applying genetic operations such as crossover and mutation, mathematical formula must be presented in unified form consists of a series of parameters with certain length, this form called genetic form (or chromosome). Binary tree form is used to convert any mathematical formula into standard fixed format which can easily presents in genetic form. Generally, any mathematical or logical operator could be used in (GP), the only restrain is that the operator should have two or less inputs and only one output, the basic five mathematical operators are (=,+,-,x,/) as shown in figure (1). Figure (2) shows an example for a formula presented in mathematical format, binary tree format and genetic format and it could be noted that: Any formula in binary form could be divided into levels, the more the level the more the formula complexity. Genetic form (chromosome) is divided into two parts, the upper part for operators and the lower part for variables Length of operators part is (2 No. of levels -1), length of
Volume 5, Issue 5, September – October 2016
ISSN 2278-6856
variables part is (2 No. of levels) and total length of chromosome is (2 No. of levels+1 -1). Two-points crossover technique was suggested by Riccardo (1996), where the re- generated member is produced by mixing operators parts and variable parts of two randomly selected survivors. The author developed another crossover technique in (2004) called Random crossover, where the re- generated member is produced gene by gene by random selection from many survivors (typically all survivors). figure (3) shows both techniques.
Figure 1: The five basic mathematical operators in (GP)
Figure 2: Mathematical and genetic representation of binary tree
(a) (b) Figure 3: (a) Two-point crossover, (b) Random crossover
Page 8
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016 2. RESEARCH PLAN Research plan aims to determine the optimum combination of (GP) parameters to achieve maximum quality and compression ratio. Since GP is used to find best fitting formula, hence, there will always be some error in the results and so image compression using GP is irreversible (Loosy). Success in compression were measured using (MSE) and (PSNR) for objective image quality, (SSIM) for subjective image quality and (CR) for compression efficiency. A parametric study was carried out to evaluate the effect of several parameters on compressed image quality and compression ratio, the considered parameters are sampling size, number of levels, population size, number of generations. A special C++ software were developed to carry out all compression and decompression calculations, while the rendering of both original and reconstructed images were carried out using built in cell color function in Microsoft Excel. (MSE), (PSNR) and (SSIM) were calculated using software written by Ming-Jun Chen,2010 In order to maximize the compression ratio, compressed image by (GP) were recompressed using WinZip. A well-known gray scale photo “lena.tif” is used as the subject of the parametric study, it is 256x256 pixel with 256 level of gray scale, study results were verified using “Cameraman.tif”. Both “lena.tif” and “Cameraman.tif” was compressed using JPEG technique by commercial software “Snagit Editor” with two different quality degrees (80% & 90%) to be compared with study results.
ISSN 2278-6856
applying GP technique on each zone, collecting the results in output file and compressing it using WinZip to produce the compressed image. In order to apply GP on certain zone, the software generates set of records to present the data of this zone in usable form, each record contains X, Y coordinates of each pixel (referring to zone edge) and level of gray of that pixel. After generating the population, the software checks the singularities of each formula to avoid any mathematical, overflow or underflow errors during calculations, the defected formulas are replaced by new randomly generated ones. Then, the software picks the survivors based on their sum of squared error (SSE) and regenerates the population using random crossover and starts the next generation. Figure (4) shows the flowchart of the compression software. Output file contains the best fitting formula for each zone in genetic form, hence, its size should be (chromosome size x number of zones). Because operator gene can be (+, -, x, or /) and variable gene can be just (x or y) , both types of genes is stored in 2 bits, so chromosome size equals to quarter chromosome length (2 No. of levels ) in bytes. It means that the size of output file (before applying WinZip) depends only on number levels and zones regardless the content of the image. Decompression software reads the compressed image, unzip it, regenerates each zone by substituting in corresponding formula and finally puts all pieces together to form the reconstructed image. Figure (5) shows the flowchart of the decompression software.
3. METHODOLOGY 3.1 Parametric study Because GP is a resource consuming technique, it is important to figure out the optimum GP parameters that produces best image quality, maximum compression ratio with minimum resources. In order to achieve that goal, a parametric study was designed to test the effect of changing each parameter on the quality and size of compressed image. The considered parameters in the study and their values are as follows: Sample size (2x2, 4x4, 8x8) pixels Number of chromosome levels (2, 3, 4) levels Population size (50, 100, 300) Number of generations (25, 50, 100) 3.2 Compression & decompression software Author had developed a general purpose GP software back in 2004 using C++, this software is used as core for the compression software, it starts with reading the original image, dividing it into zones according to sample size,
Volume 5, Issue 5, September – October 2016
Figure (4): Flowchart of compression software Page 9
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016
ISSN 2278-6856
stage trials for visual quality judgment. From table (1) it could be noted that (SSIM) increases with decreasing sample size.
Figure (5): Flowchart of decompression software 3.3 Image rendering Both original and reconstructed images are graphically presented using cell color conditional formatting of Microsoft Excel.
(a)
4. RESULTS & COMMENTS Results of the parametric study are summarized in table (1), the tables shows GP parameters of each trial and the corresponding (MSE), (PSNR), (SSIM), compressed file size (before and after WinZip) and the compression ratio. It should be noted that number of survivors is kept in optimum range (25-35% of population size) in all trials to speed up the iteration and prevent sticking in local minimum. The study was divided into two stages as follows: First stage: Nine trials (from 1 to 9 ) was dedicated to study the effect of sampling size and number of levels on the quality and size of compressed image, figure (6-a) present the relation between sample size and (MSE), while figure (6-b) present the relation between sample size and compression ratio for different number of levels. Figure (6-a) shows that (MSE) value decreases almost linearly with decreasing the sample size regardless the number of levels. While figure (6-b) shows that (CR) value decreases with decreasing the sample size regardless the number of levels. Also, (CR) value decreases faster for simple formulas than complicated ones. (CR) value of trial no. (7) is less than 1.00, which means it is inefficient combination because the size of compressed image is larger than the original one. Figure (8) shows the reconstructed images of the first
Volume 5, Issue 5, September – October 2016
(b) Figure (6): Effect of Sample size & No. of levels on (MSE) and (CR). Second stage: This stage aims to study the effect of population size and number of generations on the quality of compressed image. Based on both quality and compression ratio results, trials (1) and (5) were selected to be considered in the second stage. Although trial (8) has the same quality and compression ratio of trial (1), but it was neglected because it uses more complex formulas (4 levels) and consumes much more time. This stage consists of twelve trials (form 10 to 21). Trials from (10) to (18) were dedicated to expand the study of trial (1), while trials from (19) to (21) concerning in expanding the study of trial (5). Figure (7-a) shows the relation between number of generation and (MSE) for different population size, it Page 10
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016 indicates that regardless population size, increasing number of generations enhance (MSE) value, but enhancement rate decreases when number of generations exceeded 50, while figure (7-b) shows the relation between population size and (MSE) for different sample sizes, it could be noted that the (MSE) value decreases with increasing population size and the rate of decreasing in case of small sample size is faster than in case of large one.
ISSN 2278-6856
Based on the previous results, it is recommended to use population size not less than 1000 and number of generations up to 50 generations. Verification: “Cameraman.tif” were used to verify the results of the study, it was compressed using parameters combinations of trials (17), (21) and (8) besides the JPEG trials as shows in table (2). The verification shows good matching with study results. Figure (10) presents the reconstructed images of the three verification trials.
5. CONCLUSIONS
(a)
Results of this research could be concluded as follows: Using (GP) technique in image compression shows acceptable quality (SSIM and MSE) for compression ratio ranged between 2.5 to 4.5 Two (GP) parameters combinations showed both accepted quality and compression ratio, those combinations are: Sample size 2 x 2 pixels with 2 levels formula and compression ratio of 2.5 Sample size 4 x 4 pixels with 3 levels formula and compression ratio of 4.5 For same compression ratio, the quality of (GP) compressed images are so close to the JPEG ones. It is recommended to use population size not less than 1000 and number of generations up to 50 generations. Using Winzip as lossless compression tool after (GP) compression enhance the compression ratio by about 20%. Results of this study are valid for gray scale image and need to be verified for colored ones. (GP) is a very time and resources consuming technique, it is recommended to use parallel processing in farther studies. ACKNOWLEDGEMENT The author is very grateful to his colleague Dr. Omar M. Fahmy, for his kind revision and useful comments.
(b) Figure (7): Effect of No. of generations & Population size on (MSE) Figure (9) shows the reconstructed images of the second stage trials of the study. Table (1) shows that number of generations has very minor effect on (SSIM) values. Comparing (GP) study results with equivalent JPEG ones (trial 17 with trial 23 & trial 21 with trial 22) shows that for same compression ratio, the (SSIM) values are so close.
Volume 5, Issue 5, September – October 2016
Page 11
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016
ISSN 2278-6856
Table (1): Summary for parametric study results
Trial Sample No. of Pop. No. of No. of No. Size Levels Size Survivors Gen. Effect of Sample size & No. of levels 1 2x 2 2 1000 300 100 2 4x 4 2 1000 300 100 3 8x 8 2 1000 300 100 4 2x 2 3 1000 300 100 5 4x 4 3 1000 300 100 6 8x 8 3 1000 300 100 7 2x 2 4 1000 300 100 8 4x 4 4 1000 300 100 9 8x 8 4 1000 300 100 Effect of Population size & No. of Generations 10 2x 2 2 100 30 25 11 2x 2 2 100 30 50 12 2x 2 2 100 30 100 13 2x 2 2 500 150 25 14 2x 2 2 500 150 50 15 2x 2 2 500 150 100 16 2x 2 2 1000 300 25 17 2x 2 2 1000 300 50 18 2x 2 2 1000 300 100 19 4x 4 3 100 30 50 20 4x 4 3 500 150 50 21 4x 4 3 1000 300 50 JPEG technique ------------- 80% quality -----------22 -------------90% quality -----------23
MSE
PSNR
SSIM
Comp. Size (KB) GP GP+WinZip
59 175 365 17 105 240 9 82 202
30.4 25.7 22.5 35.8 27.9 24.3 38.6 29.0 25.1
0.970 0.926 0.830 0.983 0.958 0.884 0.987 0.967 0.906
32.0 8.0 2.0 64.0 16.0 4.0 128.0 32.0 8.0
25.9 6.6 1.7 50.6 13.1 3.4 102.4 25.7 6.6
2.5 9.7 37.6 1.3 4.9 18.8 0.6 2.5 9.7
95 86 81 74 67 63 63 60 59 136 119 110
28.4 28.8 29.0 29.4 29.9 30.1 30.1 30.3 30.4 26.8 27.4 27.7
0.955 0.958 0.960 0.965 0.966 0.968 0.968 0.970 0.970 0.950 0.957 0.960
32.5 32.5 32.5 32.5 32.5 32.5 32.5 32.5 32.5 16.0 16.0 16.0
25.7 25.8 25.8 25.8 25.9 25.9 25.9 25.9 25.9 12.9 13.1 13.1
2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 5.0 4.9 4.9
29 11
33.5 37.7
0.98 0.99
-
14.0 22.0
4.6 2.9
CR
Table (2): Summary for verification results
Trial Sample No. of
Pop.
No.
Size Survivors Gen.
Size
Levels
No. of
No. of
1 2x 2 2 1000 300 50 2 4x 4 3 1000 300 50 3 4x 4 4 1000 300 50 JPEG technique ------------- 80% quality -----------4 -------------90% quality -----------5
Volume 5, Issue 5, September – October 2016
Comp. Size (KB) MSE
PSNR
SSIM
GP
GP+WinZip
CR
72 178 161
29.6 25.6 26.1
0.965 0.930 0.960
32.5 16.0 32.0
25.9 13.1 25.7
2.5 4.9 2.5
20 7
35.1 39.7
0.98 0.99
-
13.0 20.0
4.9 3.2
Page 12
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016
ISSN 2278-6856
Figure (8): Effect of Sample size & No. of levels on visual quality
Volume 5, Issue 5, September – October 2016
Page 13
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016
ISSN 2278-6856
Figure (9): Effect of population size on visual quality
Figure (10): Verifying study results using “cameraman” image
Volume 5, Issue 5, September – October 2016
Page 14
International Journal of Emerging Trends & Technology in Computer Science (IJETTCS) Web Site: www.ijettcs.org Email:
[email protected] Volume 5, Issue 5, September - October 2016
ISSN 2278-6856
References [1] Ahmed M. Ebid, “Applications of genetic programming in geotechnical engineering”, 2004, Ph.D. thesis, Ain Shams University, Cairo, Egypt. [2] Rafael C. Gonzalez, and Richard E. Woods, ”Digital Image Processing” (2nd Edition), Prentice Hall, 2002, ISBN: 0201180758. [3] John R. Koza, “Genetic Programming On the Programming of Computers by Means of Natural Selection”, Sixth printing, 1998 © 1992 Massachusetts Institute of Technology [4] Pengwei Hao, “C++ for Image Processing”, Lecture notes, Department of Computer Science Queen Mary, University of London [5] James Rosenthal, “JPEG Image Compression Using an FPGA”,2006, M.Sc. Thesis, University of California, USA. [6] Wei-Yi Wei, “An Introduction to Image Compression”, National Taiwan University, Taipei, Taiwan, ROC [7] Ja-Ling Wu, “Information Theory – part II: Image Data Compression”, Lecture notes, Department of Computer Science and Information Engineering National Taiwan University [8] Ming-Jun Chen and Alan C. Bovik, “Fast structural similarity index algorithm”, Journal of Real-Time Image Processing, pp. 1-7. August, 2010 [9] M. Kudelka Jr., “Image Quality Assessment”, WDS'12 Proceedings of Contributed Papers, Part I, 94–99, 2012. [10] M.R Bonyadi, E.Dehghani, and Mohsen Ebrahimi Moghaddam, “A Non-uniform Image Compression Using Genetic Algorithm”, 15th International Conference on Systems, Signals and Image Processing, IWSSIP 2008, Bratislava, Slovak Republic.
Volume 5, Issue 5, September – October 2016
Page 15