Main Content


Denoising image datastore


Use a denoisingImageDatastore object to generate batches of noisy image patches and corresponding noise patches from images in an ImageDatastore. The patches are used to train a denoising deep neural network.

This object requires that you have Deep Learning Toolbox™.


When you use a denoising image datastore as a source of training data, the datastore adds random noise to the image patches for each epoch, so that each epoch uses a slightly different data set. The actual number of training images at each epoch is increased by a factor of PatchesPerImage. The noisy image patches and corresponding noise patches are not stored in memory.



dnimds = denoisingImageDatastore(imds) creates a denoising image datastore, dnimds using images from image datastore imds. To generate noisy image patches, the denoising image datastore randomly crops pristine images from imds then adds zero-mean Gaussian white noise with a standard deviation of 0.1 to the image patches.


dnimds = denoisingImageDatastore(imds,Name,Value) uses name-value pairs to specify the two-dimensional image patch size or to set the PatchesPerImage, GaussianNoiseLevel, ChannelFormat, and DispatchInBackground properties. You can specify multiple name-value pairs. Enclose each argument or property name in quotes.

For example, denoisingImageDatastore(imds,'PatchesPerImage',40) creates a denoising image datastore and randomly generates 40 noisy patches from each image in the image datastore, imds.

Input Arguments

expand all

Image datastore, specified as an ImageDatastore object.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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

Patch size, specified as the comma-separated pair consisting of 'patchSize' and a scalar or 2-element vector with positive integer values. This argument sets the first two elements of the PatchSize property.

  • If 'patchSize' is a scalar, then the patches are square.

  • If 'patchSize' is a 2-element vector of the form [r c], then 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

Channel format, specified as 'grayscale' or 'rgb'.

Data Types: char

Dispatch observations in the background during training, prediction, and classification, specified as false or true. To use background dispatching, you must have Parallel Computing Toolbox™. If DispatchInBackground is true and you have Parallel Computing Toolbox, then denoisingImageDatastore asynchronously reads patches, adds noise, and queues patch pairs.

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

  • If GaussianNoiseLevel is a scalar, then the standard deviation of the added zero-mean Gaussian white noise is identical for all image patches.

  • If GaussianNoiseLevel is a 2-element vector, then it specifies a range of standard deviations [stdmin stdmax]. The standard deviation of the added zero-mean Gaussian white noise is unique for each image patch, and is randomly sampled from a uniform distribution with the range [stdmin stdmax].

Data Types: single | double

Number of observations that are returned in each batch. You can change the value of MiniBatchSize only after you create the datastore. For training, prediction, or classification, the MiniBatchSize property is set to the mini-batch size defined in trainingOptions (Deep Learning Toolbox).

This property is read-only.

Total number of observations in the denoising image datastore. The number of observations is the length of one training epoch.

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

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

This property is read-only.

Patch size, specified as a 3-element vector of positive integers. If you create a denoising image datastore by specifying a 'patchSize' name-value pair argument, then the first two elements of the PatchSize property are set according to the value of the patchSize argument.

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

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

  • If ChannelFormat is 'RGB', then 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

Object Functions

combineCombine data from multiple datastores
hasdataDetermine if data is available to read
partitionByIndexPartition denoisingImageDatastore according to indices
previewPreview subset of data in datastore
readRead data from denoisingImageDatastore
readallRead all data in datastore
readByIndexRead data specified by index from denoisingImageDatastore
resetReset datastore to initial state
shuffleShuffle data in datastore
transformTransform datastore
isPartitionableDetermine whether datastore is partitionable
isShuffleableDetermine whether datastore is shuffleable


collapse all

Get an image datastore. The datastore in this example contains color images.

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

Create a denoisingImageDatastore object that creates many patches from each image in the image datastore, and adds Gaussian noise to the patches. Set the optional PatchesPerImage, PatchSize, GaussianNoiseLevel, and ChannelFormat properties of the denoisingImageDatastore using name-value pairs. When you set the ChannelFormat property to 'grayscale', the denoisingImageDatastore converts all color images to grayscale.

dnds = denoisingImageDatastore(imds,...
    'GaussianNoiseLevel',[0.01 0.1],...
dnds = 
  denoisingImageDatastore with properties:

         PatchesPerImage: 512
               PatchSize: [50 50 1]
      GaussianNoiseLevel: [0.0100 0.1000]
           ChannelFormat: 'grayscale'
           MiniBatchSize: 128
         NumObservations: 16896
    DispatchInBackground: 0


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

  • To visualize the data in a denoising image datastore, you can use the preview function, which returns a subset of data in a table. The input variable contains the noisy image patches and the response variable contains the corresponding noise patches. Visualize all of the noisy image patches or noise patches in the same figure by using the montage function. For example, this code displays data in a denoising image datastore called dnimds.

    minibatch = preview(dnimds);

  • Each time images are read from the denoising image datastore, a different random amount of Gaussian noise is added to each image.

Version History

Introduced in R2018a