Train and Apply Denoising Neural Networks
Image Processing Toolbox™ and Deep Learning Toolbox™ provide many options to remove noise from images. The simplest and fastest solution is to use the built-in pretrained denoising neural network, called DnCNN. However, the pretrained network does not offer much flexibility in the type of noise recognized. For more flexibility, train your own network using predefined layers, or train a fully custom denoising neural network.
Remove Gaussian Noise Using Pretrained Network
You can use the built-in pretrained DnCNN network to remove Gaussian noise without the challenges of training a network. Removing noise with the pretrained network has these limitations:
Noise removal works only with 2-D single-channel images. If you have multiple color channels, or if you are working with 3-D images, remove noise by treating each channel or plane separately. For an example, see Remove Noise from Color Image Using Pretrained Neural Network.
The network recognizes only Gaussian noise, with a limited range of standard deviation.
To load the pretrained DnCNN network, use the denoisingNetwork
function. Then, pass the DnCNN network and a noisy
2-D single-channel image to denoiseImage
. The image shows the workflow to denoise an image using
the pretrained DnCNN network.
Train a Denoising Network Using Built-In Layers
You can train a network to detect a larger range of Gaussian noise standard deviations from grayscale images, starting with built-in layers provided by Image Processing Toolbox. To train a denoising network using predefined layers, follow these steps. The diagram shows the training workflow in the dark gray box.
Create an
ImageDatastore
object that stores pristine images.Create a
denoisingImageDatastore
object that generates noisy training data from the pristine images. To specify the range of the Gaussian noise standard deviations, set theGaussianNoiseLevel
property. You must use the default value ofPatchSize
(50
) andChannelFormat
('grayscale'
) so that the size of the training data matches the input size of the network.Get the predefined denoising layers using the
dnCNNLayers
function.Define training options using the
trainingOptions
(Deep Learning Toolbox) function.Train the network, specifying the denoising image datastore as the data source for
trainNetwork
(Deep Learning Toolbox). For each iteration of training, the denoising image datastore generates one mini-batch of training data by randomly cropping pristine images from theImageDatastore
, then adding randomly generated zero-mean Gaussian white noise to each image patch. The standard deviation of the added noise is unique for each image patch, and has a value within the range specified by theGaussianNoiseLevel
property of the denoising image datastore.
After you have trained the network, pass the network and a noisy grayscale image
to denoiseImage
. The diagram shows the denoising workflow in the light
gray box.
Train Fully Customized Denoising Neural Network
To train a denoising neural network with maximum flexibility, you can use a custom datastore to generate training data or define your own network architecture. For example, you can:
Train a network that detects a larger variety of noise, such as non-Gaussian noise distributions, in single-channel images. You can define the network architecture by using the layers returned by the
dnCNNLayers
function. To generate training images compatible with this network, use thetransform
andcombine
functions to batches of noisy images and the corresponding noise signal. For more information, see Preprocess Images for Deep Learning (Deep Learning Toolbox).After you train a denoising network using the DnCNN network architecture, you can use the
denoiseImage
function to remove image noise.Tip
The DnCNN network can also detect high-frequency image artifacts caused by other types of distortion. For example, you can train the DnCNN network to increase image resolution or remove JPEG compression artifacts. The JPEG Image Deblocking Using Deep Learning example shows how to train a DnCNN network to remove JPEG compression artifacts
Train a network that detects a range of Gaussian noise distributions for color images. To generate training images for this network, you can use a
denoisingImageDatastore
and set theChannelFormat
property to'rgb'
. You must define a custom convolutional neural network architecture that supports RGB input images.After you train a denoising network using a custom network architecture, you can use the
activations
(Deep Learning Toolbox) function to isolate the noise or high-frequency artifacts in a distorted image. Then, subtract the noise from the distorted image to obtain a denoised image.
See Also
denoisingImageDatastore
| dnCNNLayers
| denoisingNetwork
| trainingOptions
(Deep Learning Toolbox) | trainnet
(Deep Learning Toolbox) | trainNetwork
(Deep Learning Toolbox) | denoiseImage
| activations
(Deep Learning Toolbox) | combine
| transform
Related Examples
- Remove Noise from Color Image Using Pretrained Neural Network
- JPEG Image Deblocking Using Deep Learning
- Prepare Datastore for Image-to-Image Regression (Deep Learning Toolbox)
More About
- Preprocess Images for Deep Learning (Deep Learning Toolbox)
- Deep Learning in MATLAB (Deep Learning Toolbox)