An Empirical Analysis of Requantization
Errors for Recompressed JPEG Images
B.VINOTH KUMAR
Assistant Professor, Department of CSE, PSG College of Technology Coimbatore, Tamilnadu, India
Dr.G.R.KARPAGAM
Professor, Department of CSE, PSG College of Technology Coimbatore, Tamilnadu, India
Abstract:
Images from sources like digital camera, internet and the like are in the JPEG format. There is a tremendous need for recompression of JPEG images in order to satisfy the space constraints and to transmit the images with limited bandwidth. Several techniques have been developed for recompressing the JPEG image in order to achieve low bit rate and to have good visual quality. In this paper, we concentrated on requantization method to achieve recompression. We have analyzed the occurrence of requantization errors empirically for Normal rounding technique. Based on our experience, we have proposed the Enhanced rounding technique for requantization of JPEG images. The resulting images are generally smaller in size and have improved perceptual image quality over Normal rounding technique. We have compared the recompression results for standard benchmark 256x256 gray scale images against image quality measures such as image size, compression ratio, bits per pixel and Peak Signal to Noise Ratio (PSNR).
Keywords: JPEG; Image Compression; Quantization; Recompression; Requantization Error; Rounding Technique.
1. Introduction
Photos from digital camera are mostly compressed in JPEG format and these compressed images play a vital role on the internet and in day-to-day life. About 80% of images appearing on the World Wide Web are stored using the JPEG standard. This standard has been extremely successful in maintaining a balance between low file size and high visual fidelity. For applications such as transmission of image data over mobile networks, uploading and downloading of images in social network and storing more images in limited disk space, there is a need to reduce the bits per pixel and /or file size of the JPEG images. As the original uncompressed image is not available, it may no longer exist or it may be too difficult to retrieve in real time, which leads to the recompression of compressed image.
The general approaches for recompression are Post- processing [7, 9, 11, 13]; to improve perceptual image quality, Pre- Processing [1, 5, 12]; to optimize image fidelity and Requantization; to optimally balance image quality and bit rate. Among above methods, requantization method will be a best choice to reduce the bits per pixel and to maintain image quality. In this paper, the challenges in requantization process are studied and also an enhanced rounding technique for requantization is proposed.
This paper is organized as follows. The fundamental JPEG compression steps are given in section 2. In section 3, the occurrence of requantization errors are studied. Related work to requantization is given in section 4. Enhanced rounding technique is proposed in section 5. Experimental results and comparative study are presented in section 6.
2. Jpeg Image Compression Steps
scale factor, degree of compression is determined. Increasing the quantization scale factor leads to rude quantization, this gives high compression ratio and low image quality and vice versa.
3. Requantization
Though JPEG has different steps, compression is mainly done through quantization. The information lost through quantization cannot be retrieved. For quantization, the quantization (or Quality factor) matrix recommended by Independent JPEG Group (IJG) [6] and quality factor ranges from Q1 (poor) to Q100 (excellent) is used. In the existing literature, Blind Requantization can be achieved by dequantizing the JPEG image and then quantizing it again with a larger step size.
Fig.1 Y75_50 (Blind Requantization) Fig.2 Y75_48 (Blind Requantization)
Requantizing an already quantized image leads to unwanted artifacts and unpredictable behavior. Unpredictable behavior is that better quality factor produces poorer quality images in recompression. For example, an uncompressed image X [17] is compressed with a quality level Q75 (a common quality setting). Then it is recompressed to quality level Q50 and Q48. The resulting images denoted as Y75_50 (Fig.1) and Y75_48 (Fig.2) respectively. Comparing these images, Y75_50 is grainer than Y75_48 which is quite contrary. The same can be visualized through fig. 3(d).
3.1.Direct Vs. Two step Quantization
To study about the challenges in requantization process, the following experiment is carried out. Let Q0 & Q1 are the quantization matrices, having smaller and larger step size respectively and x be in N*. Direct quantization performs the quantization operation on image directly by Q1 whereas two step quantization performs the quantization operation initially by Q0 and then by Q1.
Direct dequantization is one, performing on image which is quantized once, and is given by
x→q1.round(x/q1) …………. (1)
Two-step dequantization is one, performing on image which is quantized twice and is given by
x→q1.round (q0.round(x/q0)/q1) …… (2)
where q0 and q1 are the entries of Q0 & Q1 respectively.
40 42 44 46 48 50 52 54 56 58 60 7000
7500 8000 8500 9000 9500 10000 10500 11000 11500
Quality factor
Siz
e
LENA
YQ1 Y75Q1
Fig.3 (a) One step vs. Two step dequantization: Size vs. Quality factor
40 42 44 46 48 50 52 54 56 58 60
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
Quality factor
B
its p
e
r p
ix
e
l
LENA
YQ1 Y75Q1
40 42 44 46 48 50 52 54 56 58 60
5.5 6 6.5 7 7.5 8 8.5 9 9.5
Quality factor
C
o
m
p
re
ssi
o
n
r
a
ti
o
LENA
YQ1 Y75Q1
Fig.3 (b) One step vs. Two step dequantization: Compression ratio vs. Quality factor
40 42 44 46 48 50 52 54 56 58 60
30.5 31 31.5 32 32.5 33 33.5 34
Quality factor
PSN
R
LENA
YQ1 Y75Q1
Fig.3 (c) One step vs. Two step dequantization: Fig.3 (d) One step vs. Two step dequantization:
Bits per pixel vs. Quality factor PSNR vs. Quality factor
3.2.Requantization Error
Requantization error is one which occurs during requantization and it classifies in to two types. One type of error is Positive Requantization Error (PRE) [3, 14] that occurs when the requantized coefficient is larger in terms of magnitude than it would have been if directly quantized to quality Q1. Another type of error is Negative Requantization Error (NRE) [3, 14] that occurs when the requantized coefficient is smaller in terms of magnitude than it would have been if directly quantized to quality Q1.
From the figure 3 (a) and (d), it is clear that recompressed image has low PSNR even though file size is high. File size varies directly (inversely) with the percentage of positive (negative) requantization errors. This is due to PRE having occurred in coefficients which should have been zero, and NRE have forced the requantized coefficients to zero. During requantization, the percentage of NRE is high for the quality scale from 40 to 49 and percentage of PRE is high for the quality scale from 50 to 60. The occurrence of PRE will deteriorate the efficiency of the run length coding while the occurrence of NRE will improve it, thus leading to the corresponding variations in recompressed image file size shown in figure 3 (a). Due to change in Image file size, the corresponding changes are also occurred in Bits per Pixel and Compression ratio.
3.2.1 Occurrence of PRE & NRE
The Requantization errors have strong relationship with Quantization Step Ratio (QSR), defined as the ratio q1/q0. These errors will be high when QSR is equal or nearer to even numbers especially 2, and it will be low while QSR is equal or nearer to odd numbers.
Performing element-wise division of the second quantization matrix (Q50 and Q48) by first quantization matrix (Q75), it turns out that all entries of Q50./Q75 and of Q48./Q75 are very close to 2. Here 2+ or 2- stands for real number that is greater than or lesser than 2 respectively. Q50./Q75 has more number of 2- which leads to large number of PREs and also resulting image has poor PSNR whereas Q48./Q75 has more number of 2+ which leads to large number of NREs and resulting image has better PSNR than Q50./Q75. The numerical comparison given in Table 1 & 2 justifies the above statement.
Q50./Q75
=
Q48./Q75=
From the experiment carried out in section 3.1, the numbers of PREs and NREs in recompressed image are calculated and the results are tabulated with respect to QSR in Table 1. PSNR comparison of Blind Requantization and Direct Quantization by Q1 for different images is shown in Table 2.
Table 1. Requantization Error comparison of various QSR for different images (Normal Rounding Technique)
Image
QSR is slightly less than 2 (Q0=Q75 & Q1=Q52)
QSR is slightly more than 2 (Q0=Q75 & Q1=Q49)
QSR is on and around 4 (Q0=Q75 & Q1=Q24)
QSR is on and around 3 (Q0=Q75 & Q1=Q33) PRE NRE PRE NRE PRE NRE PRE NRE Lena Cameraman Bird Henry Home Baboon 4686 4776 2715 8214 3498 11310 616 509 367 450 399 671 915 1027 837 1308 775 1246 2053 2106 1057 826 1559 5310 313 284 197 307 269 465 679 697 355 675 447 1659 43 29 9 28 23 68 103 126 57 144 77 215
Table 2. PSNR comparison of Blind Requantization and Direct Quantization by Q1 (Normal Rounding Technique)
P1: PSNR of Blind Requantization in dB. P2: PSNR of Direct Quantization by Q1 in dB.
Image
QSR is slightly less than 2 (Q0=Q75 & Q1=Q52)
QSR is slightly more than 2 (Q0=Q75 & Q1=Q49)
QSR is on and around 4 (Q0=Q75 & Q1=Q24)
3.2.2 Observations from Table 1 & 2
• When QSR is equal to or just below 2, number of PREs in a recompressed image is very high which leads to decrease in PSNR of recompressed image in an average of 2 dB.
• When QSR is slightly greater than 2, number of NREs in a recompressed image is very high which leads to which leads to decrease in PSNR of recompressed image in an average of 1dB.
• When QSR is on and around 4, the number of PREs & NREs is low which leads to slight decrease in PSNR of the recompressed image.
• When QSR is on and around 3, then PSNR of blind requantization is almost equal to PSNR of direct quantization by Q1.
From the above observation, it is clear that the PRE adds more noise to an image which will lead to poor PSNR whereas NRE reduces the sharpness particularly around the edges, and also increase in NRE does not have great impact on PSNR and it is less objectionable to eye.
4. Related Work
The main objective of the requantization is to optimally balance the image quality and bit rate. To validate the recompressed image, image quality measures such as PSNR, Bits per Pixel, Compression ratio and Image Size are used. The factors that control these image quality measures are Requantization error, Quantization Step Ratio (QSR) and Normal rounding technique during requantization. The combinations of these factors have been studied by many researchers to improve the image quality measures of recompressed image.
The relationship between requantization errors and visual quality has been studied by Syin Chan 1992; C.M.Ng 2001; and Jae won Moon 2006. To get the better recompression images, both PRE and NRE should be minimized. If it is possible to know the locations of the PRE & NRE, a correction may be made to restore the image to be closed as to the intended image. However, in the situation where the original image is not available, it is not possible to determine exactly the coefficients in which the requantization errors occur. So Syin Chan [3] decided to calculate the probabilities of the occurrence of PRE and NRE in the coefficients; subsequently these probabilities may be used for determining the correction to be made. He also proposed the function of estimation of the probabilities of errors; probability of coefficient enlargement and probability of coefficient reduction [3]. Using these probability functions, he suggested different methods to suppress the probabilities of errors to overcome the recompression artifacts.
C.M.Ng et al [14] presented a quantization error reduction algorithm to preserve the originality of the image against recompression based on QSR. His algorithm consists of two phases. The first phase collects statistical data to determine the threshold for the runtime correction in the second phase. In second phase, for each DCT coefficient, the probabilities of occurrence of quantized errors are calculated using probability functions [14]. These probabilities are checked against the thresholds obtained in the first phase and the quantized DCT coefficients will be adjusted accordingly. This algorithm improves the PSNR over 1dB.
Jae won Moon et al [10] demonstrated an algorithm that manipulates the requantized DCT coefficients for enhancing the quality of recompressed image, regardless of the choice of requantization step sizes. The requantized image (YQ0_Q1) has lower PSNR than the directly quantized one (YQ1) when there are more wrong coefficients which is due to requantization errors. They defined the requantization error as the discontinuity of pixels around the block boundaries, between the given JPEG image and the targeting one. They defined the error measure as the difference of pixels of YQ0_Q1 (u, v) around the boundary from those of neighboring blocks of YQ0 (u, v). The requantized coefficients are adjusted to minimize the smoothness constraint [10]. A coefficient needs to be adjusted only when the quantization steps of Q0 overlap with those of Q1. An alternative method is also proposed to reduce the computational loads. The proposed algorithm improves the PSNR up to 3 dB and shows better performance at the range of moderate bits per pixel but becomes a little poorer than the blind requantization in the low bits per pixel.
then it generates the new quantization matrix Q1 for requantization based on QSR. A modified rounding convention, which rounds genuine positive half integers (1/2, 3/2...) down (towards zero) is used for rounding the requantized coefficients. This algorithm is mainly concentrated on the perceptual image quality of recompressed image and other image quality measures are not considered. The heuristic algorithm performs better than blind requantization over most images and it improves the PSNR over 5dB for higher quality factor Q1.
Ora Gendler et al [15] in 2009 analyzed the requantization method for recompression of images in the DCT domains from a rate distortion point of view. They found that an even multiple of the original quantization step as the most efficient requantization step and also suggested to round the requantized coefficients towards zero. Bit rate of requantized image decreased significantly when the requantization step is an even multiple of the original step size. MSE is minimized at odd multiples of the original quantization step size and increased at even multiples. However the visual quality obtained at even multiples is still much better than for other (not integer multiples of original quantization step) requantization steps. They introduced a rate distortion function which is used to analyze the performance of the second stage quantizer. These experimental results show that there are some requantization step sizes that will cause a larger distortion without reducing the rate which clearly state to avoid such requantization steps.
5. Proposed Work
Generally quantization error occurs due to rounding of quantized coefficients whose decimal value occurs on and around 0.5. Normal rounding technique rounds the decimal value towards zero when it occurs between 0 & 0.49 and remaining values rounded towards infinity. This normal rounding technique may increases requantization error. For example, let us consider a requantized coefficient whose decimal value is 0.53, then it is rounded towards positive infinity according to normal rounding technique. While dequantization, the dequantized coefficient value will be high in terms of half of quantizer (Q1/2) which leads to error.
This Normal rounding technique creates unacceptable change in PSNR when QSR is around 2 that lead to downside of the Blind requantization method which is shown in fig. 3(d). When an image which is already quantized by lower quality scale Q0 and it is requantized to higher quality scale Q1, one is supposed to expect the image quality equal to the image which is directly quantized by Q1. The rounding of all requantized coefficients towards zero may minimized the above said error. But there is a loss in sharpness of the recompressed image. So instead of rounding all requantized coefficients towards zero, we can round the coefficients whose decimal value is around 0.5.
Based on our experience, we have proposed an enhanced rounding technique for requantization and also suggested to have the difference between two quality scales (Q0 & Q1) is no less than 15. This technique rounds the positive requantized coefficient having decimal value up to 0.7 towards zero and negative requantized coefficient having decimal value up to 0.6 towards zero. This enhanced rounding technique optimally increases the PSNR and other image quality measures. The numbers of PREs and NREs in recompressed image are calculated and the results are tabulated with respect to QSR in Table 3. PSNR comparison of both rounding techniques with various QSR for different images is shown in Table 4.
Table 3. Requantization Error comparison of various QSR for different images (Enhanced Rounding Technique)
Table 4. PSNR comparison of rounding techniques with various QSR for different images.
Image
QSR is slightly less than 2 (Q0=Q75 & Q1=Q52)
QSR is slightly more than 2 (Q0=Q75 & Q1=Q49)
QSR is on and around 4 (Q0=Q75 & Q1=Q24)
QSR is on and around 3 (Q0=Q75 & Q1=Q33) PRE NRE PRE NRE PRE NRE PRE NRE Lena
Cameraman Bird Henry Home Baboon
135 150 112 184 93 293
3534 3669 1953 1571 2683 8152
45 43 39 57 29 69
2814 2921 1573 1361 2207 6410
5 6 4 0 2 2
1299 1314 748 1320 1179 2634
5 4 1 4 2 22
Image
QSR is slightly less than 2 (Q0=Q75 & Q1=Q52)
QSR is slightly more than 2 (Q0=Q75 & Q1=Q49)
QSR is on and around 4 (Q0=Q75 & Q1=Q24)
QSR is on and around 3 (Q0=Q75 & Q1=Q33) Normal
Rounding (dB)
Enhanced Rounding
(dB)
Normal Rounding
(dB)
Enhanced Rounding
(dB)
Normal Rounding
(dB)
Enhanced Rounding
(dB)
Normal Rounding
(dB)
Enhanced Rounding
(dB) Lena
Cameraman Bird Henry Home Baboon
30.53 29.25 36.14 29.63 35.05 22.82
32.02 30.68 37.44 31.83 36.27 24.54
31.96 30.71 37.24 31.67 36.03 24.52
32.03 30.73 37.43 31.79 36.21 24.55
30.30 28.92 35.51 29.87 33.87 22.76
30.20 28.80 35.33 29.79 33.54 22.73
31.48 30.24 36.87 30.91 35.46 23.91
30.90 29.56 36.20 30.38 34.67 23.36
5.1.Observations from Table 3 & 4
• The enhanced rounding technique reduces the PRE in appreciable manner but it also increases the NRE which is less objectionable to our eye.
• The enhanced rounding technique increases the PSNR than normal rounding technique in an average of 2 dB for QSR on and around 2.
• When QSR is around 3 & 4, PSNR is decreased slightly than normal rounding technique even though NRE is very high.
6. Experimental Results
We estimated the quality measures for the following 256x256 gray scale images: Lena, Cameraman, Bird, Henry, Home and Baboon. Test images are compressed to Q75 and then recompressed to different quality levels using enhanced rounding technique. MATLAB R2007b, technical computing software was used for implementing the JPEG algorithm. In addition, this software supports the image processing toolbox which is used as a basis for developing custom algorithms.
Fig.4: Y75_50 Blind Requantization (Normal Rounding)
40 42 44 46 48 50 52 54 56 58 60 7000
7500 8000 8500 9000 9500 10000 10500 11000 11500
Quality factor
Si
z
e
LENA
Y75Q1(Normal Rounding)
YQ1
Y75Q1(Enhanced Rounding)
Fig. 6(a) Lena: Image Size vs. Quality factor
40 42 44 46 48 50 52 54 56 58 60
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
Quality factor
B
it
s
pe
r pi
x
e
l
LENA
Y75Q1(Normal Rounding)
YQ1
Y75Q1(Enhanced Rounding)
Fig. 6(c) Lena: Bits per Pixel vs. Quality factor
40 42 44 46 48 50 52 54 56 58 60
5.5 6 6.5 7 7.5 8 8.5 9 9.5
Quality factor
Co
m
p
re
s
s
io
n
ra
ti
o
LENA
Y75Q1(Normal Rounding)
YQ1
Y75Q1(Enhanced Rounding)
Fig. 6(b) Lena:Compression Ratio vs. Quality factor
40 42 44 46 48 50 52 54 56 58 60
30.5 31 31.5 32 32.5 33 33.5 34
Quality factor
PSN
R
LENA
Y75Q1(Normal Rounding)
YQ1
Y75Q1(Enhanced Rounding)
Fig. 6(d) Lena: PSNR vs. Quality factor
Blind Requantization (Enhanced rounding) solves the contrary problem discussed in section 3.1 and the resulting images have almost same PSNR and have good ratings over other image quality measures when compared to Blind Requantization (Normal Rounding) method. The performance of enhanced rounding technique is empirically analyzed with respect to Requantization errors for various QSR. The analysis confirms that the enhanced rounding technique decreases the PRE and also increases the image quality measures.
The Enhanced rounding technique produces better results than direct quantization for all image quality measures except PSNR. Comparison of image quality measures with respect to different quality factor for images “Lena”, are shown in figures 6(a)-(d). The perceptual quality of the “Lena” image for both rounding techniques is shown in figure 4 & 5 for comparison. For illustration, two boxes marked in figure 4 have been improved using the proposed method as shown in figure 5.
7. Conclusion
References
[1] Andrew B. Watson. (1993): Visual Optimization of DCT Quantization Matrices for Individual Images. Proceedings AIAA Computing in Aerospace 9, San Diego, CA, American Institute of Aeronautics and Astronautics. pp.286-291.
[2] Bauschke H.H; Hamilton C.H; Macklem M.S; McMichael J.S; Swart N.R. (2003): Recompression of JPEG images by Requantization. IEEE Trans. On Image Processing Vol 12, Issue 7 pp. 843-849.
[3] Chan.S. (1992): Recompression of Still images. Tech. Rep.2-92* University of Kent, Canterbury, UK. [4] Gregory K.Wallace.(1991): The JPEG Still Picture Compression Standard. CACM, Vol. 34, No. 4, pp.31-44.
[5] Habiba Loukil Hadj Kacem, Fahmi Kammoun and Mohamed Salim Bouhlel.(2004): Improvement of the Compression JPEG Quality by a Pre-processing Algorithm based on Denoising. IEEE International Conference of Industrial Technology (ICIT), 2004.
[6] Independent JPEG group, http://www.ijg.org
[7] Ingo Bauermann and Eckehard Steinbach.(2004): Further Lossless Compression of JPEG Images. Picture Coding Symp., PCS 2004, San Francisco.
[8] Joint Photographic Experts Group, http://www.jpeg.org.
[9] Jonathan K.Su and Russell M.Mersereau. (1995): Post-Processing for Artifact Reduction in JPEG-Compressed Images. Acoustics, Speech and Signal Processing. (ICASSP).
[10] Jae Won Moon, Jong Seok Lee, Nam Ik Cho.(2006): A requantization algorithm for the transcoding of JPEG images,Signal Processing: Image communication (21) 13-21.
[11] Macklem M.S.(2002): Multidimensional Modeling of Image Fidelity Measures. M.Sc. Thesis, Dept. Mathematics, Simon Fraser University, Burnaby, BC, Canada.
[12] Munenori Oizumi (2006): Preprocessing method for DCT-based Image-Compression. IEEE Transcations on Consumer Electronics, Vol. 52, No.3.
[13] Nikolay Ponomarenko, Karen Egiazarian. Vladimir Lukin, Jaakko Astola.(2005): Additional Lossless Compression of JPEG Images. Proceedings of the 4th International Symposium on Image and Signal Processing and Analysis.
[14] Ng C.M, Vincent Ng and Poon P L (2001): Quantisation Error Reduction for Reducing Q-Factor JPEG Recompression. IFSA World Congress and 20th NAFIPS International Conference (Joint 9th).
[15] Ora Gendler and Moshe Porat(2009): On Efficient Quantization for Image Recompression”, 17th European Signal Processing Conference, (EUSIPCO).
[16] Reininger R.C and Gibson J.D.(983): Distributions of the two dimensional DCT coefficients for images. IEEE Trans.Commun., vol COM-31 pp.835-839.