DnCNN¶
| Fact | Value |
|---|---|
| Also called | CNN denoiser, DnCNN-based deblocking, DnCNN-3 |
| Status | Available through an optional pretrained model |
| Family | Deep learning and learned processing |
| Engine | Science engine |
| Type | Nonlinear, learned, residual CNN denoising |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | 20 |
| Code | engine/src/pixelnexus_engine/filters/learned.py, dncnn |
| Operator code | engine/src/pixelnexus_engine/filters/learned.py, dncnn_representation |
| Packages | ONNX Runtime (optional) |
Overview¶
DnCNN, by Zhang and colleagues, removes noise with a network of 20 convolutions. It does not learn the clean image. It learns the noise, which is simpler, and subtracts it. The color model is blind, so you set no noise level. A second model, DnCNN-3, was trained for noise, blur and JPEG blocking together. PixelNexus uses it on the brightness to clean JPEG artifacts. The filter runs in the PixelNexus engine.
It needs an optional model. The model downloads only when you click Download model in the Properties panel, which first shows its size and license, and the engine checks its SHA-256 before it keeps it. Models published as PyTorch weights are converted to ONNX once on your computer with tools/export_models.py. The engine itself never uses PyTorch. Results carry the label: AI result. Detail may not exist in the original scene.
How it works¶
- Scale the pixels to 0 to 1.
- Run 20 convolutions with ReLU, which estimate the noise.
- Subtract the estimate from the input.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(y\): The noisy image
- \(f_\theta\): The network with its trained weights
- \(\hat{x}\): The restored image
y is the noisy image and f is the network. Instead of the clean image, DnCNN learns the noise, the residual, and subtracts it. Batch normalization made training stable, and in the released weights it is merged into the convolutions.
Residual learning makes the task easier: for small noise, the residual is close to a Gaussian with a fixed spread, whatever the image. Batch normalization stabilized training. In the released weights, KAIR merged it into the convolutions, so inference is plain convolution and ReLU.
Kernel or operator¶
A trained network has many learned kernels, not one. The Inspector shows the stages and the model with its license.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Task task |
Remove noise (color, blind) | Remove noise (color, blind), Clean JPEG artifacts (DnCNN-3) | Which model runs. Each downloads on its own. |
Implementation¶
dncnn in engine/src/pixelnexus_engine/filters/learned.py runs the ONNX file that tools/export_models.py made from KAIR's weights. The export imports KAIR's own network code at a pinned commit, with the settings of KAIR's test script: 20 layers, batch normalization merged. It keeps the file only when ONNX Runtime matches PyTorch, here to within 2e-6. Images run in tiles of 512 pixels with 24 pixels of margin, wider than the 20 pixel reach of the network, so tiles equal a run on the whole image. For JPEG cleanup, DnCNN-3 runs on Y of full-range Y'CbCr with the BT.709 weights, and Cb and Cr stay, our choice for color images.
Worked example¶
| Noise sigma | Noisy (dB) | DnCNN (dB) | FFDNet, level set (dB) | BM3D-lite (dB) |
|---|---|---|---|---|
| 15, in each channel | 24.63 | 37.56 | 38.63 | 37.69 |
| 25, in each channel | 20.24 | 34.60 | 35.24 | 33.76 |
| 50, in each channel | 14.76 | 30.18 | 29.72 | 27.81 |
| 25, the same in all channels | 20.20 | 20.38 | 23.68 | 33.59 |
JPEG artifacts, the gray image saved by Pillow at each quality:
| JPEG quality | JPEG (dB) | DnCNN-3 on Y (dB) |
|---|---|---|
| 10 | 25.68 | 28.37 |
| 20 | 27.10 | 29.43 |
| 40 | 29.96 | 31.46 |
PSNR against the clean image of the figure, 120 x 120, over the three channels. Gaussian noise is rounded and clipped to 8 bits. BM3D-lite runs on each channel.
With independent noise in each channel, both networks gain 14 to 15 dB at sigma 25 and beat BM3D-lite. Noise that is the same in all channels is another matter, as in a gray image saved as RGB. DnCNN then changes almost nothing, 0.2 dB, and FFDNet gains only 3.5 dB. Both color models were trained on noise that differs between channels, so noise without color looks like detail to them. For gray images, BM3D-lite or a gray model is the better choice. DnCNN-3 gains 1.5 to 2.7 dB on JPEG blocking.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels. About 0.7 million weights.
Artifacts and limitations¶
Limitations
- Trained on Gaussian noise, so real camera noise may be left.
- DnCNN-3 works on one channel, so color blocking stays.
Artifacts
- Smooth, waxy areas at strong noise.
Tests¶
Tiny ONNX models made inside the tests check the plumbing in every test run. Tiles with enough margin must equal a run on the whole image. Color, alpha and padding must be handled as described. Where the real model is downloaded, as on the development machine, the real network is checked too. On a noisy color scene the real DnCNN must gain more than 6 dB, and its tiles must equal a run on the whole image.
References¶
- Zhang, K., Zuo, W., Chen, Y., Meng, D., and Zhang, L. Beyond a Gaussian denoiser. Residual learning of deep CNN for image denoising. IEEE Transactions on Image Processing 26(7), 3142 to 3155, 2017. DOI 10.1109/TIP.2017.2662206.
- KAIR, the image restoration toolbox of Kai Zhang, which holds the trained weights and the network code that tools/export_models.py imports. https://github.com/cszn/KAIR