This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Denoising image source


A denoisingImageSource object encapsulates an image source that creates batches of noisy image patches and corresponding noise patches. The patches are used to train a denoising deep neural network.

This object requires that you have Neural Network Toolbox™.



source = denoisingImageSource(imds)
source = denoisingImageSource(imds,Name,Value)


source = denoisingImageSource(imds) creates a pairs of randomly cropped pristine and noisy image patchs, source, using images from image datastore imds.


source = denoisingImageSource(imds,Name,Value) specifies the patch size or sets properties using name-value pairs. You can specify multiple name-value pairs. Enclose each property name in quotes.

Input Arguments

expand all

Images, specified as an ImageDatastore object with categorical labels. You can store data in ImageDatastore for only classification problems.

ImageDatastore allows batch-reading of JPG or PNG image files using pre-fetching. If you use a custom function for reading the images, pre-fetching does not happen.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: denoisingImageSource(imds,'patchSize',48) creates a denoising image source that has a square patch size of 48 pixels.

expand all

Patch size, specified as the comma-separated pair consisting of 'patchSize' and a scalar or 2-element vector with positive integer values.

  • When 'patchSize' is a scalar, the patches are square

  • When 'patchSize' is a 2-element vector of the form [r c], the first element specifies the number of rows in the patch, and the second element specifies the number of columns

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32


expand all

Number of random patches per image, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Patch size, specified as a 3-element vector of positive integers. If the denoising image source is created specifying a 'patchSize' name-value argument, the first two elements of the PatchSize property are set according to the value of patchSize.

The ChannelFormat property determines the third element of the PatchSize property.

  • If ChannelFormat is 'Grayscale', all color images are converted to grayscale and the third element of PatchSize is 1.

  • If ChannelFormat is 'RGB', grayscale images are replicated to simulate an RGB image and the third element of PatchSize is 3.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Gaussian noise variance as a fraction of the image class maximum, specified as a scalar or 2-element vector with values in the range [0, 1].

  • When GaussianNoiseVariance is a scalar, it signifies a single noise level.

  • When GaussianNoiseVariance is a 2-element vector, it specifies the minimum and maximum noise variance. The range of noise variances is uniformly sampled, and each patch is assigned a unique noise level from the sampling.

Data Types: single | double

Channel format, specified as 'Grayscale' or 'RGB'.

Data Types: char

Flag to preprocess training patches in parallel, specified as true or false. When BackgroundExecution is true and you have Parallel Computing Toolbox™, denoisingImageSource asynchronously reads patches, adds noise, and queues patch pairs.

Data Types: char


expand all

Get an image datastore. This datastore contains RGB images.

setDir = fullfile(toolboxdir('images'),'imdata');
imds = imageDatastore(setDir,'FileExtensions',{'.jpg'});

Create a denoisingImageSource object. The image source creates many patches from each image in the datastore, and adds Gaussian noise to the patches. Set the optional PatchesPerImage, PatchSize, GaussianNoiseLevel, and ChannelFormat properties of the denoisingImageSource using name-value pairs.

source = denoisingImageSource(imds,...
    'GaussianNoiseLevel',[0.01 0.1],...
source = 
  denoisingImageSource with properties:

       PatchesPerImage: 512
             PatchSize: [50 50 3]
    GaussianNoiseLevel: [0.0100 0.1000]
         ChannelFormat: 'rgb'

You can use the denoisingImageSource to train a custom image denoising network. However, to do this, the image source must be created using grayscale images. Modify this example to point to your own image datastore containing grayscale images, and create a new denoising image source. Specify the ChannelFormat property of the image source as 'Grayscale'. Provide your new image source and dnCNNLayers to trainNetwork.


  • Training a deep neural network for a range of noise variances is a much more difficult problem than training a single noise level network. You should create more patches compared to a single noise level case, and training might take more time.

Introduced in R2017b

Was this topic helpful?