JPEG Artifact Correction using Denoising Diffusion Restoration Models
Abstract
Diffusion models can be used as learned priors for solving various inverse problems.
However, most existing approaches are restricted to linear inverse problems, limiting their applicability to more general cases.
In this paper, we build upon Denoising Diffusion Restoration Models (DDRM) and propose a method for solving some non-linear inverse problems.
We leverage the pseudo-inverse operator used in DDRM and generalize this concept for other measurement operators, which allows us to use pre-trained unconditional diffusion models for applications such as JPEG artifact correction.
We empirically demonstrate the effectiveness of our approach across various quality factors, attaining performance levels that are on par with state-of-the-art methods trained specifically for the JPEG restoration task.
Our code is available at https://github.com/bahjat-kawar/ddrm-jpeg .
[Figure]
Introduction
Many image processing problems are instances of inverse problems [22, 20, 21].
In real-world applications, one would often need to face multiple different degradation models [33, 14, 16], where training problem-specific models on each case could be expensive [27].
Therefore, it is valuable to develop methods that apply problem-agnostic models, which would adapt to different degradation models at inference time without retraining.
Existing approaches, while achieving decent performance on a variety of tasks, are generally limited to linear inverse problems [5, 34, 18, 16], leaving out certain important non-linear inverse problems such as JPEG artifact correction.
Since JPEG is a lossy image compression format [37], JPEG images exhibit loss of quality and undesired artifacts.
Several methods have been developed for addressing this problem [40, 4, 9, 23, 10, 15]. A v e r a g e P S N R ( d B )
Compression Rate (bpp)
JPEG Ours (A) To address this issue, we introduce a method that performs JPEG artifact correction using Denoising
Diffusion Restoration Models (DDRM) [16].
Our core idea is to generalize the pseudo-inverse matrix that exists in the DDRM update rule for the noiseless observation case.
This generalized notion of a “pseudo-inverse” includes JPEG as a special case, where the “pseudo-inverse” for JPEG encoding is simply JPEG decoding.
The resulting algorithm resembles the original update for DDRM, replacing the linear operator and its pseudo-inverse with JPEG encoding and decoding, respectively.
We apply our algorithm for JPEG restoration with various quality factors (QF), where the quantization matrices are embedded in the JPEG files and naturally known at inference time.
In common image quality metrics such as PSNR, SSIM [38], and LPIPS [41], our method compares favorably against a recent state-of-the-art GAN-based baseline [10] trained specifically for JPEG restoration.
Our method achieves even more improvement on low QF that the baseline is not trained on, demonstrating the generalization advantages of methods that leverage unconditional diffusion models.
Background
Diffusion Models.
Diffusion models [31, 13] are generative models with a Markov chain structure x T → x T − 1 → . . .
→ x 1 → x 0 , where ∀ t : x t ∈ R n , which defines the following joint distribution:
[Equation]
After x T , . . .
, x 0 are drawn, only x 0 is kept as the final output of the generative model.
When training a diffusion model, a fixed, factorized variational inference distribution is assumed:
[Equation]
which leads to an evidence lower bound (ELBO) on the maximum likelihood objective.
One particular parametrization [32] takes the following form:
[Equation]
where p ( t ) θ can be trained via a denoising autoencoder [36] objective; in the ideal case, the denoiser, denoted as f ( t ) θ ( x t ) should map to the MMSE (Minimum Mean Squared Error) estimator E q ( x 0 | x t )
[ x 0 ] , and constitutes a prediction over the “clean” x 0 .
Diffusion models have achieved unprecedented success in image generation [32, 35, 8, 17], and they have also been deployed for a variety of tasks [19, 6, 25, 3, 12, 1, 2, 29, 30].
Linear Inverse Problems.
A general linear inverse problem is posed as
[Equation]
where our aim is to recover the signal x ∈ R n from measurements y ∈ R m .
H ∈ R m × n is a known degradation matrix, and z ∼ N (0 , σ 2 y I ) is an additive white Gaussian noise with known variance.
Various works have applied diffusion models for inverse problem solving, mostly for the noiseless case.
While it is possible to train a conditional diffusion model based on pairs of x and y [27, 28, 39], such models may not generalize to other inverse problems.
Therefore, it is often desirable to formulate inverse problem solvers from unconditional diffusion models [5, 34, 18, 16], where the knowledge about the inverse problem does not need to be known during training; compared with problem-specific conditional diffusion models, problem-agnostic techniques save significant computational resources. [Table]
Denoising Diffusion Restoration Models (DDRM).
In particular, DDRM [16] is a general solver for linear inverse problems in both noisy and noiseless cases.
For any linear inverse problem, the
DDRM model is defined as
[Equation]
where x 0 is the final diffusion output.
The high-level idea behind DDRM is to leverage the singular value decomposition of H and transform both x and the possibly noisy y to a shared spectral space.
In this space, DDRM performs denoising on dimensions when information from y is available ( i.e. , when singular values are non-zero) and performs imputation on ones where such information is not available ( i.e. , when singular values are zero), taking account of the measurement noise explicitly.
JPEG.
JPEG [37] is a commonly used lossy compression method for images.
At a high-level, JPEG first transforms an uncompressed image from the RGB color space to the YCbCr space, optionally applies chroma subsampling, splits the image into 8 × 8 pixel blocks, performs a discrete cosine transform (DCT), and then performs quantization of the resulting values using a fixed quantization matrix.
These values can then be compressed in a lossless fashion via Huffman trees.
The entire process can be reverted to define the JPEG decoding method, with loss of information happening in the chroma subsampling and the quantization steps.
Since its introduction in 1991, JPEG has become the most widely used image compression format in the world, with several billion JPEG images produced every day; thus, restoring high-quality images from JPEG-compressed ones has wide applications.
Several previous methods were developed for this purpose [40, 4, 9, 23, 10, 15].
JPEG Artifact Correction with DDRM
For the case of no noise in the observation y , the general DDRM process to sample from p ( t ) θ ( x t | x t +1 , y ) for linear inverse problems simplifies to be
[Equation]
where H † is the Moore-Penrose pseudo-inverse of H , f ( t +1) θ ( x t +1 ) is the denoising model output at the previous step t + 1 , ϵ ( t +1) θ
[Equation]
is the predicted noise value, η and η b are user-defined hyperparameters, and ϵ t ∼ N (0 , I ) is a standard Gaussian distributed vector.
At a high level, we inject information about y via x ′ t where we replace the values in the spectral domain with what we know from y .
The sampling process then aggregates x ′ t (corrected from y ), x t +1 (the current input), and f ( t +1)
θ ( x t +1 ) (the denoiser output) to produce the value for the next iteration.
While it seems that the above approach only works for linear H , its insights can actually be used for other non-linear inverse problems, such as JPEG artifact correction.
We note that for a linear H , its pseudo-inverse H † has two important properties:
HH † H =
H , i.e. , taking the pseudo-inverse does not change the measurement.
H † H x is “close” to x , in the sense that H † H x provides a least squares solution for the problem min
z ∥
z − x ∥ 22 for all x when observing only y =
H x (but not x ).
The above properties may exist for operators that are not linear.
For example, if we treat H as the
JPEG encoding operator, then the JPEG decoding operator also satisfies these properties:
The JPEG encoding introduces loss of information during the quantization and chroma subsampling stages.
The remaining information is kept during JPEG decoding, and thus encoding it again will lead to the same result.
The JPEG decoding method generally preserves visual similarity, so applying decoding after encoding should generate an image that is “close” to the original one.
With this insight, we can simply perform JPEG restoration with DDRM with the update rule
[Equation]
which can be used in realistic settings as the quantization matrices are stored within the JPEG files.
Experimental Results
We evaluate our method on the ImageNet [7] dataset, as it is diverse and represents real-world use cases.
Specifically, we evaluate on a 1000 image subset of the ImageNet validation set named
ImageNet-1K [26].
We utilize the diffusion model from [8], trained on 256 × 256 -pixel ImageNet training images, for a diffusion schedule of 1000 timesteps.
In all of our experiments, we choose the hyperparameters η = 1 , η b = 0 . 4 , and 20 uniformly-spaced diffusion steps.
Additionally, since JPEG images generally preserve overall image contents, we find that we can perturb a JPEG-compressed image with noise and use it as an initialization for our sampling process at an intermediate step t = 300 , similar to [24].
This allows the sampling to provide more faithful reconstructions, avoiding the unnecessary randomness induced by starting at the initial timestep T = 1000 .
However, as we use a probabilistic sampling scheme, randomness can still be expected in the results.
In order to stabilize performance, we draw 8 independent samples for each input and save the resulting average image.
We denote the first sample as “Ours (S)” and the averaged image as “Ours (A)” .
For our JPEG artifact correction experiments, we use the most common variant of JPEG [11], which includes chroma subsampling and quantization matrices defined by a quality factor (QF) ranging from 1 to 100 , 1 being the most compressed, and 100 being the most faithful to the original image.
Our method produces high quality reconstructions (see Figures 1, 4).
Moreover, when evaluated numerically on common metrics such as PSNR, SSIM [38], and LPIPS [41], our method provides a significant improvement over simple JPEG decoding, and its performance is favorable or comparable to a recent state-of-the-art JPEG artifact correction named QGAC [10].
QGAC was specifically trained for JPEG restoration with QF ∈ [10 , 100] , and as can be seen in Table 1, it generalizes poorly for lower QF.
In contrast, our method generalizes well for all QF without JPEG-specific training.
We demonstrate its success by showing its compression rate-distortion curve in Figure 3.
Furthermore, our method is not limited to JPEG artifact correction, but can also be applied to similar non-linear inverse problems not covered by DDRM [16].
For instance, we consider the problem of image dequantization, where we attempt to recover high-quality reconstructions from images that were quantized below the standard 24 bits per color.
As evident in Figure 2, our method generalizes well for image dequantization, owing to its problem-agnostic nature.
Conclusion
We propose a novel method for correcting JPEG compression artifacts using diffusion models.
Our method extends DDRM [16] beyond the linear case by generalizing the pseudo-inverse concept.
We perform evaluations on ImageNet-1K [7, 26] where our method performs on par with a state-of-the-art baseline in most cases, and exhibits generalization abilities for lower quality factors which specifically trained baselines do not possess.
Our method can further generalize beyond JPEG restoration, as we successfully demonstrate on the image dequantization problem.
It does so seamlessly, without retraining, and without problem-specific hyperparameter tuning.
A Additional
Results
[Equation]