High Synthetic Image Coding System

*Abdallah A. Ibrahim and Loay E. George*

#### **Abstract**

Compressing an image and reconstructing it without degrading its original quality is one of the challenges that still exist now a day. A coding system that considers both quality and compression rate is implemented in this work. The implemented system applies a high synthetic entropy coding schema to store the compressed image at the smallest size as possible without affecting its original quality. This coding schema is applied with two transform-based techniques, one with Discrete Cosine Transform and the other with Discrete Wavelet Transform. The implemented system was tested with different standard color images and the obtained results with different evaluation metrics have been shown. A comparison was made with some previous related works to test the effectiveness of the implemented coding schema.

**Keywords:** image coding, image compression, Discrete Cosine Transform (DCT), Discrete Wavelet Transform (DWT), entropy coding, quantization

#### **1. Introduction**

In this work, a synthetic image coding schema will be described in detail. The implemented compression system is consisting of four stages to compress the input color image. First, the color transformation resolved from RGB (Red, Green, and Blue) space to YCbCr (Y<sup>0</sup> is the luma component and CB and CR are the bluedifference and red-difference chroma components, respectively). The second stage applies DCT (Discrete Cosine Transform) or DWT (Discrete Wavelet Transform) to produce the transform coefficients for a better representation of image data. These coefficients are quantized using the scalar quantization technique in the third stage. Finally, synthetic entropy coding schema will be implemented to encode the quantized coefficients to produce a stream of bits for the purpose of storing. The entropy encoder work by implementing the adaptive shift coding technique to specify the optimal number of bits needed to store each value of image pixels. The system will be tested on different color images and the results will be shown in detail with various evaluation metrics.

#### **2. The implemented system schema**

The system will be implemented with two transform techniques, one with DCT and the other with DWT. In the first schema, the input image is split into blocks of size N N (where N is multiple of 2), each block is categorized according to its spatial details whether it is a high-frequency block (its pixels are uncorrelated) or low-frequency block that contains correlated pixels by using DPCM (Differential Pulse Coding Modulation) in three different aspects (horizontally, vertically, and diagonally) then the energy of each block is calculated to determine the correlation level between its nearby pixels by using a specified threshold value. Then, image blocks are scanned and converted into 1D vectors using a horizontal scan order. The next step is to apply the 1D-DCT on each vector to produce the transform coefficients. Then, adaptive scalar quantization is applied for both correlated and uncorrelated blocks. The level of the quantization values for each block is different according to the block feature whether it is high-frequency detailed blocks or low-frequency correlated blocks, by taking advantage of that these high-frequency blocks can be treated separately from low frequency to produce better compression. Finally, the entropy encoder is applied to the quantized coefficients to store each coefficient with an optimal number of bits. The encoding and decoding process of DCT are described in detail in our original work in the following paper [1]. **Figure 1** demonstrates the encoder and decoder units.

In the second schema, the image is transformed using wavelet biorthogonal CDF-9/7 (Cohen-Daubechies-Feauveau) to produce the detailed and approximate coefficients. Then, the size of the transformed coefficient will be reduced using progressive scalar quantization. Finally, entropy coding is applied to store these coefficients. DWT encoder and decoder units are presented in **Figure 2**.

#### **3. RGB color space decomposition**

RGB color space stands for Red, Green, and Blue, RGB is the most popular color space used, it is device-dependent and it is used for a display system. All colors in the RGB color space are formed using only three-color coordinates: Red, Green, and Blue (RGB) to render the color image. Each color within RGB space ranges from (0 to 255) that is R = {0, 1, 2 … 255}, G = {0, 1, 2 … 255} and B = {0, 1, 2 … 255}. Every pixel within a grayscale image is defined to have a depth of 8 bits per pixel. In other words, the picture consists of different gray values ranging from 0 to 255. In the RGB image, each pixel is a combination of three different channels (Red, Green, and Blue), each of which is considered to be an 8-bit gray-scale image. All other color spaces used in various applications can be extracted from RGB color information [2].

In this work, a true-color image is selected for testing. Each pixel existing in a true-color image comprises of 24-bits. These bits are divided into three parts, each part is set of 8 bits for Red, Green, and Blue channels, respectively. And so, 16,777,216 probable colors could exist within such an image. To process these colors, they are decomposed into their original space channels. These channels hold basic color plane components (Red, Green, and Blue), which hold the color information for each pixel in the image. The values for each channel range from 0 to 255 for each color plane.

*High Synthetic Image Coding System DOI: http://dx.doi.org/10.5772/intechopen.109902*

**Figure 1.**

*Block diagram of DCT encoder and decoder [1].*

### **4. RGB to YCbCr conversion**

YCbCr is the most commonly used color space for compression. YCbCr is an ascended and offset version of the YUV color space. Y is brightness (luminance or Luma), that is, the gray scale value. U & V are the chrominance or chroma, used to describe the image color and saturation, and used to specify the pixel color. Cb and Cr

**Figure 2.** *Block diagram of DWT encoder and decoder.*

are the chrominance components, CB is defined as the difference between the blue part of the RGB input signal and the brightness value of the RGB signal, and Cr is the difference between the red part of the RGB input signal and the brightness value of the RGB signal. Since the human visual system (HVS) is more sensitive to changes in luminance than to changes in chrominance, by describing a color in terms of its luminance and chrominance content separately enables more efficient processing and transmission of color signals in many applications, therefore images are compressed more efficiently with this space [3].

The transform from RGB color space to YCbCr space is given by the following equation [4]:

$$\text{Y} = \text{16} + \left(\frac{65.738 \text{ Red}}{256}\right) + \left(\frac{129.057 \text{ Green}}{256}\right) + \left(\frac{25.064 \text{ Blue}}{256}\right) \tag{1}$$

$$\text{Tb} = 128 + \left(\frac{-37.945 \text{ Red}}{256}\right) - \left(\frac{74.494 \text{ Green}}{256}\right) + \left(\frac{112.439 \text{ Blue}}{256}\right) \tag{2}$$

$$\text{Cr} = 128 + \left(\frac{112.439 \text{ Red}}{256}\right) - \left(\frac{94.154 \text{ Green}}{256}\right) - \left(\frac{18.285 \text{ Blue}}{256}\right) \tag{3}$$

where Red, Green, and Blue are the color values of each pixel in the input image multiplied by floating points constants, these constants are scaled by dividing each by 28 = 256.

The inverse transform from YCbCr color space to RGB space is given by the following equations:

$$\text{Red} = \left(\frac{298.082 \text{ Y}}{256}\right) + \left(\frac{408.583 \text{ Cr}}{256}\right) - 222.921\tag{4}$$

*High Synthetic Image Coding System DOI: http://dx.doi.org/10.5772/intechopen.109902*

$$\text{Green} = \left(\frac{298.082 \text{ Y}}{256}\right) - \left(\frac{100.291 \text{ Gb}}{256}\right) - \left(\frac{208.120 \text{ Cr}}{256}\right) + 135.576\tag{5}$$

$$\text{Blue} = \left(\frac{298.082 \text{ Y}}{256}\right) + \left(\frac{516.412 \text{ Cb}}{256}\right) - 276.836\tag{6}$$

#### **5. CDF-9/7 biorthogonal wavelet transform**

To apply the biorthogonal wavelet, transforming the image includes two steps: lifting steps follows by scaling steps. The lifting scheme is implemented through a sequence of phases. It can be identified in three phases: split phase, predict phase, and update phase as shown in **Figure 3**.

In the split phase, the original data is partitioned into two sub-bands: the first subband consists of the elements of odd indices and the second consists of the elements of even indices. The predict phase (P) is utilized to get the coefficients of the highfrequency sub-bands details (these coefficients are called wavelet coefficients), and this phase aims to predict the values of the even indices by values of the odd indices. After the predict phase, the update phase (U) is applied to obtain the coefficients of the low-frequency sub-band by making the average value of the output of low-pass coefficients equal to the average values of the original input data. So, the update phase (U) is used to update the even samples by using the previously calculated detail (wavelet) coefficients [6].

#### **6. Progressive scalar quantization**

A progressive scalar quantization is applied to quantize the produced wavelet detailed and approximate coefficients. Progressive quantization work by applying quantization in a hierarchal form where each pass in the wavelet transform is quantized with different scales, starting with large quantization scales and decreasing drastically as the number of passes increase.

**Figure 3.** *Lifting scheme transform [5].*

The quantization step used to quantize the coefficients of each sub-band calculated, according to the following eq. [7]:

$$Q\_{\omega} = \begin{cases} Q0 \text{ for LL band in the n}^{\text{th}} \text{ Level} \\ Qa^{N\text{R}as-1} \text{ for LH.HL in n}^{\text{th}} \text{ Level} \\ Q\beta a^{N\text{R}as-1} \text{ for HH in n}^{\text{th}} \text{ Level} \end{cases} \tag{7}$$

where NPass is the wavelet level number (i.e., the pass number), α is the descending rate parameter, and *β* is the Beta multiplication (such that Q0 = 2, Q ≥ 1, α ≤ 1, β ≥ 1). The value of the quantization step is decreased using linear, progressive relationship, and its value for HH sub-band is greater than its value for the corresponding HL and LH sub-bands because it is multiplied by β (≥ 1).

#### **7. Synthetic entropy encoder**

Synthetic entropy coding is applied to represent the quantized coefficients as a sequence of 0 and 1, by storing the optimal number of bits needed for each coefficient. The flowchart of the implemented synthetic entropy encoder is shown in **Figure 4**.

Firstly, the input array of coefficients is partitioned as a block of size (N\*N), where N is the size of the block used in DCT divided by 2 or the size of the LL band used in DWT. Then, the block with all zero coefficients will be discarded and the block with nonzero values will be converted into 1-D vector.

The next step is to map each negative value into a positive one to get rid of the negative sign and also avoid the coding complexity when storing these numbers. This is simply done by mapping all negative values to positive odd numbers while the positive values are mapped to be even numbers. The mapped numbers are produced by applying the following equation [7]:

$$\text{Pi} = \begin{cases} \text{ 2 } \text{Pi } \text{if } \text{Pi} \ge \text{0} \\ (/\text{Pi} / \ast \text{2}) - \text{1 } \text{if } \text{Pi} < \text{0} \end{cases} \tag{8}$$

where Pi is the coefficient value in the incoming sequence. The inverse mapping process is implemented using the following equation:

$$\mathbf{P'\dot{i}} = \begin{cases} \begin{array}{c} \text{Pi/2 } \dot{\text{if } Pi \text{ is even number}} \\ (-Pi + \mathbf{1})/2 \text{ } \dot{\text{if } Pi \text{ is odd number}} \end{array} \end{cases} \tag{9}$$

The next step is to decompose each vector by moving each nonzero value (> = 1) into a new vector and replacing its original location with one. Then, the run length encoding process is applied to the original vector [1].

The resultant vectors from the previous stage (Nonzero Vector and Run Vector) are further separated into two sub-vectors, according to the mean value. The first vector will contain the values less than the mean value and the second vector will contain the values that are greater than or equal to the mean value and then subtract the second vector from the mean value to reduce its scaling range.

Finally, the adaptive shift coding technique is applied to assign the optimal number of bits required to store each coefficient [1].

**Figure 4.** *The implemented synthetic entropy encoder flowchart.*

#### **8. Evaluation metrics**

A set of evaluation metrics have been taken to investigate the performance of the compression method applied.

Compression ratio (CR) is defined as the ratio of the size between the original image and the compressed image size. They can be measured in (bits, bytes, kilobytes, etc.). The higher CR is the better compression technique used to compress the image [8].

$$\text{CR} = \frac{\text{Original file Size}}{\text{Compressed}} \tag{10}$$

Mean Square Error (MSE) is computed by averaging the cumulative squared intensity error differences between the original image and the reconstructed image. MSE value closest to zero is better, and the reconstructed image quality is poor when MSE is large, thus MSE must be as low as possible for effective compression. MSE is calculated through the following equation [9]:

$$\text{MSE} = \frac{1}{\text{m}} \sum\_{i=0}^{\text{m}-1} \sum\_{j=0}^{\text{n}-1} \left[ \mathbf{X}(\text{i.j}) - \mathbf{Y}(\text{i.j}) \right]^2 \tag{11}$$

where X is the original image pixel and Y is the compressed image. The dimension of the images is m � n.

Peak-Signal-to-Noise Ratio (PSNR) is the ratio between maximum signal power, which is considered as the original image and the power of distorting noise obtained from MSE. The higher the PSNR, the better the quality of the reconstructed image. Typical values for lossy compression of an image are between 28 dB and 40 dB. The PSNR can be given by the following equation [10]:

$$\text{PSNR} = 10 \, \log\_{10} \left( \frac{\text{MAX}\_{\text{x}}^{2}}{\text{MSE}} \right) \tag{12}$$

where MAX<sup>2</sup> is the power of maximum intensity value in the original image X.

Bit Per Pixel (BPP) is defined as a number of bits required to store each pixel in an image. Pixels must be coded efficiently to reduce redundancy, hence reducing storage requirements. BPP is calculated using the following equation [11]:

$$\text{BPP} = \frac{\text{B}}{\text{MxN}} \tag{13}$$

$$\text{for BPP} = \frac{\text{24bits}}{\text{CR}} \tag{14}$$

where B is a number of bits after compression and M � N is the total number of pixels in an image.

Compression gain (CG) is defined as the amount of compression gained after the image is compressed. The CG of a digital image is calculated by the following equations:

$$\text{CG} = \frac{\text{original size} - \text{compressed size}}{\text{original size}} \ge 100\% \tag{15}$$

$$\text{For} \qquad \text{CG} = 1 - \frac{1}{\text{CR}} \ge 100\% \tag{16}$$

Structural similarity index measure (SSIM) aims to measure quality by capturing the similarity of images. Three aspects of similarity: luminance, contrast, and structure are determined and their product is measured [9].

#### **9. Experimental results**

This section is intended to examine the results of the proposed system in detail for both DCT and DWT modules. The detailed results of many experiment tests are presented and discussed to evaluate the performance behavior of the established system. The adopted system and all additional programs for the testing purpose have been established using visual studio (C sharp programming language).

A set of standard true-color images has been utilized to test and evaluate the system's performance. These images are of type "Bitmap" format in which each pixel is stored in 24-bit true color. The image files "Lena.bmp," "Barbara.bmp," "Peppers. bmp," (smoothed images), and "Baboon.bmp" (sharp edge image). All test images are of size 256 � 256 for width and height. **Figure 5** presents these images.

A set of results tables is presented for evaluation. Each test image is evaluated using two modules. One shows the results of compression when the DCT technique is applied and the second module shows the results of compression when the DWT technique is applied. Each table shows the effectiveness of each control parameter used in the system on the resulting compressed image. The test results are evaluated and compared based on fidelity criteria measurements (i.e., MSE, PSNR, SSIM, CR, CG, and BPP). The real time of encoding and decoding process is also presented.

The effect of the following control parameters has been investigated to test the results of the proposed system using the DCT technique:

BS: is the block size used in DCT.

Thr: is the threshold value used to determine the importance of each block. Q0, Q1, and α: are the quantization control parameters used to calculate the quantization step value.

The effects of each parameter are explored by varying the value of each parameter from minimum value to maximum. **Table 1** represents the assumed default range of the considered control parameters used with the DCT module.

**Figure 5.** *Test color images.*


#### **Table 1.**

*The range of the control parameters for the system when using DCT.*

The parameters used to control the level of compression by using the DWT technique are instigated as the following:

N.Pass: the number of passes used in the wavelet transform.

Q0: used to quantize the approximation LL band.

Q1: used to quantize the details sub-bands (LH, HL, and HH).

α: the descending rate parameter used to decrease the quantization of details bands as the number of passes increase.

β: Beta multiplication parameter used to scale the quantization of HH sub-band.

The range of these parameters after making a comprehensive set of tests is shown in **Table 2**.

A set of results tables in our previous work [1] presents the system performance when applying the DCT module in terms of MSE, PSNR, SSIM, CR, CG, and BPP for Lena, Barbara, Peppers, and Baboon images, respectively. It shows that the fidelity level in terms of PSNR and SSIM increased while the CR and CG decreased.

In the same manner, the system performance was evaluated when applying DWT module on the same color images with the effects of control parameters shown in **Table 2**, **Tables 3**–**6** present these results.


**Table 2.**

*The default range of the control parameters for the system when using DWT.*


#### *High Synthetic Image Coding System DOI: http://dx.doi.org/10.5772/intechopen.109902*


**Table 3.** *Test results after applying compression with DWT module on color "Lena" test image.*


**Table 4.**

*Test results after applying compression with DWT module on color "Barbara" test image.*



**Table 5.** *Test results after applying compression with DWT module on color "Peppers" test image.*


#### **Table 6.**

*Test results after applying compression with DWT module on color "Baboon" test image.*

**Figures 6**–**9** show the tradeoff between CR and PSNR when applying compression on the test images (Lena, Barbara, Peppers, and Baboon), respectively.

A set of reconstructed color images is shown in **Figure 10** with different fidelity levels, where PSNR, SSIM, CR, and BPP values are varied**.**

*A tradeoff between CR and PSNR for color Lena image test results.*

**Figure 7.** *A tradeoff between CR and PSNR for color Barbara image test results.*

**Figure 8.** *A tradeoff between CR and PSNR for color Peppers image test results.*

#### **Figure 9.**

*A tradeoff between CR and PSNR for color Baboon image test results.*

**Figure 10.**

*Samples of the reconstructed color images where the PSNR, SSIM, CR, and BPP values are varied.*

#### **10. Comparisons with previous works**

In this section, the results of the implemented system have been compared with some previously published methods and also with the standard JPEG system.

**Table 7** lists the compression results attained by the proposed system with those given in previous studies in terms of (CR, BPP, PSNR, and SSIM), taking into consideration that in these studies same images have been used. The listed results demonstrate that the proposed system outperforms other methods.

#### **11. Conclusions**

In this chapter, a high entropy image coding system was implemented, and the system shows remarkable results compared to the existing approaches. A high compression ratio was obtained while maintaining image quality without distortion. The proposed entropy encoder has a positive significant impact on the results. It is important that the transformed image coefficients must be processed in a way to be suitable for the coding process in order to store it with a minimum number of bits.


#### **Table 7.**

*Comparison between the implemented system results and some related works used to encode different standard images.*

From the obtained test results, the proposed system shows outperformed results when dealing with smooth images like (Lena, Barbara, and Peppers) compared to the existing approaches, but it has a major drawback in a sharp image like Baboon.

As a summary, the best-attained compression gains for the test images (Lena, Barbara, Peppers, and Baboon) are 98.16%, 98.09%, 96.28%, and 91.10%, respectively, where PSNR values are in an intermediate range.

## **Author details**

Abdallah A. Ibrahim<sup>1</sup> \* and Loay E. George<sup>2</sup>

1 University of Baghdad, Baghdad, Iraq

2 University of Information Technology and Communications, Baghdad, Iraq

\*Address all correspondence to: abdullah.i@sc.uobaghdad.edu.iq

© 2023 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

#### **References**

[1] Ibrahim AA, George LE, Hassan EK. Color image compression system by using block categorization based on spatial details and DCT followed by improved entropy encoder. Iraqi Journal of Science. 2020;**61**(11):3127-3140

[2] Pm N, Chezian R. Various color spaces and color space conversion algorithms. Journal of Global Research in Computer Science. 2013;**2013**:44-48

[3] Szedo G. Color-Space Converter: RGB to YCrCb2007. pp. 1-16. Available from: https://www.researchgate.net/publica tion/277048646\_R\_Color-Space\_Conve rter\_RGB\_to\_YCrCb

[4] ITU-R. Studio Encoding Parameters of Digital Television for Standard 4:3 and Wide-screen 16:9 Aspect Ratios. International Telecommunication Union; 2011. Available from: https:// www.itu.int/rec/R-REC-BT.601/

[5] Shirvaikar M, Bushnaq T. VHDL implementation of wavelet packet transforms using SIMULINK tools. Real-Time Image Processing. 2008;**2008**:6811

[6] Lian C-J, Chen K-F, Chen H-H, Chen L-G. Lifting based discrete wavelet transform architecture for JPEG2000. In: The 2001 IEEE International Symposium on Circuits and Systems (Cat. No.01CH37196). 2001. pp. 445-448. Available from: https://www.semantic scholar.org/paper/Lifting-based-discre te-wavelet-transform-for-Lian-Chen/cc 46ac3f1f89ec38b8b641dd43d8254b8c 8637bb

[7] Ahmed SD, George LE, Dhannoon BN. The use of cubic bezier interpolation, biorthogonal wavelet and quadtree coding to compress color images. British Journal of Applied Science & Technology. 2015;**11**(4):1-11

[8] Anandan P, Sabeenian RS. Medical image compression using wrapping based fast discrete curvelet transform and arithmetic coding. Circuits and Systems. 2016;**2016**:2059-2069

[9] Varnan C, Jagan A, Kaur J, Jyoti D, Rao DS. Image quality assessment techniques pn spatial domain. International Journal of Computer Science and Technology. 2011;**2**(3): 177-184

[10] Silpa K, Mastani S. Comparison of image quality metrics. International Journal of Engineering Research & Technology (IJERT). 2012;**1**(4):1-5

[11] Nigam AK, Khare P, Srivastava VK. Image compression using hybrid approach and adaptive scanning for color images. Advances in VLSI, Communication, and Signal Processing. 2020;**587**:761-774

[12] Kalavathi P, Boopathiraja S. A wavelet based image compression with RLC encoder. In: Computational Methods, Communication Techniques and Informatics. pp. 289-292. Available from: https://www.researchgate.net/prof ile/Kalaiselvi-Thiruvenkadam/publica tion/319077453\_Computation\_Methods\_ Communication\_Techniques\_and\_Inf ormatics/links/5993f440aca272ec9087ac 00/Computation-Methods-Communica tion-Techniques-and-Informatics.pdf #page=307

[13] Hashim AT, Ali SA. Color image compression using DPCM with DCT, DWT and quadtree coding scheme. Engineering and Technology Journal. 2020;**34**:585-597

[14] Messaoudi A, Benchabane F, Srairi K. DCT-based Color Image Compression Algorithm using Adaptive Block Scanning, Signal, Image and Video Processing. Springer; 2019. Available from: https://link.springer.com/article/ 10.1007/s11760-019-01492-7

[15] Zhou Y, Wang C, Zhou X. DCTbased color image compression algorithm using an efficient lossless encoder. Image and Video Processing. 2018;**2018**:450-454

[16] Boucetta A, Melkemi KE. DWT Based-Approach for Color Image Compression Using Genetic Algorithm. 2012. pp. 476-484. Available from: https://books.google.iq/books?hl=en& lr=&id=mwC7BQAAQBAJ&oi=fnd& pg=PA476&dq=DWT+Based-Approach +for+Color+Image+Compression+Using +Genetic+Algorithm&ots=n5iiuuQd9-& sig=ToXcTrsRUaTtnSwckkq7to2XVZY &redir\_esc=y#v=onepage&q=DWT% 20Based-Approach%20for%20Color% 20Image%20Compression%20Using% 20Genetic%20Algorithm&f=false

#### **Chapter 3**
