Lossless Recompression of JPEG Images Using Transform Domain Intra Prediction
Lossless Recompression of JPEG Images Using Transform Domain Intra Prediction
Lossless Recompression of JPEG Images Using Transform Domain Intra Prediction
32, 2023
Abstract— JPEG, which was developed 30 years ago, is the an important part in social life. More importantly, more and
most widely used image coding format, especially favored by more people use social media websites such as Facebook and
the resource-deficient devices, due to its simplicity and efficiency. Flickr to share and communicate [5], [6]. These websites have
With the evolution of the Internet and the popularity of mobile
devices, a huge amount of user-generated JPEG images are to save a large number of JPEG images uploaded by people
uploaded to social media sites like Facebook and Flickr or every day. The massive application of JPEG images inevitably
stored in personal computers or notebooks, which leads to an leads to a huge demand for storage resources [7], [8]. That
increase in storage cost. However, the performance of JPEG means how to reduce the storage cost of JPEG images (or
is far from the-state-of-the art coding methods. Therefore, the files)1 in cloud or personal computers or notebooks is an
lossless recompression of JPEG images is urgent to be studied,
which will further reduce the storage cost while maintaining important problem to be studied.
the image fidelity. In this paper, a hybrid coding framework On the one hand, still image compression techniques
for the lossless recompression of JPEG images (LLJPEG) using have achieved great success in compression performance. For
transform domain intra prediction is proposed, including block example, JPEG2000 [9], which is based on wavelets and
partition and intraprediction, transform and quantization, and arithmetic coding, not only obtains higher quality images, but
entropy coding. Specifically, in LLJPEG, intra prediction is first
used to obtain a predicted block. Then the predicted block is also provides scalable capability. BPG [10], which utilizes the
transformed by DCT and then quantized to obtain the predicted HEVC intra coding techniques, achieves the similar image
coefficients. After that, the predicted coefficients are subtracted quality only with half of JPEG file size. However, due to
from the original coefficients to get the DCT coefficient residuals. their complexity, they are not widely used. Meanwhile, lossless
Finally, the DCT residuals are entropy coded. In LLJPEG,
image compression methods have made some progress and are
some new coding tools are proposed for intra prediction and
the entropy coding is redesigned. The experiments show that still under developed. For example, JPEG-LS [11] applies a
LLJPEG can reduce the storage space by 29.43% and 26.40% simple fixed context model to explore high-order correlation
on the Kodak and DIV2K datasets respectively without any loss with Golomb type codes. CALIC [12] uses a large number
for JPEG images, while maintaining low decoding complexity. of modeling contexts to condition a non-linear predictor
Index Terms— JPEG, recompression, lossless, intra prediction. and make it adaptive to varying source statistics. FLIF [13]
builds the contexts as the nodes of decision trees with a
I. I NTRODUCTION context-adaptive binary arithmetic coding. The lossless coding
techniques of HEVC [23], [24] and VVC [29], [30] explore
J PEG is a compression standard for still images developed
by the Joint Photographic Experts Group in the 1990s [1],
[2]. Currently, JPEG is still the most important and widely
more complex and efficient intra prediction. It should be
noted that all these lossless image compression methods use
used image compression format, due to its simplicity and the high order spatial correlation to get higher compression
efficiency [3], [4]. However, its compression performance is performance. However, they are not efficient to losslessly
far from the-state-of-the-art. compress a JPEG file, and even increase the JPEG file size
Nowadays, with the development of digital devices, it has when an image lossless encoder is applied to compress the
become a habit for people to use digital photo albums to record decoded JPEG image.
their lives, and digital images represented by JPEG has become On the other hand, the recompression of JPEG images
has attracted attention because it can further reduce the
Manuscript received 23 September 2021; revised 31 August 2022;
accepted 14 November 2022. Date of publication 7 December 2022; date
storage space of JPEG files [14]. The recompression of
of current version 16 December 2022. This work was supported in part by JPEG images can be classified into two categories: lossy and
the National Key Research and Development Program of China under Grant lossless JPEG recompression. In lossy JPEG recompression,
2021YFF0900500; in part by the National Natural Science Foundation of
China (NSFC) under Grant 61972115 and Grant 62272128; and in part by
TinyPNG [15], Mozjpeg [16], and Guetzli [17], [18], achieve
the Media Innovation Laboratory, Architecture and Technology Innovation better compression performance by merging colors, changing
Department, Huawei Cloud, and the Media Service Product Department, scanning order or using human visual model. However,
Huawei Cloud. The associate editor coordinating the review of this manuscript
and approving it for publication was Dr. Marc Antonini. (Corresponding
lossy JPEG recompression will inevitably lead to permanent
author: Xiaopeng Fan.) loss of JPEG images, which is unacceptable especially for
The authors are with the School of Computer Science and Technology, some applications such as medical research and criminal
Harbin Institute of Technology, Harbin 150001, China, and also with the
Peng Cheng Laboratory, Shenzhen 519055, China (e-mail: [email protected];
[email protected]; [email protected]). 1 In this paper, a JPEG image or JPEG file means the generated bitstream
Digital Object Identifier 10.1109/TIP.2022.3226409 of an image after JPEG encoding.
1941-0042 © 2022 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission.
See https://www.ieee.org/publications/rights/index.html for more information.
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
SUN et al.: LOSSLESS RECOMPRESSION OF JPEG IMAGES USING TRANSFORM DOMAIN INTRA PREDICTION 89
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
90 IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 32, 2023
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
SUN et al.: LOSSLESS RECOMPRESSION OF JPEG IMAGES USING TRANSFORM DOMAIN INTRA PREDICTION 91
Fig. 3. The distribution comparison of DCT coefficient residuals (blue lines) and original DCT coefficients (red lines) on Lena image (512 × 512) with
QF = 80.
original coefficients to get the DCT coefficient residuals. quantization and entropy coding. On the one hand, the fixed
Finally, the DCT coefficient residuals are encoded by the coding block size in JPEG cannot adapt to a variety of image
redesigned entropy coder. contents, so LLJPEG can adopt more flexible block partition
For LLJPEG decoder, the decoding process corresponds to to improve the coding performance. On the other hand, the
the encoding process one by one. After decoding the transform transform and quantization units of JPEG is 8 × 8 blocks, that
coefficients of all blocks, the LLJPEG decoder encodes the means the transform and quantization unit of LLJPEG must
transform coefficients and the JPEG header information into be consistent with JPEG to perform intra prediction for DCT
the output JPEG file using the JPEG entropy encoder. coefficients in a JPEG file.
Based on the above observation, a quadtree structure for
C. Block Partition and Intra Prediction block partition is adopted by LLJPEG. In the block partition
1) Block Partition in LLJPEG: The coding block size in scheme, a unit called coding block (CU) is defined, the size
JPEG is fixed to 8 × 8, which is the unit of transform, of which is 8 × 8, 16 × 16, 32 × 32, and 64 × 64. CU is the
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
92 IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 32, 2023
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
SUN et al.: LOSSLESS RECOMPRESSION OF JPEG IMAGES USING TRANSFORM DOMAIN INTRA PREDICTION 93
TABLE I its filtered pixel. For vertical modes and horizontal modes, the
H IT R ATE OF DC M ODE W HEN R EFERENCE P IXELS A RE THE S AME filtered boundary pixels are calculated as follows, respectively:
p ′ (0, j) = (5 ∗ p (0, j) + 2 ∗ ( p (−1, j) − p (−1, −1))
+ ( p (−2, j) − p (−2, −1)) + 4) ≫ 3 (3)
p (i, 0) = (5 ∗ p (i, 0) + 2 ∗ ( p (i, −1) − p (−1, −1))
′
encoding process directly and accurately, the Sum of Absolute p ′ (0, 0) = (2 ∗ p (−1, −1) + 3 ∗ ( p (−1, 0)
Hadamard Transformed Difference (SATD) is not needed. The + p (0, −1))+8 ∗ dc + 8) ≫ 4 (5)
cost of LLJPEG rough mode selection is calculated as follows p (i, 0) = ( p (i, −2) + 2 ∗ p (i, −1) + 5 ∗ dc + 4) ≫ 3 (6)
′
cost mode = Sum abs C p − Co + λ ∗ R (i mode ) (1) p ′ (0, j) = ( p (−2, j) + 2 ∗ p (−1, j) + 5 ∗ dc + 4) ≫ 3 (7)
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
94 IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 32, 2023
Fig. 9. Transform and quantization in an m × m CU. m ranges from 8 to 64, n = (m/8)∗ (m/8).
Fig. 10. Reorganization of transform coefficient residuals for a CU with 16 × 16. The left is the coefficient residuals in a 16 × 16 CU. Different colors are
used to represent the coefficient residuals in different 8 × 8 blocks. The right is the coefficient residuals after reorganization.
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
SUN et al.: LOSSLESS RECOMPRESSION OF JPEG IMAGES USING TRANSFORM DOMAIN INTRA PREDICTION 95
TABLE IV
C OMPRESSION P ERFORMANCE C OMPARISON (B ITS S AVING ) ON KODAK DATASET
TABLE V
C OMPRESSION P ERFORMANCE C OMPARISON (B ITS S AVING ) ON DIV2K DATASET
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
96 IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 32, 2023
TABLE VI
C OMPRESSION P ERFORMANCE (B ITS S AVING ) C OMPARISON ON KODAK DATASET W HEN QF = 80
TABLE VII
AVERAGE E NCODING AND D ECODING T IME C OMPARISON ON KODAK DATASET ( IN S ECONDS )
TABLE VIII
AVERAGE E NCODING AND D ECODING T IME C OMPARISON ON DIV2K DATASET ( IN S ECONDS )
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
SUN et al.: LOSSLESS RECOMPRESSION OF JPEG IMAGES USING TRANSFORM DOMAIN INTRA PREDICTION 97
TABLE IX
C OMPRESSION P ERFORMANCE AND C OMPLEXITY OF F OUR I NTRA P REDICTION M ODES , C LOSING THE B LOCK PARTION , C LOSING THE
N EW DC M ODE D ECISION M ETHOD , C LOSING THE F ILTERING OF P REDICTED B LOCKS ON KODAK DATASET
TABLE X
C OMPRESSION P ERFORMANCE AND C OMPLEXITY OF F OUR I NTRA P REDICTION M ODES , C LOSING THE B LOCK PARTION , C LOSING THE
N EW DC M ODE D ECISION M ETHOD , C LOSING THE F ILTERING OF P REDICTED B LOCKS ON DIV2K DATASET
We also compare the compression performance of LLJPEG time of LLJPEG is 0.058 seconds, while the encoding time is
with the prior-based JPEG lossless recompression method [21] 1.903 seconds. On the DIV2K dataset, the decoding time of
on the Kodak dataset under the quality factor of 80. The LLJPEG is about 0.101 seconds, while the encoding time is
experimental results are shown in Table VI. As [21] only 3.320 seconds. The experimental results on the two datasets
provides the experimental result on the 12 images with show that Winzip has the shortest encoding and decoding time,
QF = 80 and does not provide the experimental result on followed by jpegtran and LLJPEG.
other images or other QFs, Table VI only shows its results on
the 12 images. For a complete comparison, we also provide
the experimental results for all images on the Kodak dataset D. Ablation Experiments
using LLJPEG, Winzip and jpegtran. It can be seen that [21] In addition, in order to test the performance of LLJPEG’s
saves 7.76% of the storage space on average, while the storage coding tools, four ablation experiments are designed. We limit
space saved in LLJPEG is 21.57%. the intra prediction of LLJPEG to four intra modes (DC
mode, Planar mode, mode_26 and mode_10 only), turn off
the block partition of LLJPEG, turn off the new decision
C. Complexity Comparison for DC mode, and turn off the filtering after intra prediction.
The computational complexity of the above methods is also These experiments are carried out on the Kodak and DIV2K
tested. The experiments are carried out on the Kodak and datasets with QF from 90 to 10. The results are shown in
DIV2K datasets. The results are shown in Tables VII and VIII. Table IX and Table X.
Since the output of jpegtran is still in JPEG format, we only It can be seen that on the Kodak dataset, when only 4 intra
provide its encoding time. On the Kodak dataset, the decoding prediction modes are used, the encoding time is 66.22% of
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
98 IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 32, 2023
TABLE XI
P ERFORMANCE AND E NCODING T IME C OMPARISON OF THE P ROPOSED T WO -S TAGE I NTRA P REDICTION M ODE D ECISION ON KODAK DATASET
TABLE XII
P ERFORMANCE AND E NCODING T IME C OMPARISON OF THE P ROPOSED T WO -S TAGE I NTRA P REDICTION M ODE D ECISION ON DIV2K DATASET
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.
SUN et al.: LOSSLESS RECOMPRESSION OF JPEG IMAGES USING TRANSFORM DOMAIN INTRA PREDICTION 99
[19] H. Kulissen. (2005). Jpegtran Description. [Online]. Available: Chentian Sun received the B.S. and M.S. degrees
http://jpegclub.org/articles/Verlustfreie_JPEG_Drehung.pdf from the School of Computer Science and Technol-
[20] H. Kulissen. (2005). Jpegtran Project. [Online]. Available: https://www. ogy, Harbin Institute of Technology, Harbin, China,
npmjs.com/package/jpegtran in 2014 and 2016, respectively, where he is currently
[21] X. Liu, G. Cheung, C. Lin, D. Zhao, and W. Gao, “Prior-based pursuing the Ph.D. degree. His research interests
quantization bin matching for cloud storage of JPEG images,” IEEE include data compression, image and video coding,
Trans. Image Process., vol. 27, no. 7, pp. 3222–3235, Jul. 2018. computer vision, and deep learning.
[22] T.-A. Pham and M. Delalandre, “Effective decompression of JPEG
document images,” IEEE Trans. Image Process., vol. 25, no. 8,
pp. 3655–3670, Aug. 2016.
[23] G. J. Sullivan, J.-R. Ohm, W.-J. Han, and T. Wiegand, “Overview of the
high efficiency video coding (HEVC) standard,” IEEE Trans. Circuits
Syst. Video Technol., vol. 22, no. 12, pp. 1649–1668, Dec. 2012.
[24] F. Bossen, B. Bross, K. Sühring, and D. Flynn, “HEVC complexity and
implementation analysis,” IEEE Trans. Circuits Syst. Video Technol.,
vol. 22, no. 12, pp. 1685–1696, Dec. 2012.
[25] X. Zhang, S. Liu, and S. Lei, “Intra mode coding in HEVC standard,” Xiaopeng Fan (Senior Member, IEEE) received the
in Proc. Vis. Commun. Image Process., Nov. 2012, pp. 1–6. B.S. and M.S. degrees from the Harbin Institute
[26] J. Lainema, F. Bossen, W.-J. Han, J. Min, and K. Ugur, “Intra coding of of Technology (HIT), Harbin, China, in 2001 and
the HEVC standard,” IEEE Trans. Circuits Syst. Video Technol., vol. 22, 2003, respectively, and the Ph.D. degree from The
no. 12, pp. 1792–1801, Dec. 2012. Hong Kong University of Science and Technology
[27] L. Zhao, L. Zhang, S. Ma, and D. Zhao, “Fast mode decision algorithm (HKUST), Hong Kong, in 2009.
for intra prediction in HEVC,” in Proc. Vis. Commun. Image Process. From 2003 to 2005, he was a Software Engineer
(VCIP), Nov. 2011, pp. 1–4. at Intel Corporation, China. In 2009, he joined HIT,
[28] J.-R. Ohm, G. J. Sullivan, H. Schwarz, T. K. Tan, and T. Wiegand, where he is currently a Professor. From 2011 and
“Comparison of the coding efficiency of video coding standards- 2012, he was a Visiting Researcher at Microsoft
including high efficiency video coding (HEVC),” IEEE Trans. Circuits Research Asia. From 2015 to 2016, he was a
Syst. Video Tech., vol. 22, no. 12, pp. 1669–1684, Dec. 2012. Research Assistant Professor at HKUST. Since 2018, he has been with the
[29] G. J. Sullivan, “Video coding standards progress report: Joint video Peng Cheng Laboratory. He has authored one book and over 150 papers in
experts team launches the versatile video coding project,” SMPTE refereed journals and conference proceedings. His current research interests
Motion Imag. J., vol. 127, no. 8, pp. 94–98, Sep. 2018. include video coding and transmission, image processing, and computer
[30] F. Pakdaman, M. A. Adelimanesh, M. Gabbouj, and M. R. Hashemi, vision. He was a recipient of the Outstanding Contributions Award to the
“Complexity analysis of next-generation VVC encoding and decoding,” Development of IEEE Standard 1857 by IEEE in 2013. He served as the
in Proc. IEEE Int. Conf. Image Process. (ICIP), Oct. 2020, Program Chair for PCM2017, the Chair for IEEE SGC2015, and the Co-
pp. 3134–3138. Chair for MCSN2015. He has been an Associate Editor of the IEEE 1857
[31] G. Van der Auwera, J. Heo, and A. Filippov, Ce3: Summary Report on S TANDARD : E MPOWERING S MART V IDEO S URVEILLANCE S YSTEMS since
Intra Prediction and Mode Coding, document JVET-K0023, 11th JVET 2012.
Meeting, 2018.
[32] J. Chen, M. Karczewicz, Y.-W. Huang, K. Choi, J.-R. Ohm,
and G. J. Sullivan, “The joint exploration model (JEM) for video
compression with capability beyond HEVC,” IEEE Trans. Circuits Syst.
Video Technol., vol. 30, no. 5, pp. 1208–1225, May 2020.
[33] A. Said, X. Zhao, M. Karczewicz, J. Chen, and F. Zou, “Position
dependent prediction combination for intra-frame video coding,” in Proc. Debin Zhao (Member, IEEE) received the B.S.,
IEEE Int. Conf. Image Process. (ICIP), Sep. 2016, pp. 534–538. M.S., and Ph.D. degrees in computer science from
[34] B. Bross, J. Chen, J.-R. Ohm, G. J. Sullivan, and Y.-K. Wang, the Harbin Institute of Technology (HIT), China,
“Developments in international video coding standardization after AVC, in 1985, 1988, and 1998, respectively.
with an overview of versatile video coding (VVC),” Proc. IEEE, In 1987, he joined HIT, where he is currently a
vol. 109, no. 9, pp. 1463–1493, Sep. 2021. Professor with the Department of Computer Science.
[35] R. Franzen. (2010). Kodak Dataset. [Online]. Available: http://r0k. Since 2018, he has been with the Peng Cheng Labo-
us/graphics/kodak/ ratory. He has published over 200 technical paper in
[36] R. Timofte. (2018). DIV2K Dataset. [Online]. Available: https://data. refereed journals and conference proceedings. His
vision.ee.ethz.ch/cvl/DIV2K/ current research interests include image and video
[37] B. Bfriesen. (2000). Libjpeg Project. [Online]. Available: http://libjpeg. coding, compressive sensing, deep networks, and
sourceforge.net/ computer vision.
Authorized licensed use limited to: Rajeev Gandhi Memorial College of Eng and Tech. Downloaded on October 10,2023 at 13:51:42 UTC from IEEE Xplore. Restrictions apply.