denoisingImageDatastore - Denoising image datastore - MATLAB (original) (raw)
Denoising image datastore
Description
Use a denoisingImageDatastore
object to generate batches of noisy image patches and corresponding noise patches from images in anImageDatastore
. 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
Syntax
Description
dnimds = denoisingImageDatastore([imds](#d126e72688))
creates a denoising image datastore using images from image datastoreimds
. 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 of0.1
to the image patches.
dnimds = denoisingImageDatastore([imds](#d126e72688),[Name=Value](#namevaluepairarguments))
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
.
Input Arguments
Name-Value Arguments
Specify optional pairs of arguments asName1=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 thePatchSize 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
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
istrue
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 ofMiniBatchSize
only after you create the datastore. For training, prediction, or classification, theMiniBatchSize
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 thepatchSize
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 ofPatchSize
is1
. - If
ChannelFormat
is"RGB"
, then grayscale images are replicated to simulate an RGB image and the third element ofPatchSize
is3
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Object Functions
combine | Combine data from multiple datastores |
---|---|
hasdata | Determine if data is available to read |
partitionByIndex | Partition denoisingImageDatastore according to indices |
preview | Preview subset of data in datastore |
read | Read data from denoisingImageDatastore |
readall | Read all data in datastore |
readByIndex | Read data specified by index fromdenoisingImageDatastore |
reset | Reset datastore to initial state |
shuffle | Shuffle data in datastore |
transform | Transform datastore |
isPartitionable | Determine whether datastore is partitionable |
isShuffleable | Determine whether datastore is shuffleable |
Examples
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 thepreview function, which returns a subset of data in a table. The
input
variable contains the noisy image patches and theresponse
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 calleddnimds
.
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