Main Content

denoisingImageDatastore

Denoising image datastore

Description

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 Deep Learning Toolbox™.

Note

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.

Creation

Description

dnimds = denoisingImageDatastore(imds) creates a denoising image datastore 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 arguments to specify the two-dimensional image patch size or to set the PatchesPerImage, GaussianNoiseLevel, ChannelFormat, and DispatchInBackground properties. You can specify multiple name-value arguments.

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.

example

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.

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

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 a positive integer or 2-element vector of positive integers. 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

Properties

expand all

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

Data Types: char | string

Dispatch observations in the background during training, prediction, and classification, specified as a numeric or logical 0 (false) or 1 (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, specified as a positive integer. 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, specified as a positive integer. 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 the patchSize name-value 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

Examples

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 arguments. When you set the ChannelFormat property to "grayscale", the denoisingImageDatastore converts all color images to grayscale.

dnds = denoisingImageDatastore(imds, ...
    PatchesPerImage=20, ...
    PatchSize=64, ...
    GaussianNoiseLevel=[0.01 0.1], ...
    ChannelFormat="grayscale")
dnds = 
  denoisingImageDatastore with properties:

         PatchesPerImage: 20
               PatchSize: [64 64 1]
      GaussianNoiseLevel: [0.0100 0.1000]
           ChannelFormat: 'grayscale'
           MiniBatchSize: 128
         NumObservations: 660
    DispatchInBackground: 0

Tips

  • 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);
    montage(minibatch.input)
    figure
    montage(minibatch.response)

  • 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

See Also

| | | (Deep Learning Toolbox) | (Deep Learning Toolbox)